From 48deaf177633e062582b7733f633a37b296cac95 Mon Sep 17 00:00:00 2001 From: R0flcopt3r <12752060+R0flcopt3r@users.noreply.github.com> Date: Sat, 5 Jun 2021 22:42:56 +0200 Subject: feat: adds pet command. When petting the cat it will reply with some random action. --- src/hooks/pet.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/hooks/pet.rs (limited to 'src/hooks/pet.rs') diff --git a/src/hooks/pet.rs b/src/hooks/pet.rs new file mode 100644 index 0000000..dcd8148 --- /dev/null +++ b/src/hooks/pet.rs @@ -0,0 +1,33 @@ +use std::str; + +use anyhow::Result; +use irc::client::prelude::*; +use macros::privmsg; + +use rand::thread_rng; +use rand::seq::SliceRandom; + +const PET_RESPONSE: [&str; 5] = [ + "purrs", + "moews loudly", + "walks away", + "snuggles back", + "strikes you with it's sharp claws", +]; + +/// Pet cat +/// +/// Sends some random action when petted. +/// +/// # See also +/// +/// - [`Bot::send_action`] +/// - RESPONSE +pub fn pet(bot: &crate::Bot, msg: Message) -> Result<()> { + let mut rng = thread_rng(); + let choice = PET_RESPONSE.choose(&mut rng); + + privmsg!(msg, { + bot.send_action(msg.response_target().unwrap(), choice.unwrap())?; + }) +} -- cgit v1.2.3