From 23d90a78b9f5014bb8044fac6b8a9b21a81cd43e Mon Sep 17 00:00:00 2001 From: Agatha Rose Date: Fri, 10 Jul 2020 23:44:09 +0300 Subject: [PATCH] Add link to original message in pinned embed --- src/commands/pinned.rs | 18 ++++++++++++++++++ src/main.rs | 14 ++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/commands/pinned.rs b/src/commands/pinned.rs index 385d3eb..a6de9ae 100644 --- a/src/commands/pinned.rs +++ b/src/commands/pinned.rs @@ -33,10 +33,28 @@ fn pinned(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult return Err(CommandError(s!("Index out of bounds!"))); } + let channel = match pinned[idx].channel(&ctx) { + Some(g) => g, + None => return Err(CommandError(s!("Could not get Channel"))), + }; + + let guild_arc = match channel.guild() { + Some(a) => a, + None => return Err(CommandError(s!("Could not find Guild Arc"))), + }; + let guild = guild_arc.read(); + let guild_id = guild.guild_id; + + let msg_link = format!( + "https://discordapp.com/channels/{}/{}/{}", + guild_id, &pinned[idx].channel_id, &pinned[idx].id + ); + let _ = message.channel_id.send_message(&ctx.http, |m| { m.embed(|e| { e.title(format!("Pinned message #{}", idx + 1)) .description(&pinned[idx].content) + .field("🔗 link", format!("[original message]({})", msg_link), true) .timestamp(&pinned[idx].timestamp); e.author(|a| { a.name(&pinned[idx].author.name) diff --git a/src/main.rs b/src/main.rs index bcb9ec0..ed939a1 100755 --- a/src/main.rs +++ b/src/main.rs @@ -472,20 +472,18 @@ fn owo(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { use owoify::OwOifiable; let lastmsg = match message - .channel_id - .messages(&ctx.http, |get| get.before(message.id) - .limit(1)) { + .channel_id + .messages(&ctx.http, |get| get.before(message.id).limit(1)) + { Ok(v) => v, - Err(_) => return Err(CommandError(s!("Could not get last message!"))) + Err(_) => return Err(CommandError(s!("Could not get last message!"))), }; let ref lastmsg = lastmsg[0].content; let input: String = match args.is_empty() { - true => { - s!(lastmsg) - }, - false => args.rest().trim().to_string() + true => s!(lastmsg), + false => args.rest().trim().to_string(), }; let _ = message.channel_id.say(&ctx.http, input.owoify());