Skip to content

Commit

Permalink
feat: js command (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
cathyprime authored Oct 28, 2024
1 parent 8de9cb9 commit 673030b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions twitch/bot/src/commands/js.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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))
}
}
}
}
2 changes: 2 additions & 0 deletions twitch/bot/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod tictactoe;
pub mod uwu;
pub mod vods;
pub mod youtube;
pub mod js;

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 673030b

Please sign in to comment.