comments cleanup

This commit is contained in:
ModulatingForce 2024-01-29 03:20:56 -05:00
commit 3585c1ec9b
4 changed files with 13 additions and 583 deletions

View file

@ -16,19 +16,9 @@ use std::collections::HashMap;
use rand::Rng;
//mod sub::ratelimiter;
use crate::core::ratelimiter::RateLimiter;
use crate::core::ratelimiter;
// use crate::core::ratelimiter;
// pub fn init() -> ()
// {
// println!("I was here");
// }
// use crate::core::botmodules::BotAction
use crate::core::botmodules;
use crate::core::botmodules::ModulesManager;
@ -47,20 +37,6 @@ pub enum ModType {
pub use ModType::BotModule;
// pub enum EnType {
// Enabled(ChType),
// }
// pub use EnType::Enabled;
// pub enum ModStatusType {
// Enabled(EnType),
// Disabled(EnType),
// Enabled(ModType),
// Disabled(ModType),
// }
#[derive(Clone)]
pub struct Chat {
pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
@ -78,10 +54,14 @@ impl Chat {
pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
// envelops a message before sending a message
// [x] This could include additional formatting (e.g., add in random number of blank spaces)
// [x] Incrementing or checking with RateLimiters
// [ ] For BotActions of Enabled Modules , checking whether the caller is Permissible to run the command ?
/*
formats message before sending to TwitchIRC
- [x] Custom String Formatting (e.g., adding random black spaces)
- [x] Ratelimiter Handling
- [ ] Checkf if BotActions is Enabled & Caller is Allowed to Run
*/
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
@ -148,48 +128,23 @@ impl Chat {
// pub struct BotInstance<F>
// where
// // F: std::future::Future + ?Sized,
// // F: std::future::Future,
// //F: std::future::Future + Send,
// F: Send + ?Sized,
pub struct BotInstance
{
prefix : char,
bot_channel : ChType,
//pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
pub incoming_messages : UnboundedReceiver<ServerMessage>,
// pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
pub chat : Chat,
// botmodules : HashMap<ModType,Vec<EnType>>,
// pub botmodules : ModulesManager<F>,
pub botmodules : ModulesManager,
//pub botmodules : &'static mut ModulesManager,
twitch_oauth : String,
pub bot_channels : Vec<ChType>,
/*bot_commands : Vec[BotCommand],
bot_listeners : Vec[Listener],
bot_routines : Vec[Routine],*/
// botactionsdb : botactionsdb:botactions,
// identity : identitymodule,
}
// impl<F> BotInstance<F>
// where
// // F: std::future::Future + 'static,
// //F: 'static,
// //F: std::future::Future + Send + ?Sized 'static,
// F: Send + ?Sized + 'static,
impl BotInstance
{
// pub fn init() -> BotInstance<F>
// where
// F: std::future::Future + 'static,
pub fn init() -> BotInstance
{
dotenv().ok();
@ -245,17 +200,9 @@ impl BotInstance
ratelimiters : ratelimiters,
client : client,
} ,
// ratelimiters : ratelimiters, // used to limit messages sent per channel
// botmodules : HashMap::new(),
botmodules : ModulesManager::init(),
//botmodules : bm,
twitch_oauth : oauth_token,
bot_channels : botchannels,
/*bot_commands : Vec[BotCommand],
bot_listeners : Vec[Listener],
bot_routines : Vec[Routine],*/
// botactionsdb : botactionsdb:botactions,
// identity : identitymodule,
bot_channels : botchannels,
};
@ -316,54 +263,6 @@ impl BotInstance
}
// pub async fn run(mut self) -> () {
// let join_handle = tokio::spawn(async move {
// while let Some(message) = self.incoming_messages.recv().await {
// // Below can be used to debug if I want to capture all messages
// // println!("Received message: {:?}", message);
// match message {
// ServerMessage::Notice(msg) => {
// if let Some(chnl) = msg.channel_login {
// println!("NOTICE : (#{}) {}", chnl, msg.message_text);
// }
// }
// ServerMessage::Privmsg(msg) => {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// println!("Privmsg section");
// // b.listener_main_prvmsg(&msg);
// self.listener_main_prvmsg(&msg).await;
// // - BotCommand listener should likely need to be called within the above
// },
// ServerMessage::Whisper(msg) => {
// println!("(w) {}: {}", msg.sender.name, msg.message_text);
// },
// ServerMessage::Join(msg) => {
// println!("JOINED: {}", msg.channel_login);
// },
// ServerMessage::Part(msg) => {
// println!("PARTED: {}", msg.channel_login);
// },
// _ => {}
// }
// }
// });
// join_handle.await.unwrap();
// }
// -----------------
// PRIVATE FUNCTIONS
@ -372,37 +271,6 @@ impl BotInstance
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// // // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
// let contextratelimiter = self.ratelimiters
// .get_mut(&Channel(String::from(&msg.channel_login)))
// .expect("ERROR: Issue with Rate limiters");
// // let contextratelimiter = self.ratelimiters.get(&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);
// //let mut outmsg = "GotTrolled ".to_owned();
// let mut outmsg = "annytfLurk ".to_owned();
// for _i in 1..maxblanks {
// let blankspace: &str = "󠀀";
// outmsg.push_str(blankspace);
// }
// // client.say_in_reply_to(&msg,outmsg).await.unwrap();
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
// println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
// contextratelimiter.increment_counter();
// println!("{:?}",self.ratelimiters);
// },
// ratelimiter::LimiterResp::Skip => {
// (); // do nothing otherwise
// }
// self.chat.say_in_reply_to(msg,String::from("annytfLurk")).await;
// // [ ] 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)
for (_m,acts) in &self.botmodules.botactions {