Skip to content
Snippets Groups Projects
Unverified Commit ea9b627a authored by tec's avatar tec
Browse files

auto-formatting + tweaks to reactions on motions

parent 0531948a
No related merge requests found
...@@ -46,9 +46,9 @@ macro_rules! e { ...@@ -46,9 +46,9 @@ macro_rules! e {
($error: literal, $x:expr) => { ($error: literal, $x:expr) => {
match $x { match $x {
Ok(_) => (), Ok(_) => (),
Err(why) => eprintln!($error, why) Err(why) => eprintln!($error, why),
} }
} };
} }
struct Handler; struct Handler;
...@@ -80,11 +80,13 @@ impl EventHandler for Handler { ...@@ -80,11 +80,13 @@ impl EventHandler for Handler {
let message_content: Vec<_> = msg.content.splitn(2, ' ').collect(); let message_content: Vec<_> = msg.content.splitn(2, ' ').collect();
match message_content[0] { match message_content[0] {
"!join" => { "!join" => {
e!("Unable to get user: {:?}", e!(
serenity::model::id::GuildId(SERVER_ID) "Unable to get user: {:?}",
.member(ctx.http.clone(), msg.author.id) serenity::model::id::GuildId(SERVER_ID)
.map(|member| new_member(&ctx, member))); .member(ctx.http.clone(), msg.author.id)
}, .map(|member| new_member(&ctx, member))
);
}
"!move" => { "!move" => {
let motion = message_content[1]; let motion = message_content[1];
if motion.len() > 0 { if motion.len() > 0 {
...@@ -96,14 +98,14 @@ impl EventHandler for Handler { ...@@ -96,14 +98,14 @@ impl EventHandler for Handler {
"If there's something you want to motion, put it after the !move keyword", "If there's something you want to motion, put it after the !move keyword",
)); ));
} }
}, }
"!motion" => { "!motion" => {
e!("Error sending message: {:?}", e!("Error sending message: {:?}",
msg.channel_id.say( msg.channel_id.say(
&ctx.http, &ctx.http,
"I hope you're not having a motion. You may have wanted to !move something instead." "I hope you're not having a motion. You may have wanted to !move something instead."
)); ));
}, }
"!poll" => { "!poll" => {
let topic = message_content[1]; let topic = message_content[1];
if topic.len() > 0 { if topic.len() > 0 {
...@@ -115,45 +117,56 @@ impl EventHandler for Handler { ...@@ -115,45 +117,56 @@ impl EventHandler for Handler {
"If there's something you want to motion, put it after the !move keyword", "If there's something you want to motion, put it after the !move keyword",
)); ));
} }
}, }
"!register" => { "!register" => {
let name = message_content[1]; let name = message_content[1];
if name.len() > 0 { if name.len() > 0 {
e!("Unable to get member: {:?}", e!(
serenity::model::id::GuildId(SERVER_ID) "Unable to get member: {:?}",
.member(ctx.http.clone(), msg.author.id) serenity::model::id::GuildId(SERVER_ID)
.map(|mut member| { .member(ctx.http.clone(), msg.author.id)
e!("Unable to remove role: {:?}", .map(|mut member| {
member.remove_role(&ctx.http, UNREGISTERED_MEMBER_ROLE)); e!(
e!("Unable to edit nickname: {:?}", "Unable to remove role: {:?}",
member.edit(&ctx.http, |m| { member.remove_role(&ctx.http, UNREGISTERED_MEMBER_ROLE)
let mut rng = rand::thread_rng(); );
m.nickname(format!( e!(
"{}, {}", "Unable to edit nickname: {:?}",
name, member
[ .edit(&ctx.http, |m| {
"The Big Cheese", let mut rng = rand::thread_rng();
"The One and Only", m.nickname(format!(
"The Exalted One", "{}, {}",
"not to be trusted", name,
"The Scoundrel", [
"A big fish in a small pond", "The Big Cheese",
][rng.gen_range(0, 5)] "The One and Only",
)); "The Exalted One",
m "not to be trusted",
}).map(|()| { "The Scoundrel",
e!("Unable to add role: {:?}", "A big fish in a small pond",
member.add_role(&ctx.http, REGISTERED_MEMBER_ROLE)); ][rng.gen_range(0, 5)]
})); ));
}) m
})
.map(|()| {
e!(
"Unable to add role: {:?}",
member.add_role(&ctx.http, REGISTERED_MEMBER_ROLE)
);
})
);
})
); );
e!("Error deleting register message: {:?}", e!("Error deleting register message: {:?}", msg.delete(ctx));
msg.delete(ctx));
} else { } else {
e!("Error sending message: {:?}", e!(
msg.channel_id.say(&ctx.http, "Usage: !register <ucc username>")); "Error sending message: {:?}",
msg.channel_id
.say(&ctx.http, "Usage: !register <ucc username>")
);
} }
}, }
"!cowsay" => { "!cowsay" => {
let mut text = message_content[1].to_owned(); let mut text = message_content[1].to_owned();
text.escape_default(); text.escape_default();
...@@ -170,14 +183,20 @@ impl EventHandler for Handler { ...@@ -170,14 +183,20 @@ impl EventHandler for Handler {
String::from_utf8(output.stdout).expect("unable to parse stdout to String"), String::from_utf8(output.stdout).expect("unable to parse stdout to String"),
None, None,
); );
e!("Error sending message: {:?}", msg.channel_id.say(&ctx.http, message.build())); e!(
}, "Error sending message: {:?}",
msg.channel_id.say(&ctx.http, message.build())
);
}
"!help" => { "!help" => {
let mut message = MessageBuilder::new(); let mut message = MessageBuilder::new();
message.push_line("Use !move <action> to make a circular motion"); message.push_line("Use !move <action> to make a circular motion");
message.push_line("Use !poll <proposal> to see what people think about something"); message.push_line("Use !poll <proposal> to see what people think about something");
e!("Error sending message: {:?}", msg.channel_id.say(&ctx.http, message.build())); e!(
}, "Error sending message: {:?}",
msg.channel_id.say(&ctx.http, message.build())
);
}
_ => {} _ => {}
} }
} }
...@@ -215,9 +234,13 @@ impl EventHandler for Handler { ...@@ -215,9 +234,13 @@ impl EventHandler for Handler {
} }
Ok(false) => { Ok(false) => {
if user.id.0 != BOT_ID { if user.id.0 != BOT_ID {
if let Err(why) = add_reaction.delete(&ctx) { if ![APPROVE_REACT, DISAPPROVE_REACT]
println!("Error deleting react: {:?}", why); .contains(&add_reaction.emoji.as_data().as_str())
}; {
if let Err(why) = add_reaction.delete(&ctx) {
println!("Error deleting react: {:?}", why);
};
}
} }
} }
Err(why) => { Err(why) => {
...@@ -301,7 +324,13 @@ fn create_motion(ctx: &Context, msg: &Message, topic: &str) { ...@@ -301,7 +324,13 @@ fn create_motion(ctx: &Context, msg: &Message, topic: &str) {
embed.field("Votes", "For: 0\nAgainst: 0\nAbstain: 0", true); embed.field("Votes", "For: 0\nAgainst: 0\nAbstain: 0", true);
embed embed
}); });
m.reactions(vec![FOR_VOTE, AGAINST_VOTE, ABSTAIN_VOTE]); m.reactions(vec![
FOR_VOTE,
AGAINST_VOTE,
ABSTAIN_VOTE,
APPROVE_REACT,
DISAPPROVE_REACT,
]);
m m
}) { }) {
Err(why) => { Err(why) => {
......
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