text-mods Module: re-writen code
the module now works with the actual command and not with the listener
This commit is contained in:
parent
b561d24c65
commit
6fd5f7b7fb
1 changed files with 67 additions and 128 deletions
|
@ -1,48 +1,39 @@
|
|||
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::bot_actions::{actions_util, ExecBodyParams};
|
||||
use crate::core::botinstance::Channel;
|
||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule,ModulesManager};
|
||||
use crate::core::identity::UserRole::*;
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
//use rand::{thread_rng, Rng};
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
||||
|
||||
|
||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||
|
||||
// Example Working BotCommand Add
|
||||
BotCommand {
|
||||
//DEFINING BOT COMMAND
|
||||
let replyer = BotCommand {
|
||||
module: BotModule(String::from("TextMods")),
|
||||
command: String::from("Reply"),
|
||||
alias: vec![],
|
||||
exec_body: actions_util::asyncbox(fors),
|
||||
command: String::from("reply"),
|
||||
alias: vec![
|
||||
String::from("reply1")
|
||||
],
|
||||
exec_body: actions_util::asyncbox(thereplyer),
|
||||
help: String::from("txt mods help"),
|
||||
required_roles: vec![BotAdmin],
|
||||
}
|
||||
.add_to_modmgr(Arc::clone(&mgr))
|
||||
.await;
|
||||
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),
|
||||
],
|
||||
};
|
||||
//ADDINNG BOT ACTION TO MODULE MANAGER
|
||||
replyer.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)
|
||||
|
||||
async fn thereplyer(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
|
||||
//getting the user message
|
||||
let sender_message = ¶ms.msg.message_text;
|
||||
|
||||
//vector to store the words
|
||||
|
@ -57,103 +48,51 @@ async fn mods(params: ExecBodyParams)
|
|||
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;
|
||||
//reply message
|
||||
let mut bot_reply = String::new();
|
||||
|
||||
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||
botlock
|
||||
for index in 1..index_words.len()
|
||||
{
|
||||
if let Some(word) = index_words.get(&index)
|
||||
{
|
||||
bot_reply.push_str(word);
|
||||
bot_reply.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,
|
||||
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;
|
||||
// }
|
||||
.say_in_reply_to(
|
||||
¶ms.msg,
|
||||
bot_reply.clone(),
|
||||
params.clone()
|
||||
).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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// //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<usize,String> = HashMap::new();
|
||||
|
||||
// //adding to the hashmap each word
|
||||
// for(index,word) in words.iter().enumerate()
|
||||
// {
|
||||
// index_words.insert(index, String::from(*word));
|
||||
// }
|
Loading…
Reference in a new issue