Shuffle thing!
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
haruyuumei 2024-04-07 15:25:07 -03:00
parent 6a71e3375b
commit 13663d1ae3

View file

@ -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<ModulesManager>) {
//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<ModulesManager>) {
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(&params);
if usermessage.len() > 2
{
let mut indexes: Vec<usize> = (1..usermessage.len()).collect();
indexes.shuffle(&mut thread_rng());
let mut new_reply: HashMap<usize, String> = 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(&params.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(
&params.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<ModulesManager>) {
}
async fn forsenforsen(params : ExecBodyParams)
{
if params.msg.message_text == "forsen" || params.msg.message_text == "Forsen"