2023-12-19 20:38:20 -05:00
2024-02-12 01:25:12 -05:00
// use futures::lock::Mutex;
2023-12-19 20:38:20 -05:00
use tokio ::sync ::mpsc ::UnboundedReceiver ;
2024-02-12 01:25:12 -05:00
use tokio ::sync ::RwLock ;
2023-12-19 20:38:20 -05:00
use twitch_irc ::login ::StaticLoginCredentials ;
use twitch_irc ::ClientConfig ;
use twitch_irc ::SecureTCPTransport ;
use twitch_irc ::TwitchIRCClient ;
2023-12-20 17:55:46 -05:00
use twitch_irc ::message ::PrivmsgMessage ;
2023-12-19 20:38:20 -05:00
use twitch_irc ::message ::ServerMessage ;
use twitch_irc ::transport ::tcp ::TCPTransport ;
use twitch_irc ::transport ::tcp ::TLS ;
2024-02-04 14:28:37 -05:00
// use std::borrow::Borrow;
use std ::borrow ::BorrowMut ;
use std ::boxed ;
use std ::cell ::Ref ;
2023-12-19 20:38:20 -05:00
use std ::env ;
use dotenv ::dotenv ;
2023-12-19 21:08:48 -05:00
use std ::collections ::HashMap ;
2023-12-19 21:43:03 -05:00
use rand ::Rng ;
2024-02-12 01:25:12 -05:00
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
use tokio ::sync ::Mutex ;
2023-12-19 21:08:48 -05:00
2024-02-12 06:30:42 -05:00
use crate ::core ::botmodules ::BotAction ;
2024-02-01 09:43:39 -05:00
use crate ::core ::botmodules ::BotAction ;
2023-12-19 21:08:48 -05:00
use crate ::core ::ratelimiter ::RateLimiter ;
2023-12-19 21:43:03 -05:00
use crate ::core ::ratelimiter ;
2023-12-21 00:48:09 -05:00
use crate ::core ::botmodules ;
2024-02-12 06:31:28 -05:00
use crate ::core ::botmodules ::ModulesManager ;
2024-02-13 07:54:35 -05:00
use crate ::core ::identity ::{ IdentityManager , Permissible , ChangeResult } ;
2024-01-29 06:18:27 -05:00
2024-02-04 14:28:37 -05:00
use std ::rc ::Rc ;
use std ::cell ::RefCell ;
2024-02-12 01:25:12 -05:00
use std ::sync ::Arc ;
2024-02-04 14:28:37 -05:00
// use futures::lock::Mutex;
use std ::pin ::Pin ;
//use std::borrow::Borrow;
use core ::borrow ::Borrow ;
2024-02-12 01:25:12 -05:00
// pub type BotAR = Arc<RwLock<BotInstance>>;
use super ::botmodules ::bot_actions ::actions_util ::BotAR ;
2023-12-21 00:48:09 -05:00
2024-02-13 07:54:35 -05:00
use casual_logger ::{ Level , Log } ;
pub mod botlog {
/*
Module intends to add some layers to logging with the module user only requiring to pass :
- String Log message
- Option < String > - Code Module
- Option < PrivmsgMessage > - this is used to parse out Chatter & Channel into the logs
* /
use casual_logger ::{ Level , Log } ;
use twitch_irc ::message ::PrivmsgMessage ;
// trace, debug, info, notice, warn, error, fatal
fn trace ( in_msg :& str , module :Option < String > , prvmsg :Option < PrivmsgMessage > , ) -> ( ) {
}
fn debug ( prvmsg :Option < PrivmsgMessage > , in_msg :& str ) -> ( ) {
}
fn info ( prvmsg :Option < PrivmsgMessage > , in_msg :& str ) -> ( ) {
}
fn notice ( prvmsg :Option < PrivmsgMessage > , in_msg :& str ) -> ( ) {
}
fn warn ( prvmsg :Option < PrivmsgMessage > , in_msg :& str ) -> ( ) {
}
fn error ( prvmsg :Option < PrivmsgMessage > , in_msg :& str ) -> ( ) {
}
}
2024-01-29 02:10:29 -05:00
#[ derive(Debug, PartialEq, Eq, Hash, Clone) ]
2023-12-20 20:25:20 -05:00
pub enum ChType {
Channel ( String ) ,
2023-12-19 22:21:56 -05:00
}
2023-12-19 21:08:48 -05:00
2023-12-20 20:25:20 -05:00
pub use ChType ::Channel ;
2024-01-29 02:10:29 -05:00
#[ derive(Clone) ]
2023-12-22 21:09:36 -05:00
pub struct Chat {
2024-02-04 14:28:37 -05:00
pub ratelimiters : Arc < Mutex < HashMap < ChType , RateLimiter > > > , // used to limit messages sent per channel
2023-12-22 21:09:36 -05:00
pub client : TwitchIRCClient < TCPTransport < TLS > , StaticLoginCredentials > ,
}
impl Chat {
2024-01-31 01:07:27 -05:00
pub fn init ( ratelimiters :HashMap < ChType , RateLimiter > ,
client :TwitchIRCClient < TCPTransport < TLS > , StaticLoginCredentials > ) -> Chat {
Chat {
2024-02-04 14:28:37 -05:00
ratelimiters : Arc ::new ( Mutex ::new ( ratelimiters ) ) ,
2024-01-31 01:07:27 -05:00
client : client ,
}
}
2024-02-04 14:28:37 -05:00
pub async fn init_channel ( & mut self , chnl :ChType ) -> ( ) {
2023-12-22 21:09:36 -05:00
let n = RateLimiter ::new ( ) ;
2024-02-04 14:28:37 -05:00
self . ratelimiters . lock ( ) . await . insert ( chnl , n ) ;
2023-12-22 21:09:36 -05:00
}
2024-02-04 14:28:37 -05:00
// pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
pub async fn say_in_reply_to ( & self , msg :& PrivmsgMessage , mut outmsg :String ) -> ( ) {
2024-01-29 03:20:56 -05:00
/*
formats message before sending to TwitchIRC
2024-01-29 04:09:53 -05:00
2024-01-29 03:20:56 -05:00
- [ x ] Custom String Formatting ( e . g . , adding random black spaces )
- [ x ] Ratelimiter Handling
- [ ] Checkf if BotActions is Enabled & Caller is Allowed to Run
* /
2023-12-22 21:09:36 -05:00
2024-02-04 14:28:37 -05:00
let a = Arc ::clone ( & self . ratelimiters ) ;
let mut a = a . lock ( ) . await ;
let contextratelimiter = a
// .get_mut()
2023-12-22 21:09:36 -05:00
. get_mut ( & Channel ( String ::from ( & msg . channel_login ) ) )
. expect ( " ERROR: Issue with Rate limiters " ) ;
match contextratelimiter . check_limiter ( ) {
ratelimiter ::LimiterResp ::Allow = > {
let maxblanks = rand ::thread_rng ( ) . gen_range ( 1 ..= 20 ) ;
for _i in 1 .. maxblanks {
let blankspace : & str = " " ;
outmsg . push_str ( blankspace ) ;
}
self . client . say_in_reply_to ( msg , outmsg ) . await . unwrap ( ) ;
2024-02-13 07:54:35 -05:00
// println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
Log ::trace ( & format! ( " (# {} ) > {} " , msg . channel_login , " rate limit counter increase " ) ) ;
2023-12-22 21:09:36 -05:00
contextratelimiter . increment_counter ( ) ;
2024-02-13 07:54:35 -05:00
// println!("{:?}",self.ratelimiters);
Log ::trace ( & format! ( " {:?} " , self . ratelimiters ) ) ;
2023-12-22 21:09:36 -05:00
} ,
ratelimiter ::LimiterResp ::Skip = > {
( ) ; // do nothing otherwise
}
}
2024-02-13 07:54:35 -05:00
Log ::flush ( ) ;
2023-12-22 21:09:36 -05:00
}
async fn say ( & self , _ :String , _ :String ) -> ( ) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
// self.client.say(msg,outmsg).await.unwrap();
}
async fn me ( & self , _ :String , _ :String ) -> ( ) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
// self.client.me(msg,outmsg).await.unwrap();
}
async fn me_in_reply_to ( & self , _ :String , _ :String ) -> ( ) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
// self.client.me(msg,outmsg).await.unwrap();
}
}
2024-01-31 18:36:23 -05:00
#[ derive(Clone) ]
2024-01-30 20:21:58 -05:00
pub struct BotManagers {
2024-01-31 18:36:23 -05:00
// pub botmodules : ModulesManager,
2024-02-12 01:25:12 -05:00
pub identity : Arc < RwLock < IdentityManager > > ,
2024-01-31 01:11:45 -05:00
pub chat : Chat ,
2024-01-30 20:21:58 -05:00
}
impl BotManagers {
2024-01-31 01:11:45 -05:00
pub fn init ( ratelimiters :HashMap < ChType , RateLimiter > ,
client :TwitchIRCClient < TCPTransport < TLS > , StaticLoginCredentials > )
-> BotManagers {
2024-02-12 14:54:35 -05:00
2024-01-30 20:21:58 -05:00
BotManagers {
2024-02-12 01:25:12 -05:00
identity : Arc ::new ( RwLock ::new ( IdentityManager ::init ( ) ) ) ,
2024-01-31 01:11:45 -05:00
chat : Chat ::init ( ratelimiters , client ) ,
2024-01-30 20:21:58 -05:00
}
2024-02-04 14:28:37 -05:00
}
2024-02-12 01:25:12 -05:00
pub fn rIdentity ( self ) -> Arc < RwLock < IdentityManager > > {
2024-02-04 14:28:37 -05:00
self . identity
}
2024-01-31 09:31:14 -05:00
2024-02-04 14:28:37 -05:00
}
2024-01-31 09:31:14 -05:00
2024-02-04 14:28:37 -05:00
pub struct ArcBox < T : Clone > ( pub Arc < Mutex < T > > ) ;
2024-01-31 09:31:14 -05:00
2024-02-04 14:28:37 -05:00
impl < T : Clone > ArcBox < T > {
pub fn inst ( & self ) -> & Mutex < T > {
& self . 0
2024-01-30 20:21:58 -05:00
}
2024-02-04 14:28:37 -05:00
2024-01-30 20:21:58 -05:00
}
2024-02-04 14:28:37 -05:00
//#[derive(Clone)]
// #[derive(Copy)] // <-- Cannot be derived
2024-01-29 01:13:56 -05:00
pub struct BotInstance
2023-12-28 06:02:55 -05:00
{
2024-02-04 14:28:37 -05:00
pub prefix : char ,
pub bot_channel : ChType ,
2024-02-12 01:25:12 -05:00
pub incoming_messages : Arc < RwLock < UnboundedReceiver < ServerMessage > > > ,
pub botmodules : Arc < ModulesManager > ,
2024-02-04 14:28:37 -05:00
pub twitch_oauth : String ,
2023-12-20 20:25:20 -05:00
pub bot_channels : Vec < ChType > ,
2024-01-30 20:21:58 -05:00
pub botmgrs : BotManagers ,
2023-12-19 20:38:20 -05:00
}
2023-12-20 17:55:46 -05:00
2024-01-29 01:13:56 -05:00
impl BotInstance
2023-12-28 06:02:55 -05:00
{
2024-02-12 02:34:32 -05:00
pub async fn init ( ) -> BotInstance
2023-12-28 06:02:55 -05:00
{
2023-12-19 20:38:20 -05:00
dotenv ( ) . ok ( ) ;
2023-12-20 19:12:53 -05:00
let login_name = env ::var ( " login_name " ) . unwrap ( ) . to_owned ( ) ;
2023-12-19 20:38:20 -05:00
let oauth_token = env ::var ( " access_token " ) . unwrap ( ) . to_owned ( ) ;
2023-12-20 19:22:45 -05:00
let prefix = env ::var ( " prefix " ) . unwrap ( ) . to_owned ( ) . chars ( ) . next ( ) . expect ( " ERROR : when defining prefix " ) ;
2023-12-19 20:38:20 -05:00
/*
Vector of channels to join
* /
let mut botchannels = Vec ::new ( ) ;
for chnl in env ::var ( " bot_channels " ) . unwrap ( ) . split ( ',' ) {
// println!("(Env Var # {})",chnl);
2023-12-20 20:25:20 -05:00
botchannels . push ( Channel ( String ::from ( chnl ) ) ) ;
2023-12-19 20:38:20 -05:00
}
let config = ClientConfig ::new_simple (
StaticLoginCredentials ::new ( login_name . to_owned ( ) , Some ( oauth_token . to_owned ( ) ) )
) ;
let ( incoming_messages , client ) =
TwitchIRCClient ::< SecureTCPTransport , StaticLoginCredentials > ::new ( config ) ;
2023-12-20 20:25:20 -05:00
// hashmap for channels and their associated ratelimiters
let mut ratelimiters = HashMap ::new ( ) ;
for Channel ( chnl ) in & botchannels {
// For each channel in botchannels
2023-12-19 20:38:20 -05:00
client . join ( chnl . to_owned ( ) ) . unwrap ( ) ;
2023-12-20 20:25:20 -05:00
2023-12-20 20:27:01 -05:00
// ratelimiters are a hashmap of channel and a corresponding rate limiter
2023-12-20 20:25:20 -05:00
let n = RateLimiter ::new ( ) ;
ratelimiters . insert ( Channel ( String ::from ( chnl ) ) , n ) ;
2023-12-22 21:09:36 -05:00
//self.chat.ratelimiters.insert(Channel(String::from(chnl)),n);
2023-12-19 20:38:20 -05:00
}
2023-12-22 21:09:36 -05:00
2023-12-20 20:25:20 -05:00
let b = BotInstance {
2023-12-20 19:22:45 -05:00
prefix : prefix ,
2023-12-20 20:25:20 -05:00
bot_channel : Channel ( login_name ) ,
2024-02-12 01:25:12 -05:00
incoming_messages : Arc ::new ( RwLock ::new ( incoming_messages ) ) ,
2024-02-12 02:34:32 -05:00
botmodules : ModulesManager ::init ( ) . await ,
2023-12-19 20:38:20 -05:00
twitch_oauth : oauth_token ,
2024-01-29 03:20:56 -05:00
bot_channels : botchannels ,
2024-01-31 01:11:45 -05:00
botmgrs : BotManagers ::init ( ratelimiters , client ) ,
2023-12-19 21:08:48 -05:00
} ;
b
2023-12-19 20:38:20 -05:00
}
2024-02-12 01:25:12 -05:00
pub async fn runner ( self ) -> ( ) {
2024-02-04 14:28:37 -05:00
2024-02-12 01:25:12 -05:00
let bot = Arc ::new ( RwLock ::new ( self ) ) ;
2024-02-04 14:28:37 -05:00
2023-12-28 06:02:55 -05:00
let join_handle = tokio ::spawn ( async move {
2024-02-12 01:25:12 -05:00
let a = bot . read ( ) . await ;
let mut a = a . incoming_messages . write ( ) . await ;
while let Some ( message ) = a . recv ( ) . await {
2023-12-28 06:02:55 -05:00
match message {
ServerMessage ::Notice ( msg ) = > {
2024-02-12 14:54:35 -05:00
2024-01-31 09:31:14 -05:00
match & msg . channel_login {
2024-02-13 07:54:35 -05:00
Some ( chnl ) = > {
// println!("NOTICE : (#{}) {}", chnl, msg.message_text)
Log ::notice ( & format! ( " NOTICE : (# {} ) {} " , chnl , msg . message_text ) ) ;
} ,
None = > {
// println!("NOTICE : {}", msg.message_text);
Log ::notice ( & format! ( " NOTICE : {} " , msg . message_text ) ) ;
} ,
2023-12-28 06:02:55 -05:00
}
}
ServerMessage ::Privmsg ( msg ) = > {
2024-02-13 07:54:35 -05:00
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
Log ::trace ( & format! ( " (# {} ) {} : {} " , msg . channel_login , msg . sender . name , msg . message_text ) ) ;
2023-12-28 06:02:55 -05:00
2024-02-13 07:54:35 -05:00
// println!("Privmsg section");
Log ::debug ( & format! ( " Privmsg section " ) ) ;
2023-12-28 06:02:55 -05:00
2024-02-13 07:54:35 -05:00
BotInstance ::listener_main_prvmsg ( Arc ::clone ( & bot ) , & msg ) . await ;
2024-02-12 01:25:12 -05:00
2023-12-28 06:02:55 -05:00
} ,
ServerMessage ::Whisper ( msg ) = > {
2024-02-13 07:54:35 -05:00
// println!("(w) {}: {}", msg.sender.name, msg.message_text);
Log ::trace ( & format! ( " (w) {} : {} " , msg . sender . name , msg . message_text ) ) ;
2023-12-28 06:02:55 -05:00
} ,
ServerMessage ::Join ( msg ) = > {
2024-02-13 07:54:35 -05:00
// println!("JOINED: {}", msg.channel_login);
Log ::notice ( & format! ( " JOINED: {} " , msg . channel_login ) ) ;
2023-12-28 06:02:55 -05:00
} ,
ServerMessage ::Part ( msg ) = > {
2024-02-13 07:54:35 -05:00
// println!("PARTED: {}", msg.channel_login);
Log ::notice ( & format! ( " PARTED: {} " , msg . channel_login ) ) ;
2023-12-28 06:02:55 -05:00
} ,
_ = > { }
2024-02-13 07:54:35 -05:00
} ;
Log ::flush ( ) ;
2023-12-28 06:02:55 -05:00
}
} ) ;
join_handle . await . unwrap ( ) ;
2024-02-04 14:28:37 -05:00
2023-12-28 06:02:55 -05:00
}
2024-02-04 14:28:37 -05:00
2024-02-12 01:25:12 -05:00
pub fn get_botmodules ( self ) -> Arc < ModulesManager > {
2024-02-12 14:54:35 -05:00
2024-02-04 14:28:37 -05:00
self . botmodules
2024-02-12 14:54:35 -05:00
}
2024-02-12 01:25:12 -05:00
pub async fn get_botmgrs ( self ) -> BotManagers {
2024-02-04 14:28:37 -05:00
let a = self . botmgrs ;
a
}
2024-02-12 01:25:12 -05:00
pub fn get_identity ( & self ) -> Arc < RwLock < IdentityManager > > {
Arc ::clone ( & self . botmgrs . identity )
2024-02-04 14:28:37 -05:00
}
2024-02-12 01:25:12 -05:00
pub fn get_prefix ( & self ) -> char {
( * self ) . prefix
2024-02-04 14:28:37 -05:00
}
2024-02-12 01:25:12 -05:00
2023-12-20 17:55:46 -05:00
// -----------------
// PRIVATE FUNCTIONS
2024-02-12 01:25:12 -05:00
pub async fn listener_main_prvmsg ( bot :BotAR , msg :& PrivmsgMessage ) -> ( ) {
2024-02-13 07:54:35 -05:00
// println!(">> Inner listenermain_prvmsg()");
Log ::trace ( " >> Inner listenermain_prvmsg() " ) ;
2023-12-20 17:55:46 -05:00
2024-02-12 01:25:12 -05:00
// let a = a;
2024-01-29 04:09:53 -05:00
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
2023-12-20 17:55:46 -05:00
2023-12-23 12:29:20 -05:00
// // [ ] Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel)
2024-02-12 01:25:12 -05:00
let botlock = bot . read ( ) . await ;
2024-02-12 02:34:32 -05:00
let hacts = Arc ::clone ( & botlock . botmodules . botactions ) ;
// let hacts = hacts.read().await;
let a = hacts . read ( ) . await ;
2024-02-13 07:54:35 -05:00
// println!("hacts size : {}",(*a).len());
Log ::debug ( & format! ( " hacts size : {} " , ( * a ) . len ( ) ) ) ;
2024-02-12 02:34:32 -05:00
2024-02-13 07:54:35 -05:00
// println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
Log ::trace ( " >> Inner listenermain_prvmsg() >> before for loop of bot actions " ) ;
2024-02-12 14:54:35 -05:00
2024-02-12 02:34:32 -05:00
for ( _m , acts ) in & * hacts . read ( ) . await {
2024-02-12 01:25:12 -05:00
2024-02-13 07:54:35 -05:00
// println!(">> Inner listenermain_prvmsg() >> checking bot actions");
Log ::trace ( " >> Inner listenermain_prvmsg() >> checking bot actions " ) ;
2024-02-12 01:25:12 -05:00
// let bot = bot;
2024-02-04 14:28:37 -05:00
2024-01-29 02:10:29 -05:00
for a in acts {
2024-01-29 04:09:53 -05:00
2024-02-13 07:54:35 -05:00
// println!(">> Inner listenermain_prvmsg() >> checking bot actions >> 2");
Log ::trace ( " >> Inner listenermain_prvmsg() >> checking bot actions >> 2 " ) ;
2024-02-01 09:43:39 -05:00
2024-02-04 14:28:37 -05:00
let _act = match a {
2024-01-29 04:09:53 -05:00
crate ::core ::botmodules ::BotAction ::C ( c ) = > {
/*
BotCommand handling -
2024-01-29 04:11:45 -05:00
- [ x ] Checks if the input message is a prefix with command name or alias
2024-01-29 22:57:07 -05:00
- [ ] Validate User can run based on identityModule ( From_Bot ) ::can_user_run (
_usr :String ,
_channelname :ChType ,
_chat_badge :ChatBadge ,
_cmdreqroles :Vec < UserRole > )
2024-01-29 04:09:53 -05:00
* /
2024-01-31 21:30:08 -05:00
// for v in msg.message_text.split(" ") {
// println!("args : {v}");
// }
2024-02-13 07:54:35 -05:00
// println!("Reviewing internal commands");
Log ::trace ( " Reviewing internal commands " ) ;
2024-02-12 02:34:32 -05:00
2024-01-29 04:09:53 -05:00
let inpt = msg . message_text . split ( " \n " ) . next ( ) . expect ( " ERROR during BotCommand " ) ;
2024-01-31 21:30:08 -05:00
let inpt = msg . message_text . split ( " " ) . next ( ) . expect ( " ERROR during BotCommand " ) ;
2024-01-29 04:09:53 -05:00
// [x] Check if a bot command based on ...
// [x] prefix + command
2024-01-29 06:18:27 -05:00
2024-01-29 22:57:07 -05:00
let mut confirmed_bot_command = false ;
2024-02-04 14:28:37 -05:00
2024-02-12 01:25:12 -05:00
let instr = bot . read ( ) . await . get_prefix ( ) ;
if inpt = = String ::from ( instr ) + c . command . as_str ( ) {
2024-01-29 22:57:07 -05:00
confirmed_bot_command = true ;
2024-01-29 04:09:53 -05:00
}
// [x] prefix + alias
for alias in & c . alias {
2024-02-12 14:54:35 -05:00
2024-02-12 01:25:12 -05:00
let instr = bot . read ( ) . await . get_prefix ( ) ;
if inpt = = String ::from ( instr ) + alias . as_str ( ) {
2024-01-29 22:57:07 -05:00
confirmed_bot_command = true ;
2024-01-29 04:09:53 -05:00
}
}
2024-01-29 06:18:27 -05:00
2024-01-29 22:57:07 -05:00
if confirmed_bot_command {
2024-02-13 07:54:35 -05:00
// println!("Confirmed bot command");
Log ::debug ( " Confirmed bot command " ) ;
2024-02-04 14:28:37 -05:00
2024-02-13 07:54:35 -05:00
// println!("Going for botlock");
Log ::trace ( " Going for botlock " ) ;
2024-02-12 01:25:12 -05:00
let botlock = bot . read ( ) . await ;
2024-02-13 07:54:35 -05:00
// println!("Going for identity");
Log ::trace ( " Going for identity " ) ;
2024-02-12 01:25:12 -05:00
let id = botlock . get_identity ( ) ;
2024-02-12 14:54:35 -05:00
2024-02-12 05:25:38 -05:00
let eval = {
let mut id = id . write ( ) . await ;
2024-02-13 07:54:35 -05:00
// println!("Unlocking identity");
Log ::trace ( " Unlocking identity " ) ;
let ( a , b ) = id . can_user_run_PRVMSG ( & msg , c . required_roles . clone ( ) ) . await ;
// // [-] #todo : need ot add functionality around here to do an o7 when a mod has been promoted => Preferring to do this outside the mutex
// if let ChangeResult::Success(b) = b {
// // let b = b.to_lowercase();
// // let b = b.contains(&"Auto Promoted Mod".to_lowercase());
// if b.to_lowercase().contains(&"Auto Promoted Mod".to_lowercase()) {
// let chat =
// }
// }
( a , b )
2024-02-12 05:25:38 -05:00
} ;
2024-02-13 07:54:35 -05:00
// println!("Checking if permissible");
Log ::trace ( " Checking if permissible " ) ;
let ( eval , rolechange ) = eval ;
if let ChangeResult ::Success ( b ) = rolechange {
if b . to_lowercase ( ) . contains ( & " Auto Promoted Mod " . to_lowercase ( ) ) {
// println!("Read() lock Bot");
Log ::trace ( " Read() lock Bot " ) ;
let botlock = bot . read ( ) . await ;
let outstr = " o7 a Mod. I kneel to serve! pepeKneel " . to_string ( ) ;
( * botlock ) . botmgrs . chat . say_in_reply_to ( msg , outstr ) . await ;
}
}
2024-02-12 01:25:12 -05:00
match eval {
2024-01-29 22:57:07 -05:00
Permissible ::Allow = > {
2024-02-13 07:54:35 -05:00
// println!("Executed as permissible");
Log ::debug ( " Executed as permissible " ) ;
2024-02-12 01:25:12 -05:00
let a = Arc ::clone ( & bot ) ;
2024-02-12 05:25:38 -05:00
c . execute ( a , msg . clone ( ) ) . await ;
2024-02-13 07:54:35 -05:00
// println!("exit out of execution");
Log ::trace ( " exit out of execution " ) ;
2024-02-04 14:28:37 -05:00
2024-01-29 22:57:07 -05:00
}
2024-02-01 09:43:39 -05:00
Permissible ::Block = > {
2024-02-13 07:54:35 -05:00
// println!("User Not allowed to run command");
Log ::info ( " User Not allowed to run command " ) ;
2024-02-01 09:43:39 -05:00
} ,
2024-01-29 22:57:07 -05:00
// _ => (),
2024-02-01 09:43:39 -05:00
} ;
2024-02-12 06:30:42 -05:00
} ;
2024-01-29 22:57:07 -05:00
2024-02-12 05:25:38 -05:00
2024-01-29 06:18:27 -05:00
}
2024-02-12 14:54:35 -05:00
2024-01-29 04:09:53 -05:00
} ,
2024-02-04 14:28:37 -05:00
crate ::core ::botmodules ::BotAction ::L ( l ) = > {
2024-02-12 01:25:12 -05:00
let a = Arc ::clone ( & bot ) ;
2024-02-12 05:25:38 -05:00
l . execute ( a , msg . clone ( ) ) . await ;
2024-02-04 14:28:37 -05:00
} ,
2024-02-01 09:43:39 -05:00
2024-01-29 04:09:53 -05:00
_ = > ( ) ,
2024-02-01 09:43:39 -05:00
} ;
2024-01-29 02:10:29 -05:00
}
} ;
2023-12-23 12:29:20 -05:00
2024-02-01 09:43:39 -05:00
2023-12-23 12:29:20 -05:00
// // [ ] There should be a BotCommand Listener to check for prefixes ran
2024-02-13 07:54:35 -05:00
// println!("End of Separate Listener Main prvmsg");
Log ::trace ( " End of Separate Listener Main prvmsg " ) ;
2023-12-22 21:09:36 -05:00
2024-02-12 01:25:12 -05:00
// self
// bot
2024-02-13 07:54:35 -05:00
Log ::flush ( ) ;
2023-12-20 17:55:46 -05:00
}
2023-12-22 21:09:36 -05:00
2023-12-20 17:55:46 -05:00
}
2023-12-22 21:09:36 -05:00
2023-12-28 06:02:55 -05:00
// ======================================
// ======================================
// ======================================
// ======================================
// UNIT TEST MODULES
#[ cfg(test) ]
mod tests {
fn always ( ) {
assert_eq! ( 1 , 1 ) ;
}
}