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. --- Cargo.lock | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/hooks/mod.rs | 3 +++ src/hooks/pet.rs | 33 +++++++++++++++++++++++++++++++++ src/main.rs | 5 +++++ 5 files changed, 90 insertions(+) create mode 100644 src/hooks/pet.rs diff --git a/Cargo.lock b/Cargo.lock index 4eebb11..b273198 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,7 @@ dependencies = [ "irc", "irc-proto", "macros", + "rand", "regex", "sasl", "sedregex", @@ -601,6 +602,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -631,6 +638,46 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 1d76cb8..7b164a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,5 +27,7 @@ tracing-futures = "0.2" regex = "1" sedregex = { git = "https://gitlab.com/audron/sedregex" } +rand = "0.8.3" + [workspace] members = ["macros"] 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())?; + }) +} diff --git a/src/main.rs b/src/main.rs index 3213d50..21a1ba1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,5 +40,10 @@ async fn main() { r"^\[.*?\]$", catinator::hooks::intensify ), + command( + "pet", + "Pet the cat, cats generally like pets.", + catinator::hooks::pet::pet + ), ]; } -- cgit v1.2.3