Gulpo adding textmods to branch

oh god pls let everythign works fine
This commit is contained in:
haruyuumei 2024-04-02 21:19:20 -03:00
parent b9227cc72b
commit 2315270388

159
src/custom/text_mods.rs Normal file
View file

@ -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<ModulesManager>) {
// 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(&params.msg),
);
}
async fn mods(params: ExecBodyParams)
{
// //getting the user message
let sender_message = &params.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<usize,String> = 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(&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,
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(&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,
// 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(&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, String::from("Forsen!"), params.clone())
.await;
sleep(Duration::from_secs_f64(0.5)).await;
}
}