From 2b81b94916c96d0d6cbff62eba0c45d8395b1e5f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 24 Jul 2021 12:25:04 +0000 Subject: feat(commands): poll command --- src/commands.rs | 26 ++++++++++++++++++++++++++ src/main.rs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/commands.rs b/src/commands.rs index ee875cb..eddb115 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -9,6 +9,11 @@ use serenity::{ utils::{content_safe, ContentSafeOptions}, }; +fn num_to_emoji(num: i32) -> String { + // Naive + num.to_string() + "️⃣" +} + #[command] pub async fn ping(ctx: &Context, msg: &Message) -> CommandResult { msg.channel_id.say(&ctx.http, "Pong!").await?; @@ -184,3 +189,24 @@ pub async fn count(ctx: &Context, msg: &Message) -> CommandResult { Ok(()) } + +#[command] +pub async fn poll(ctx: &Context, msg: &Message, args: Args) -> CommandResult { + let message = format!("__Poll created by {}__\n\n{}", msg.author.name, args.rest()); + + // let ops = args.rest().split(" "); + // let mut tick = 1; + // for op in ops { + // message += &(num_to_emoji(tick) + " " + op + "\n"); + // tick += 1; + // } + + let sent = msg.channel_id.say(&ctx.http, message).await?; + for i in 1..10 { + sent + .react(&ctx.http, ReactionType::Unicode(num_to_emoji(i))) + .await?; + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 3e2bfb7..e859c3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ impl EventHandler for Handler { } #[group] -#[commands(ping, help, say)] +#[commands(ping, help, say, poll)] struct General; #[group] -- cgit v1.2.3