From 13663d1ae3c0bd40abb5d5a5844e1d963c2dca52 Mon Sep 17 00:00:00 2001 From: haruyuumei Date: Sun, 7 Apr 2024 15:25:07 -0300 Subject: [PATCH] Shuffle thing! --- src/custom/text_mods.rs | 67 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/src/custom/text_mods.rs b/src/custom/text_mods.rs index 8960476..5aab4ce 100644 --- a/src/custom/text_mods.rs +++ b/src/custom/text_mods.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::sync::Arc; use rand::{thread_rng, Rng}; +use rand::seq::SliceRandom; use crate::core::bot_actions::{actions_util, ExecBodyParams}; use crate::core::botinstance::Channel; @@ -26,6 +27,8 @@ pub async fn init(mgr: Arc) { //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 @@ -50,12 +53,72 @@ pub async fn init(mgr: Arc) { BotAdmin, Broadcaster, Mod(OF_CMD_CHANNEL), + Chatter, ] }; butt.add_to_modmgr(Arc::clone(&mgr)).await; + let shuffler = BotCommand{ + module:BotModule(String::from("Shuffler")), + command:String::from("Shuffle"), + alias: vec![], + exec_body: actions_util::asyncbox(shuff), + help:String::from("Shuffle Help"), + required_roles:vec![ + BotAdmin, + Broadcaster, + Mod(OF_CMD_CHANNEL), + VIP(OF_CMD_CHANNEL), + Chatter + ] + }; + shuffler.add_to_modmgr(Arc::clone(&mgr)).await; + } + async fn shuff(params : ExecBodyParams) + { + let usermessage = usermsg(¶ms); + + if usermessage.len() > 2 + { + + let mut indexes: Vec = (1..usermessage.len()).collect(); + indexes.shuffle(&mut thread_rng()); + + 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(){ + botreply.push_str(value); + botreply.push(' '); + } + + + 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, + botreply, + params.clone() + ).await; + + } + else { + //if it only has one word, shuffle its chars (exclude the n word monkaLaugh) + } + + } + + async fn butt(params : ExecBodyParams) { //getting User message @@ -94,10 +157,6 @@ pub async fn init(mgr: Arc) { } - - - - async fn forsenforsen(params : ExecBodyParams) { if params.msg.message_text == "forsen" || params.msg.message_text == "Forsen"