Commit 36b8c373 authored by Tom Almeida's avatar Tom Almeida

Let's actually stop people from doing dodgy things with cowsay

parent 36b4d635
...@@ -74,8 +74,7 @@ impl EventHandler for Handler { ...@@ -74,8 +74,7 @@ impl EventHandler for Handler {
} }
_ => {} _ => {}
} }
} } else if msg.content.starts_with("!move") {
if msg.content.starts_with("!move") {
let mut iter = msg.content.chars(); let mut iter = msg.content.chars();
iter.by_ref().nth(5); iter.by_ref().nth(5);
let topic = iter.as_str(); let topic = iter.as_str();
...@@ -93,8 +92,7 @@ impl EventHandler for Handler { ...@@ -93,8 +92,7 @@ impl EventHandler for Handler {
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.") { 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); println!("Error sending message: {:?}", why);
} }
} } else if msg.content.starts_with("!poll") {
if msg.content.starts_with("!poll") {
let mut iter = msg.content.chars(); let mut iter = msg.content.chars();
iter.by_ref().nth(5); iter.by_ref().nth(5);
let topic = iter.as_str(); let topic = iter.as_str();
...@@ -163,11 +161,13 @@ impl EventHandler for Handler { ...@@ -163,11 +161,13 @@ impl EventHandler for Handler {
println!("Error deleting motion prompt: {:?}", why); println!("Error deleting motion prompt: {:?}", why);
} }
} else if msg.content.starts_with("!cowsay") { } else if msg.content.starts_with("!cowsay") {
let mut iter = msg.content.chars(); let mut text = msg.content.split_at(7).1.to_owned();
iter.by_ref().nth(7); text.escape_default();
let text = iter.as_str(); // Guess what buddy! You definitely are passing a string to cowsay
text.insert(0, '\'');
text.insert(text.len(), '\'');
let output = std::process::Command::new("cowsay") let output = std::process::Command::new("cowsay")
.arg(text.escape_default()) .arg(text)
.output() .output()
.expect("failed to execute cowsay"); .expect("failed to execute cowsay");
let mut message = MessageBuilder::new(); let mut message = MessageBuilder::new();
......
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