diff --git a/Cargo.toml b/Cargo.toml index 0dda58fc8efaaad780912232c4bc2df2edf1c7f2..02f571c75bb51bc6e3b6eb3b1d57d813ff9ba0c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ log = "^0.4.8" simplelog = "^0.7.4" toml = "^0.5.6" serde = "^1.0.104" +chrono = "^0.4.10" diff --git a/src/main.rs b/src/main.rs index d20a54476b76fbf11f6965b7abbbdcc5b164cf55..90497c03103b3ab776a5f589508020d6ab73ae94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ extern crate simplelog; use simplelog::*; use std::fs::{read_to_string, File}; +use chrono::prelude::Utc; use serenity::{ model::{channel, channel::Message, gateway::Ready, guild::Member}, prelude::*, @@ -61,10 +62,13 @@ impl EventHandler for Handler { "cowsay" => { voting::Commands::cowsay(ctx, msg.clone(), message_content[1]); } - "logreact" => e!( - "Error sending message {:?}", - msg.channel_id.say(&ctx.http, "React to this to log the ID") - ), + "logreact" => { + e!("Error deleting logreact prompt: {:?}", msg.delete(&ctx)); + e!( + "Error sending message {:?}", + msg.channel_id.say(&ctx.http, "React to this to log the ID") + ) + } "help" => { let mut message = MessageBuilder::new(); message.push_line(format!( @@ -103,11 +107,30 @@ impl EventHandler for Handler { voting::reaction_add(ctx, add_reaction); } "logreact" => { + let react_user = add_reaction.user(&ctx).unwrap(); + if Utc::now().timestamp() - message.timestamp.timestamp() > 300 { + warn!( + "The logreact message {} just tried to use is too old", + react_user.name + ); + return; + } info!( - "The react {:?} just added is {:?}", - add_reaction.user(&ctx).unwrap().name, + "The react {} just added is {:?}", + react_user.name, add_reaction.emoji.as_data() ); + let mut msg = MessageBuilder::new(); + msg.push_italic(react_user.name); + msg.push(format!( + " wanted to know that {} is represented by ", + add_reaction.emoji, + )); + msg.push_mono(add_reaction.emoji.as_data()); + e!( + "Error sending message: {:?}", + message.channel_id.say(&ctx.http, msg.build()) + ); } _ => {} }