Commit ca3b4860 authored by Tom Almeida's avatar Tom Almeida

Fix up some of the ugliness

parent 36b8c373
...@@ -67,140 +67,110 @@ impl EventHandler for Handler { ...@@ -67,140 +67,110 @@ impl EventHandler for Handler {
println!("Error sending message: {:?}", why); println!("Error sending message: {:?}", why);
} }
} }
if msg.content.starts_with("!join") {
match serenity::model::id::GuildId(SERVER_ID).member(ctx.http.clone(), msg.author.id) { let message_content: Vec<_> = msg.content.splitn(2, ' ').collect();
Ok(member) => { match message_content[0] {
new_member(&ctx, member); "!join" => {
} serenity::model::id::GuildId(SERVER_ID)
_ => {} .member(ctx.http.clone(), msg.author.id)
} .map(|member| new_member(&ctx, member));
} else if msg.content.starts_with("!move") { },
let mut iter = msg.content.chars(); "!move" => {
iter.by_ref().nth(5); let motion = message_content[1];
let topic = iter.as_str(); if motion.len() > 0 {
if topic == "" { create_motion(&ctx, &msg, motion);
if let Err(why) = msg.channel_id.say( } else {
&ctx.http, msg.channel_id.say(
"If there's something you want to motion, put it after the !move keyword", &ctx.http,
) { "If there's something you want to motion, put it after the !move keyword",
println!("Error sending message: {:?}", why); ).map_err(|why| eprintln!("Error sending message: {:?}", why));
} }
} else { },
create_motion(&ctx, &msg, topic); "!motion" => {
} msg.channel_id.say(
} else if msg.content.starts_with("!motion") {
if let Err(why) = msg.channel_id.say(&ctx.http, "I hope you're not having a motion. You may have wanted to !move something instead.") {
println!("Error sending message: {:?}", why);
}
} else if msg.content.starts_with("!poll") {
let mut iter = msg.content.chars();
iter.by_ref().nth(5);
let topic = iter.as_str();
if topic == "" {
if let Err(why) = msg.channel_id.say(
&ctx.http, &ctx.http,
"If there's something you want to poll, put it after the !move keyword", "I hope you're not having a motion. You may have wanted to !move something instead."
) { ).map_err(|why| eprintln!("Error sending message: {:?}", why));
println!("Error sending message: {:?}", why); },
"!poll" => {
let topic = message_content[1];
if topic.len() > 0 {
create_motion(&ctx, &msg, topic);
} else {
msg.channel_id.say(
&ctx.http,
"If there's something you want to motion, put it after the !move keyword",
).map_err(|why| eprintln!("Error sending message: {:?}", why));
} }
} else { },
create_poll(&ctx, &msg, topic); "!register" => {
} let name = message_content[1];
} else if msg.content.starts_with("!register") { if name.len() > 0 {
let mut iter = msg.content.chars(); serenity::model::id::GuildId(SERVER_ID)
iter.by_ref().nth(9); .member(ctx.http.clone(), msg.author.id)
let name = iter.as_str(); .map(|mut member| {
if name == "" { member.remove_role(&ctx.http, UNREGISTERED_MEMBER_ROLE)
if let Err(why) = msg .map_err(|why| eprintln!("Unable to remove role: {:?}", why));
.channel_id member.edit(&ctx.http, |m| {
.say(&ctx.http, "Usage: !register <ucc username>") let mut rng = rand::thread_rng();
{ m.nickname(format!(
println!("Error sending message: {:?}", why); "{}, {}",
} name,
} else { [
match serenity::model::id::GuildId(SERVER_ID) "The Big Cheese",
.member(ctx.http.clone(), msg.author.id) "The One and Only",
{ "The Exalted One",
Ok(mut member) => { "not to be trusted",
if let Err(why) = member.remove_role(&ctx.http, UNREGISTERED_MEMBER_ROLE) { "The Scoundrel",
println!("Unable to remove role: {:?}", why); "A big fish in a small pond",
}; ][rng.gen_range(0, 5)]
match member.edit(&ctx.http, |m| { ));
let mut rng = rand::thread_rng(); m
m.nickname(format!( }).map(|()| {
"{}, {}", member.add_role(&ctx.http, REGISTERED_MEMBER_ROLE)
name, .map_err(|why| {
[ eprintln!("Unable to add role: {:?}", why);
"The Big Cheese", })
"The One and Only", }).map_err(|why| {
"The Exalted One", eprintln!("Unable to edit nickname: {:?}", why);
"not to be trusted", });
"The Scoundrel", })
"A big fish in a small pond", .map_err(|why| {
][rng.gen_range(0, 4)] eprintln!("Unable to get member: {:?}", why);
)); });
m msg.delete(ctx).map_err(|why| eprintln!("Error deleting register message: {:?}", why));
}) { } else {
Ok(_) => { msg.channel_id.say(&ctx.http, "Usage: !register <ucc username>")
if let Err(why) = member.add_role(&ctx.http, REGISTERED_MEMBER_ROLE) .map_err(|why| eprintln!("Error sending message: {:?}", why));
{
println!("Unable to add role: {:?}", why);
};
}
Err(why) => {
println!("Unable to edit nickname: {:?}", why);
}
};
}
Err(why) => {
println!("Unable to get member: {:?}", why);
}
} }
} },
if let Err(why) = msg.delete(ctx) { "!cowsay" => {
println!("Error deleting motion prompt: {:?}", why); let mut text = message_content[1].to_owned();
} text.escape_default();
} else if msg.content.starts_with("!cowsay") { // Guess what buddy! You definitely are passing a string to cowsay
let mut text = msg.content.split_at(7).1.to_owned(); text.insert(0, '\'');
text.escape_default(); text.insert(text.len(), '\'');
// Guess what buddy! You definitely are passing a string to cowsay let output = std::process::Command::new("cowsay")
text.insert(0, '\''); .arg(text)
text.insert(text.len(), '\''); .output()
let output = std::process::Command::new("cowsay") // btw, if we can't execute cowsay we crash
.arg(text) .expect("failed to execute cowsay");
.output() let mut message = MessageBuilder::new();
.expect("failed to execute cowsay"); message.push_codeblock(
let mut message = MessageBuilder::new(); String::from_utf8(output.stdout).expect("unable to parse stdout to String"),
message.push_codeblock( None,
String::from_utf8(output.stdout).expect("unable to parse stdout to String"), );
None, msg.channel_id.say(&ctx.http, message.build())
); .map_err(|why| eprintln!("Error sending message: {:?}", why));
if let Err(why) = msg.channel_id.say(&ctx.http, message.build()) { },
println!("Error sending message: {:?}", why); "!help" => {
} let mut message = MessageBuilder::new();
} else if msg.content.starts_with("!troll") { message.push_line("Use !move <action> to make a circular motion");
let mut iter = msg.content.chars(); message.push_line("Use !poll <proposal> to see what people think about something");
iter.by_ref().nth(5); msg.channel_id.say(&ctx.http, message.build())
let text = iter.as_str(); .map_err(|why| eprintln!("Error sending message: {:?}", why));
let output = std::process::Command::new("cat") },
.arg(text) _ => {}
.output()
.expect("failed to execute cowsay");
let mut message = MessageBuilder::new();
message.push_codeblock(
String::from_utf8(output.stdout).expect("unable to parse stdout to String"),
None,
);
if let Err(why) = msg.channel_id.say(&ctx.http, message.build()) {
println!("Error sending message: {:?}", why);
}
} else if msg.content == "!help" {
let mut message = MessageBuilder::new();
message.push_line("Use !move <action> to make a circular motion");
message.push_line("Use !poll <proposal> to see what people think about something");
if let Err(why) = msg.channel_id.say(&ctx.http, message.build()) {
println!("Error sending message: {:?}", why);
}
} }
} }
......
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