experimental say functionality
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
This commit is contained in:
parent
b8bf2e33f6
commit
5802e9b755
5 changed files with 172 additions and 6 deletions
|
@ -79,9 +79,15 @@ impl Chat {
|
||||||
let rl = Arc::clone(&self.ratelimiters);
|
let rl = Arc::clone(&self.ratelimiters);
|
||||||
let mut rllock = rl.lock().await;
|
let mut rllock = rl.lock().await;
|
||||||
|
|
||||||
|
botlog::debug(
|
||||||
|
&format!("Ratelimiter being checked for channel : {}",channel_login.clone()),
|
||||||
|
Some("Chat > send_botmsg".to_string()),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
let contextratelimiter = rllock
|
let contextratelimiter = rllock
|
||||||
// .get_mut()
|
// .get_mut()
|
||||||
.get_mut(&Channel(String::from(channel_login.clone())))
|
.get_mut(&Channel(String::from(channel_login.to_lowercase().clone())))
|
||||||
.expect("ERROR: Issue with Rate limiters");
|
.expect("ERROR: Issue with Rate limiters");
|
||||||
|
|
||||||
// Continue to check the limiter and sleep if required if the minimum is not reached
|
// Continue to check the limiter and sleep if required if the minimum is not reached
|
||||||
|
@ -154,10 +160,9 @@ impl Chat {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _say(&self, channel_login: String, message: String) {
|
pub async fn say(&self, channel_login: String, message: String) {
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
// self.client.say(msg,outmsg).await.unwrap();
|
|
||||||
self.send_botmsg(BotMsgType::Say(channel_login, message)).await;
|
self.send_botmsg(BotMsgType::Say(channel_login, message)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
`modules` will :
|
`custom` will :
|
||||||
- be a starting refrence point for the bot instance to pull module definitions for
|
- be a starting refrence point for the bot instance to pull module definitions for
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -11,7 +11,8 @@ pub use crate::core::botmodules::ModulesManager;
|
||||||
|
|
||||||
// [ ] Load submodules
|
// [ ] Load submodules
|
||||||
|
|
||||||
mod experiments;
|
// mod experiments;
|
||||||
|
mod experimental;
|
||||||
|
|
||||||
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
|
||||||
|
|
||||||
|
@ -19,5 +20,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// Modules initializer loads modules into the bot
|
// Modules initializer loads modules into the bot
|
||||||
// this is achieved by calling submodules that also have fn init() defined
|
// this is achieved by calling submodules that also have fn init() defined
|
||||||
|
|
||||||
experiments::init(mgr).await
|
// experiments::init(mgr).await
|
||||||
|
experimental::init(mgr).await;
|
||||||
}
|
}
|
||||||
|
|
24
src/custom/experimental.rs
Normal file
24
src/custom/experimental.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
`experimental` will :
|
||||||
|
- be for mostly experimental
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub use crate::core::botinstance::BotInstance;
|
||||||
|
pub use crate::core::botmodules::ModulesManager;
|
||||||
|
|
||||||
|
// [ ] Load submodules
|
||||||
|
|
||||||
|
mod experiment001;
|
||||||
|
mod experiment002;
|
||||||
|
|
||||||
|
// [ ] 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
|
||||||
|
|
||||||
|
experiment001::init(Arc::clone(&mgr)).await;
|
||||||
|
experiment002::init(Arc::clone(&mgr)).await;
|
||||||
|
}
|
135
src/custom/experimental/experiment002.rs
Normal file
135
src/custom/experimental/experiment002.rs
Normal 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();
|
||||||
|
}
|
Loading…
Reference in a new issue