experimental say functionality

This commit is contained in:
ModulatingForce 2024-03-23 13:32:22 -04:00
commit 5802e9b755
5 changed files with 172 additions and 6 deletions
src/custom/experimental

View file

@ -0,0 +1,135 @@
/*
Custom Modules -
Usage :
[ ] within the file's init(), define BotActions & Load them into the ModulesManager
[ ] Define Execution Bodies for these BotActions
[ ] Afterwards, add the following to parent modules.rs file
- mod <modulename>;
- within init(), <modulename>::init(mgr).await
*/
// use rand::Rng;
use std::sync::Arc;
use twitch_irc::message::PrivmsgMessage;
// use crate::core::botinstance::ChType::Channel;
use crate::core::botinstance::ChType;
use ChType::Channel;
use crate::core::botlog;
use casual_logger::Log;
use crate::core::bot_actions::actions_util::{self, BotAR};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
use crate::core::identity::UserRole::*;
// use tokio::time::{sleep, Duration};
pub async fn init(mgr: Arc<ModulesManager>) {
const OF_CMD_CHANNEL:ChType = Channel(String::new());
// 1. Define the BotAction
let botc1 = BotCommand {
module: BotModule(String::from("experiments002")),
command: String::from("say"), // command call name
alias: vec![
"s".to_string(),
], // String of alternative names
exec_body: actions_util::asyncbox(sayout),
help: String::from("Test Command tester"),
required_roles: vec![
BotAdmin,
Mod(OF_CMD_CHANNEL),
],
};
// 2. Add the BotAction to ModulesManager
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await;
}
async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
/*
usage :
<target channel> <message>
*/
// [x] Unwraps arguments from message
let argrslt =
if let Some((_,str1)) = msg.message_text.split_once(" ") {
if let Some((channelstr,msgstr)) = str1.split_once(" ") {
// println!("{}",cmdstr);
// println!("{}",channelstr);
// println!("{}",msgstr);
Some((channelstr,msgstr))
}
else { None }
}
else { None };
match argrslt {
Some((trgchnl,outmsg)) => {
let newoutmsg = format!("{} (from #{}) says : {}",
msg.sender.name,msg.channel_login, outmsg);
let bot = Arc::clone(&bot);
let botlock = bot.read().await;
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say(trgchnl.to_string(), newoutmsg.to_string())
.await;
// botlog::debug(
// "Sayout had issues trying to parse arguments",
// Some("experiment002 > sayout".to_string()),
// Some(&msg),
// );
},
None => {
botlog::debug(
"sayout had issues trying to parse arguments",
Some("experiment002 > sayout".to_string()),
Some(&msg),
);
let bot = Arc::clone(&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(&msg, String::from("Invalid arguments"))
.await;
},
}
Log::flush();
}