From 12da47253d2c886fc407e75e03a7d9e05e86cb9d Mon Sep 17 00:00:00 2001 From: haruyuumei Date: Tue, 9 Apr 2024 11:32:04 -0300 Subject: [PATCH] comments and small edits --- src/custom/text_mods.rs | 82 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/custom/text_mods.rs b/src/custom/text_mods.rs index 5aab4ce..62c41ee 100644 --- a/src/custom/text_mods.rs +++ b/src/custom/text_mods.rs @@ -1,3 +1,5 @@ +//! A module about editing and messing around with user text +//! use std::collections::HashMap; use std::sync::Arc; use rand::{thread_rng, Rng}; @@ -8,13 +10,11 @@ use crate::core::botinstance::Channel; 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}; pub async fn init(mgr: Arc) { - //DEFINING BOT COMMAND let replyer = BotCommand { - module: BotModule(String::from("TextMods")), + module: BotModule(String::from("Replyer")), command: String::from("Reply"), alias: vec![ String::from("reply") @@ -23,17 +23,16 @@ pub async fn init(mgr: Arc) { help: String::from("txt mods help"), required_roles: vec![ BotAdmin, - //I had to add Broadcaster, just the BotAdmin didn't work, it - //said I had no permission, even if being the broadcaster of the channel Broadcaster, Mod(OF_CMD_CHANNEL), VIP(OF_CMD_CHANNEL), Chatter ], }; - //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"), @@ -61,8 +60,10 @@ pub async fn init(mgr: Arc) { let shuffler = BotCommand{ module:BotModule(String::from("Shuffler")), command:String::from("Shuffle"), - alias: vec![], - exec_body: actions_util::asyncbox(shuff), + alias: vec![ + String::from("shuffle") + ], + exec_body: actions_util::asyncbox(shuffle), help:String::from("Shuffle Help"), required_roles:vec![ BotAdmin, @@ -75,8 +76,14 @@ pub async fn init(mgr: Arc) { shuffler.add_to_modmgr(Arc::clone(&mgr)).await; } - - async fn shuff(params : ExecBodyParams) + /// Shuffle Function + /// + /// Grabs The user message and checks how many words it has + /// + /// If the user message constains more the one word, it shuffles the words + /// + /// If its only One word, it shuffles the letters in the word + async fn shuffle(params : ExecBodyParams) { let usermessage = usermsg(¶ms); @@ -89,7 +96,6 @@ pub async fn init(mgr: Arc) { let mut new_reply: HashMap = HashMap::new(); for (index, &new_index) in indexes.iter().enumerate() { new_reply.insert(index, usermessage[&new_index].clone()); - //println!("{:?}", new_reply[&index]); } let mut botreply = String::new(); for value in new_reply.values(){ @@ -100,8 +106,6 @@ 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 @@ -118,7 +122,11 @@ pub async fn init(mgr: Arc) { } - + ///butt command hehe + /// + /// All this function does is grab the user message, and randomly pick one of the words + /// in the phrase to change the random word for `butt` + /// async fn butt(params : ExecBodyParams) { //getting User message @@ -144,8 +152,6 @@ 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 @@ -157,14 +163,13 @@ pub async fn init(mgr: Arc) { } + ///Forsen. 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 @@ -176,15 +181,19 @@ pub async fn init(mgr: Arc) { } } + ///Thereplyer Function + /// + /// This Function grabs the user message and reply the same message, without the command + /// at the beginning + /// async fn thereplyer(params : ExecBodyParams) { - let user: HashMap = usermsg(¶ms); - //reply message + let user_message: HashMap = usermsg(¶ms); let mut bot_reply = String::new(); - for index in 1..user.len() + for index in 1..user_message.len() { - if let Some(word) = user.get(&index) + if let Some(word) = user_message.get(&index) { bot_reply.push_str(word); bot_reply.push(' '); @@ -194,8 +203,6 @@ 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 @@ -207,6 +214,13 @@ pub async fn init(mgr: Arc) { } +///Usermsg Function +/// +/// Usage: this function grabs the user message, and indexate with a vector and hashmap +/// +/// It returns the User message as a `Hashmap`, with indexs so you can utilize especific words +/// +/// Where `Usize` is index and `String` is the word pub fn usermsg(params : &ExecBodyParams) -> HashMap { //getting the user message @@ -225,22 +239,4 @@ pub fn usermsg(params : &ExecBodyParams) -> HashMap } index_words -} - - - - -// //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)); -// } \ No newline at end of file +} \ No newline at end of file