forked from sorceress/rustcord
Add pinned command
This commit is contained in:
parent
21b9a1ded7
commit
e975b9689a
46
src/main.rs
46
src/main.rs
|
@ -50,7 +50,7 @@ impl EventHandler for Handler {
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(
|
#[commands(
|
||||||
init, ping, halt, list_srv, host, ship, bottom_rng, headpat, uwu, gayculator, sausage, help,
|
init, ping, halt, list_srv, host, ship, bottom_rng, headpat, uwu, gayculator, sausage, help,
|
||||||
embed, define, owo, info, echo, desc
|
embed, define, owo, info, echo, desc, pinned
|
||||||
)]
|
)]
|
||||||
struct General;
|
struct General;
|
||||||
|
|
||||||
|
@ -526,6 +526,11 @@ fn help(ctx: &mut Context, message: &Message) -> CommandResult {
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
("owo!desc", "Display channel's topic", true),
|
("owo!desc", "Display channel's topic", true),
|
||||||
|
(
|
||||||
|
"owo!pinned ``[num]``",
|
||||||
|
"Display channel's Nth pinned message",
|
||||||
|
true,
|
||||||
|
),
|
||||||
("owo!ship ``[names]``", "*Shipping intensifies*", true),
|
("owo!ship ``[names]``", "*Shipping intensifies*", true),
|
||||||
("owo!headpat ``name``", "Headpat someone", true),
|
("owo!headpat ``name``", "Headpat someone", true),
|
||||||
("owo!owo ``text``", "owoify input text", true),
|
("owo!owo ``text``", "owoify input text", true),
|
||||||
|
@ -639,3 +644,42 @@ fn desc(ctx: &mut Context, message: &Message) -> CommandResult {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
fn pinned(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult {
|
||||||
|
let pinned = match message.channel_id.pins(&ctx.http) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => {
|
||||||
|
return Err(CommandError(
|
||||||
|
format!("Could not get pinned messages! Error: {}", e).to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let idx = args.single::<usize>().unwrap_or(0);
|
||||||
|
if pinned.is_empty() {
|
||||||
|
return Err(CommandError("No pinned messages found!".to_string()));
|
||||||
|
}
|
||||||
|
if idx > pinned.len() - 1 {
|
||||||
|
return Err(CommandError("Index out of bounds!".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = message.channel_id.send_message(&ctx.http, |m| {
|
||||||
|
m.embed(|e| {
|
||||||
|
e.title(format!("Pinned message #{}", idx))
|
||||||
|
.description(&pinned[idx].content)
|
||||||
|
.timestamp(&pinned[idx].timestamp);
|
||||||
|
e.author(|a| {
|
||||||
|
//assuming first array element is name and second is icon url
|
||||||
|
a.name(&pinned[idx].author.name)
|
||||||
|
.icon_url(&pinned[idx].author.avatar_url().unwrap())
|
||||||
|
});
|
||||||
|
if !&pinned[idx].attachments.is_empty() {
|
||||||
|
e.image(&pinned[idx].attachments[0].url);
|
||||||
|
}
|
||||||
|
|
||||||
|
e
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue