Unverified Commit 2c97b924 authored by tec's avatar tec

Improve !logreact function

parent 2b37c069
...@@ -12,3 +12,4 @@ log = "^0.4.8" ...@@ -12,3 +12,4 @@ log = "^0.4.8"
simplelog = "^0.7.4" simplelog = "^0.7.4"
toml = "^0.5.6" toml = "^0.5.6"
serde = "^1.0.104" serde = "^1.0.104"
chrono = "^0.4.10"
...@@ -7,6 +7,7 @@ extern crate simplelog; ...@@ -7,6 +7,7 @@ extern crate simplelog;
use simplelog::*; use simplelog::*;
use std::fs::{read_to_string, File}; use std::fs::{read_to_string, File};
use chrono::prelude::Utc;
use serenity::{ use serenity::{
model::{channel, channel::Message, gateway::Ready, guild::Member}, model::{channel, channel::Message, gateway::Ready, guild::Member},
prelude::*, prelude::*,
...@@ -61,10 +62,13 @@ impl EventHandler for Handler { ...@@ -61,10 +62,13 @@ impl EventHandler for Handler {
"cowsay" => { "cowsay" => {
voting::Commands::cowsay(ctx, msg.clone(), message_content[1]); voting::Commands::cowsay(ctx, msg.clone(), message_content[1]);
} }
"logreact" => e!( "logreact" => {
"Error sending message {:?}", e!("Error deleting logreact prompt: {:?}", msg.delete(&ctx));
msg.channel_id.say(&ctx.http, "React to this to log the ID") e!(
), "Error sending message {:?}",
msg.channel_id.say(&ctx.http, "React to this to log the ID")
)
}
"help" => { "help" => {
let mut message = MessageBuilder::new(); let mut message = MessageBuilder::new();
message.push_line(format!( message.push_line(format!(
...@@ -103,11 +107,30 @@ impl EventHandler for Handler { ...@@ -103,11 +107,30 @@ impl EventHandler for Handler {
voting::reaction_add(ctx, add_reaction); voting::reaction_add(ctx, add_reaction);
} }
"logreact" => { "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!( info!(
"The react {:?} just added is {:?}", "The react {} just added is {:?}",
add_reaction.user(&ctx).unwrap().name, react_user.name,
add_reaction.emoji.as_data() 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())
);
} }
_ => {} _ => {}
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment