Custom this BotCommand #48

Merged
modulatingforce merged 12 commits from say-this-guy into master 2024-04-09 15:49:58 -04:00
5 changed files with 96 additions and 4 deletions
Showing only changes of commit 95a9962721 - Show all commits

View file

@ -122,8 +122,6 @@ async fn good_girl(params : ExecBodyParams) {
);
let bot = Arc::clone(&params.bot);
let botlock = bot.read().await;
// uses chat.say_in_reply_to() for the bot controls for messages
@ -135,8 +133,6 @@ async fn good_girl(params : ExecBodyParams) {
String::from("GoodGirl xdd "),
params.clone()
).await;
}
}
}

View file

@ -1,2 +1,3 @@
pub mod core;
pub mod custom;
pub mod modules;

10
src/modules.rs Normal file
View file

@ -0,0 +1,10 @@
use std::sync::Arc;
pub use crate::core::botinstance::BotInstance;
pub use crate::core::botmodules::ModulesManager;
mod thisguy;
pub async fn init(mgr:&Arc<ModulesManager>){
thisguy::init(mgr).await;
}

17
src/modules/test.rs Normal file
View file

@ -0,0 +1,17 @@
use std::sync::Arc;
// pub use crate::core::botinstance::BotInstance;
pub use crate::core::botmodules::ModulesManager;
// [ ] Load submodules
mod thisguy;
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
pub async fn init(mgr: Arc<ModulesManager>) {
// Modules initializer loads modules into the bot
// this is achieved by calling submodules that also have fn init() defined
thisguy::init(Arc::clone(&mgr)).await;
}

68
src/modules/thisguy.rs Normal file
View file

@ -0,0 +1,68 @@
use crate::core::botmodules::{ BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::identity::UserRole::*;
use crate::core::bot_actions::*;
use crate::core::botlog;
use std::sync::Arc;
use tokio::time::{sleep, Duration};
async fn tsg(params: ExecBodyParams){
if params.msg.sender.name.to_lowercase() == "haruyuumei".to_lowercase()
//|| params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
{
botlog::debug(
"Oh god I love anime Girls!!",
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,
String::from("Oh god I love anime Girls!!"),
params.clone()
).await;
sleep(Duration::from_secs_f64(0.5)).await;
}
}
pub async fn init(mgr:&Arc<ModulesManager>){
BotCommand{
module:BotModule(String::from("thisguy")),
command: String::from("this"),
alias: vec![String::from("tsg")],
exec_body: actions_util::asyncbox(tesst),
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(""),
}.add_to_modmgr(Arc::clone(&mgr)).await;
}
async fn tesst(params : ExecBodyParams) {
println!("tesst triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
botlog::debug(
"tesst triggered!",
Some("modules > tesst()".to_string()),
Some(&params.msg),
);
}