diff --git a/src/custom/text_mods.rs b/src/custom/text_mods.rs new file mode 100644 index 0000000..50ff131 --- /dev/null +++ b/src/custom/text_mods.rs @@ -0,0 +1,159 @@ +use std::collections::HashMap; +use std::sync::Arc; +use crate::core::{bot_actions::*, botlog}; +use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; +use crate::core::identity::UserRole::*; +use rand::{thread_rng, Rng}; +use tokio::time::{sleep, Duration}; + + + +pub async fn init(mgr: &Arc) { + + // Example Working BotCommand Add + BotCommand { + module: BotModule(String::from("TextMods")), + command: String::from("Reply"), + alias: vec![], + exec_body: actions_util::asyncbox(fors), + help: String::from("txt mods help"), + required_roles: vec![BotAdmin], + } + .add_to_modmgr(Arc::clone(&mgr)) + .await; + + Listener { + module: BotModule(String::from("TextMods")), + name: String::from("This Guy Listener"), + exec_body: actions_util::asyncbox(mods), + help: String::from(""), + } + .add_to_modmgr(Arc::clone(&mgr)) + .await; +} +async fn fors(params: ExecBodyParams) +{ + println!("Test triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call + botlog::debug( + "test triggered!", + Some("modules > tesst()".to_string()), + Some(¶ms.msg), + ); +} +async fn mods(params: ExecBodyParams) +{ + // //getting the user message + let sender_message = ¶ms.msg.message_text; + + //vector to store the words + let words: Vec<&str> = sender_message.split_whitespace().collect(); + + //using Hashmap to store the words + let mut index_words:HashMap = HashMap::new(); + + //adding to the hashmap each word + for(index,word) in words.iter().enumerate() + { + index_words.insert(index, String::from(*word)); + } + + //if command is rw/Rw + if index_words.get(&0).unwrap().to_string() == "+reply" + || index_words.get(&0).unwrap().to_string() == "+Reply" + { + //do what i want with the message + + //new message + let mut message:String = String::new(); + + //adding all other words in index words to the reply phrase + //for index starting at 1 til max indexed words + for index in 1..index_words.len() + { + //if the word = the word on the indexed words + if let Some(words) = index_words.get(&index) + { + //add message + message.push_str(words); + //add space + message.push_str(" "); + //do agane + } + } + + //bot typing the rest of the message + 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, + message, + params.clone()) + .await; + sleep(Duration::from_secs_f64(0.5)).await; + } + + /* + + TESTING AREA, WAITING FOR THREAD_RNG FIX :D + + */ + // if index_words.get(&0).unwrap().to_string() == "+shuffle" + // || index_words.get(&0).unwrap().to_string() == "+Shuffle"{ + // //do what i want with the message + + // //new message + // let mut message:String = String::new(); + + // let mut rnd = thread_rng(); + // let random_number = rnd.gen_range(1..=100); + // //adding all other words in index words to the reply phrase + // //for index starting at 1 til max indexed words + // for index in 1..index_words.len() + // { + // //if the word = the word on the indexed words + // if let Some(words) = index_words.get(&index) + // { + // //add message + // message.push_str(words); + // //add space + // message.push_str(" "); + // //do agane + // } + // } + + // //bot typing the rest of the message + // 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, + // message, + // params.clone()) + // .await; + // sleep(Duration::from_secs_f64(0.5)).await; + // } + + + if words.get(0).unwrap().to_string() == "forsen" + { + //bot typing the rest of the message + 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; + sleep(Duration::from_secs_f64(0.5)).await; + } + +} \ No newline at end of file