diff options
| author | R0flcopt3r <12752060+R0flcopt3r@users.noreply.github.com> | 2021-06-05 22:42:56 +0200 |
|---|---|---|
| committer | R0flcopt3r <12752060+R0flcopt3r@users.noreply.github.com> | 2021-06-05 23:12:56 +0200 |
| commit | 48deaf177633e062582b7733f633a37b296cac95 (patch) | |
| tree | e84e572de74e97c9895712166aea9217f169320e /src/hooks | |
| parent | feat: send action (diff) | |
feat: adds pet command.
When petting the cat it will reply with some random action.
Diffstat (limited to 'src/hooks')
| -rw-r--r-- | src/hooks/mod.rs | 3 | ||||
| -rw-r--r-- | src/hooks/pet.rs | 33 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index 49ec0ab..ee64643 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -1,9 +1,12 @@ +extern crate rand; + use anyhow::Result; use irc::client::prelude::*; pub mod sed; pub mod intensify; pub mod shifty_eyes; +pub mod pet; pub use shifty_eyes::shifty_eyes; pub use intensify::intensify; 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())?; + }) +} |
