aboutsummaryrefslogtreecommitdiff
path: root/src/hooks/shifty_eyes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks/shifty_eyes.rs')
-rw-r--r--src/hooks/shifty_eyes.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/hooks/shifty_eyes.rs b/src/hooks/shifty_eyes.rs
index ef9cb5a..4680007 100644
--- a/src/hooks/shifty_eyes.rs
+++ b/src/hooks/shifty_eyes.rs
@@ -1,4 +1,4 @@
-use anyhow::{anyhow, Result};
+use anyhow::{bail, Context, Result};
use irc::client::prelude::*;
const EYES: [char; 11] = ['^', 'v', 'V', '>', '<', 'x', 'X', '-', 'o', 'O', '.'];
@@ -8,9 +8,9 @@ pub fn shifty_eyes(bot: &crate::Bot, msg: Message) -> Result<()> {
if let Command::PRIVMSG(_, text) = msg.command.clone() {
if text.len() == 3 {
let mut chars = text.chars();
- let mut left = chars.next().unwrap();
- let middle = chars.next().unwrap();
- let mut right = chars.next().unwrap();
+ let mut left = chars.next().context("failed to get next character")?;
+ let middle = chars.next().context("failed to get next character")?;
+ let mut right = chars.next().context("failed to get next character")?;
if EYES.contains(&left) && NOSE.contains(&middle) && EYES.contains(&right) {
left = invert(left)?;
@@ -21,7 +21,11 @@ pub fn shifty_eyes(bot: &crate::Bot, msg: Message) -> Result<()> {
result.push(middle);
result.push(right);
- bot.send_privmsg(msg.response_target().unwrap(), result.as_str())?;
+ bot.send_privmsg(
+ msg.response_target()
+ .context("failed to get response target")?,
+ result.as_str(),
+ )?;
}
}
}
@@ -41,6 +45,6 @@ fn invert(input: char) -> Result<char> {
'-' => Ok('o'),
'o' => Ok('-'),
'O' => Ok('-'),
- _ => Err(anyhow!("not a valid char")),
+ _ => bail!("not a valid char"),
}
}