trying to add a new module
This commit is contained in:
parent
b9227cc72b
commit
95a9962721
5 changed files with 96 additions and 4 deletions
|
@ -122,8 +122,6 @@ async fn good_girl(params : ExecBodyParams) {
|
|||
);
|
||||
|
||||
let bot = Arc::clone(¶ms.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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
pub mod core;
|
||||
pub mod custom;
|
||||
pub mod modules;
|
10
src/modules.rs
Normal file
10
src/modules.rs
Normal 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
17
src/modules/test.rs
Normal 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
68
src/modules/thisguy.rs
Normal 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(¶ms.msg),
|
||||
);
|
||||
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("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(¶ms.msg),
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue