Commit 680b72cf authored by Timothy du Heaume's avatar Timothy du Heaume

use an enum for the message type

parent 0f952362
...@@ -105,11 +105,11 @@ impl EventHandler for Handler { ...@@ -105,11 +105,11 @@ impl EventHandler for Handler {
if message.author.id.0 != CONFIG.bot_id || add_reaction.user_id == CONFIG.bot_id { if message.author.id.0 != CONFIG.bot_id || add_reaction.user_id == CONFIG.bot_id {
return; return;
} }
match message_type(&message) { match get_message_type(&message) {
"motion" => { MessageType::Motion => {
voting::reaction_add(ctx, add_reaction); voting::reaction_add(ctx, add_reaction);
} }
"logreact" => { MessageType::LogReact => {
let react_user = add_reaction.user(&ctx).unwrap(); let react_user = add_reaction.user(&ctx).unwrap();
let react_as_string = get_string_from_react(add_reaction.emoji.clone()); let react_as_string = get_string_from_react(add_reaction.emoji.clone());
if Utc::now().timestamp() - message.timestamp.timestamp() > 300 { if Utc::now().timestamp() - message.timestamp.timestamp() > 300 {
...@@ -150,8 +150,8 @@ impl EventHandler for Handler { ...@@ -150,8 +150,8 @@ impl EventHandler for Handler {
{ {
return; return;
} }
match message_type(&message) { match get_message_type(&message) {
"motion" => { MessageType::Motion => {
voting::reaction_remove(ctx, removed_reaction); voting::reaction_remove(ctx, removed_reaction);
} }
_ => {} _ => {}
...@@ -209,21 +209,30 @@ fn main() { ...@@ -209,21 +209,30 @@ fn main() {
} }
} }
fn message_type(message: &Message) -> &'static str { #[derive(Debug, PartialEq)]
enum MessageType {
Motion,
Role,
LogReact,
Poll,
Misc
}
fn get_message_type(message: &Message) -> MessageType {
if message.embeds.len() <= 0 { if message.embeds.len() <= 0 {
// Get first word of message // Get first word of message
return match message.content.splitn(2, ' ').next().unwrap() { return match message.content.splitn(2, ' ').next().unwrap() {
"Role" => "role", "Role" => MessageType::Role,
"React" => "logreact", "React" => MessageType::LogReact,
_ => "misc", _ => MessageType::Misc,
}; };
} }
let title: String = message.embeds[0].title.clone().unwrap(); let title: String = message.embeds[0].title.clone().unwrap();
let words_of_title: Vec<_> = title.splitn(2, ' ').collect(); let words_of_title: Vec<_> = title.splitn(2, ' ').collect();
let first_word_of_title = words_of_title[0]; let first_word_of_title = words_of_title[0];
return match first_word_of_title { return match first_word_of_title {
"Motion" => "motion", "Motion" => MessageType::Motion,
"Poll" => "poll", "Poll" => MessageType::Poll,
_ => "misc", _ => MessageType::Misc,
}; };
} }
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