From bb2222e42b776d08a1b4a65093727e11f145df28 Mon Sep 17 00:00:00 2001 From: haruyuumei Date: Wed, 3 Apr 2024 09:34:41 -0300 Subject: [PATCH] added Forsen --- src/custom/text_mods.rs | 49 +++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/custom/text_mods.rs b/src/custom/text_mods.rs index 7d08e4f..9292db7 100644 --- a/src/custom/text_mods.rs +++ b/src/custom/text_mods.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::sync::Arc; use crate::core::bot_actions::{actions_util, ExecBodyParams}; use crate::core::botinstance::Channel; -use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule,ModulesManager}; +use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; use crate::core::identity::UserRole::*; const OF_CMD_CHANNEL:Channel = Channel(String::new()); //use rand::{thread_rng, Rng}; @@ -28,8 +28,34 @@ pub async fn init(mgr: Arc) { }; //ADDINNG BOT ACTION TO MODULE MANAGER replyer.add_to_modmgr(Arc::clone(&mgr)).await; + + let forsen_listener = Listener{ + module:BotModule(String::from("TextMods")), + name:String::from("Forsen Listener"), + exec_body:actions_util::asyncbox(forsenforsen), + help:String::from("Forsen helper"), + }; + forsen_listener.add_to_modmgr(Arc::clone(&mgr)).await; } + async fn forsenforsen(params : ExecBodyParams) + { + if params.msg.message_text == "forsen" || params.msg.message_text == "Forsen" + { + let bot = Arc::clone(¶ms.bot); + let botlock = bot.read().await; + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("Forsen!"), + params.clone() + ).await; + } + } async fn thereplyer(params : ExecBodyParams) { @@ -62,19 +88,18 @@ pub async fn init(mgr: Arc) { let bot = Arc::clone(¶ms.bot); + let botlock = bot.read().await; + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + bot_reply.clone(), + params.clone() + ).await; - let botlock = bot.read().await; - - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - bot_reply.clone(), - params.clone() - ).await; }