Custom this BotCommand #48

Merged
modulatingforce merged 12 commits from say-this-guy into master 2024-04-09 15:49:58 -04:00
Showing only changes of commit 7e04699b67 - Show all commits

View file

@ -1,63 +1,44 @@
use crate::core::bot_actions::*;
use crate::core::botinstance::Channel;
use crate::core::botlog;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
use crate::core::identity::UserRole::*;
use rand::Rng;
use std::sync::Arc;
use tokio::time::{sleep, Duration};
//using the env file to get bot prefix
use std::env;
use dotenv::dotenv;
//bot function
const OF_CMD_CHANNEL:Channel = Channel(String::new());
async fn tsg(params: ExecBodyParams) {
//Defining a var prefix to the prefix on the env file
dotenv().ok();
let prefix = env::var("prefix").unwrap();
/*
defining a text with the prefix + the command name (idk how to get the command)
so for now i'm typing the command
*/
let text = String::from(&prefix) + "This";
let text2 = String::from(&prefix) + "this";
let phrases: [String; 6] = [
"Clueless ".to_string(),
"ICANT This guy....".to_string(),
"He is right tho".to_string(),
"KEKW true!".to_string(),
"OMEGALUL wth man...".to_string(),
"PepeLaugh El no sabe".to_string(),
];
//comparing the text sent with the text (prefix + command name)
if params.msg.message_text == text
|| params.msg.message_text == text2
{
let phrases: [String; 6] = [
"Clueless".to_string(),
"ICANT This guy....".to_string(),
"He is right tho".to_string(),
"KEKW true!".to_string(),
"OMEGALUL wth man...".to_string(),
"PepeLaugh El no sabe".to_string(),
];
let r = rand::thread_rng().gen_range(0..=4);
let a = phrases[r].clone();
let r = rand::thread_rng().gen_range(0..=4);
let a = phrases[r].clone();
let test = params.get_parent_module();
botlog::debug(
"This guy works!",
Some("modules > thisguy()".to_string()),
Some(&params.msg),
);
let bot = Arc::clone(&params.bot);
let botlock = bot.read().await;
botlog::debug(
"This guy works!",
Some("modules > thisguy()".to_string()),
Some(&params.msg),
);
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, a, params.clone())
.await;
sleep(Duration::from_secs_f64(0.5)).await;
}else {
//println!("didn't type the proper command");
}
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
modulatingforce marked this conversation as resolved
Review

We're getting an error here in ci/cd

error[E0061]: this method takes 4 arguments but 3 arguments were supplied
   --> src\custom\thisguy.rs:37:10
    |
37  |         .say_in_reply_to(&params.msg, a, params.clone())
    |          ^^^^^^^^^^^^^^^ -----------     -------------- an argument of type `std::string::String` is missing
    |                          |
    |                          expected `Channel`, found `&PrivmsgMessage`
    |
note: method defined here
   --> src\core\chat.rs:415:18
    |
415 |     pub async fn say_in_reply_to(
    |                  ^^^^^^^^^^^^^^^
416 |         &self,
417 |         destination_channel : Channel ,
    |         -----------------------------
418 |         reply_message_id : String ,
    |         -------------------------
419 |         outmsg: String ,
    |         --------------
420 |         params : ExecBodyParams)
    |         -----------------------
help: provide the argument
    |
37  |         .say_in_reply_to(/* core::botinstance::Channel */, a, /* std::string::String */, params.clone())
    |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Recommend this be adjusted to

.say_in_reply_to(&params.msg.channel_login(), &params.msg.message_id(),a, params.clone())
We're getting an error here in ci/cd ``` error[E0061]: this method takes 4 arguments but 3 arguments were supplied --> src\custom\thisguy.rs:37:10 | 37 | .say_in_reply_to(&params.msg, a, params.clone()) | ^^^^^^^^^^^^^^^ ----------- -------------- an argument of type `std::string::String` is missing | | | expected `Channel`, found `&PrivmsgMessage` | note: method defined here --> src\core\chat.rs:415:18 | 415 | pub async fn say_in_reply_to( | ^^^^^^^^^^^^^^^ 416 | &self, 417 | destination_channel : Channel , | ----------------------------- 418 | reply_message_id : String , | ------------------------- 419 | outmsg: String , | -------------- 420 | params : ExecBodyParams) | ----------------------- help: provide the argument | 37 | .say_in_reply_to(/* core::botinstance::Channel */, a, /* std::string::String */, params.clone()) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` --- Recommend this be adjusted to ```rust .say_in_reply_to(&params.msg.channel_login(), &params.msg.message_id(),a, params.clone()) ```
.chat
.say_in_reply_to(&params.msg, a, params.clone())
.await;
sleep(Duration::from_secs_f64(0.5)).await;
}
pub async fn init(mgr: &Arc<ModulesManager>) {
@ -65,29 +46,14 @@ pub async fn init(mgr: &Arc<ModulesManager>) {
module: BotModule(String::from("thisguy")),
command: String::from("thisguy"),
alias: vec![String::from("Thisguy")],
exec_body: actions_util::asyncbox(test),
help: String::from("test"),
required_roles: vec![BotAdmin],
}
.add_to_modmgr(Arc::clone(&mgr))
.await;
Listener {
module: BotModule(String::from("thisguy")),
name: String::from("This Guy Listener"),
exec_body: actions_util::asyncbox(tsg),
help: String::from(""),
help: String::from("test"),
required_roles: vec![
BotAdmin,
Mod(OF_CMD_CHANNEL),
Broadcaster
],
}
.add_to_modmgr(Arc::clone(&mgr))
.await;
}
async fn test(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),
);
}
}