diff --git a/twitch/bot/src/commands/js.rs b/twitch/bot/src/commands/js.rs new file mode 100644 index 0000000..b16a77d --- /dev/null +++ b/twitch/bot/src/commands/js.rs @@ -0,0 +1,47 @@ +//! js command +//! +//! usage: ```!js``` +//! +//! author: Cathyprime + +use super::ChatCommand; +use anyhow::anyhow; +use rand::seq::SliceRandom; +use tracing::{debug, error}; + +pub struct MostlyJs {} + +impl ChatCommand for MostlyJs { + fn new() -> Self { + Self {} + } + + fn names() -> Vec { + vec!["js".to_string()] + } + + fn help(&self) -> String { + "usage: !js".to_string() + } + + fn handle( + &mut self, + api: &mut super::TwitchApiWrapper, + ctx: &twitcheventsub::MessageData, + ) -> anyhow::Result<()> { + let msgs = vec!["Undefined", "[object Object]", "x === y"]; + let js = msgs.choose(&mut rand::thread_rng()); + let msg = format!("\"{}\" does not exist", js.unwrap()); + + match api.send_chat_message_with_reply(&msg, Some(&ctx.message_id)) { + Ok(s) => { + debug!(reply = %s); + Ok(()) + } + Err(e) => { + error!(error = ?e); + Err(anyhow!("{:?}", e)) + } + } + } +} diff --git a/twitch/bot/src/commands/mod.rs b/twitch/bot/src/commands/mod.rs index 111ebe6..3347e5d 100644 --- a/twitch/bot/src/commands/mod.rs +++ b/twitch/bot/src/commands/mod.rs @@ -29,6 +29,7 @@ pub mod tictactoe; pub mod uwu; pub mod vods; pub mod youtube; +pub mod js; // ---------------------------------------------------------------------------- @@ -82,6 +83,7 @@ pub fn init() -> CommandMap { map.insert(uwu::MostlyUwU::new()); map.insert(rewrite::MostlyRewrite::new()); map.insert(tictactoe::TicTacToe::new()); + map.insert(js::MostlyJs::new()); // help is special let mut help = help::MostlyHelp::new();