comments cleanup

This commit is contained in:
ModulatingForce 2024-02-12 14:54:35 -05:00
parent a83e77ddcf
commit bac99f5845
5 changed files with 19 additions and 775 deletions

View file

@ -57,18 +57,8 @@ pub enum ChType {
pub use ChType::Channel;
// pub enum ModType {
// BotModule(String),
// }
// pub use ModType::BotModule;
#[derive(Clone)]
pub struct Chat {
// pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
pub ratelimiters : Arc<Mutex<HashMap<ChType,RateLimiter>>>, // used to limit messages sent per channel
pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
}
@ -84,7 +74,6 @@ impl Chat {
}
}
// pub fn init_channel(&mut self, chnl:ChType) -> () {
pub async fn init_channel(&mut self, chnl:ChType) -> () {
let n = RateLimiter::new();
self.ratelimiters.lock().await.insert(chnl,n);
@ -103,31 +92,23 @@ impl Chat {
*/
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
// // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
let a = Arc::clone(&self.ratelimiters);
let mut a = a.lock().await;
// let contextratelimiter = self.ratelimiters
let contextratelimiter = a
// .get_mut()
.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();
@ -184,14 +165,8 @@ impl BotManagers {
pub fn init(ratelimiters:HashMap<ChType, RateLimiter>,
client:TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>)
-> BotManagers {
// let a = Arc::new(Mutex::new(BotManagers {
// // botmodules : ModulesManager::init(),
// identity : Arc::new(Mutex::new(IdentityManager::init())),
// chat : Chat::init(ratelimiters,client),
// }));
// a
BotManagers {
// botmodules : ModulesManager::init(),
identity : Arc::new(RwLock::new(IdentityManager::init())),
chat : Chat::init(ratelimiters,client),
}
@ -201,9 +176,6 @@ impl BotManagers {
self.identity
}
// pub fn rChat(&self) -> Arc<Mutex<Chat>> {
// Arc::new(Mutex::new(self.chat))
// }
}
@ -222,15 +194,10 @@ pub struct BotInstance
{
pub prefix : char,
pub bot_channel : ChType,
// pub incoming_messages : UnboundedReceiver<ServerMessage>,
pub incoming_messages : Arc<RwLock<UnboundedReceiver<ServerMessage>>>,
// pub incoming_messages : RefCell<UnboundedReceiver<ServerMessage>>,
// pub chat : Chat,
pub botmodules : Arc<ModulesManager>,
pub twitch_oauth : String,
pub bot_channels : Vec<ChType>,
// pub identity : IdentityManager,
// pub botmgrs : Arc<Mutex<BotManagers>>,
pub botmgrs : BotManagers,
}
@ -240,8 +207,6 @@ impl BotInstance
{
// pub fn init() -> BotInstance
// pub fn init() -> Arc<BotInstance>
pub async fn init() -> BotInstance
{
dotenv().ok();
@ -284,154 +249,34 @@ impl BotInstance
// let bm = &mut ModulesManager::init();
let b = BotInstance {
prefix : prefix,
bot_channel : Channel(login_name) ,
incoming_messages : Arc::new(RwLock::new(incoming_messages)),
//client : client,
// chat : Chat {
// ratelimiters : ratelimiters,
// client : client,
// } ,
botmodules : ModulesManager::init().await,
twitch_oauth : oauth_token,
bot_channels : botchannels,
// identity : IdentityManager::init(),
botmgrs : BotManagers::init(ratelimiters,client),
};
//println!("{:?}",b.botmgrs.chat.ratelimiters);
// Arc::new(b)
//Arc::new(RwLock::new(b))
b
}
// async fn rcv_helper(self) -> Option<ServerMessage> {
// // self.incoming_messages.get_mut().recv().await
// let mut a = self.incoming_messages;
// a.get_mut().recv().await
// }
// pub async fn runner(mut self) -> () {
// pub async fn runner(&'static mut self) -> () {
pub async fn runner(self) -> () {
// let bot_am = Arc::new(Mutex::new(self));
// let mut boxed_bot = Arc::new(RefCell::new(self)); // <-- [ERROR] Future cannot be handled safely
let bot = Arc::new(RwLock::new(self));
let join_handle = tokio::spawn(async move {
// let boxed_bot = Arc::new(Mutex::new(self));
// let mut boxed_bot = Arc::new(self);
// let bot = Rc::new(RefCell::new(self));
// let mut bot = Rc::new(RefCell::new(&self));
//let bot = Arc::new(Mutex::new(&self));
// let mut boxed_bot = Arc::new(RefCell::new(self));
// let mut boxed_bot = Arc::new(Mutex::new(self));
// while let Some(message) = bot.borrow_mut().incoming_messages.recv().await {
// let bot = Arc::clone(&botinit);
// while let Some(message) = bot.lock().unwrap().incoming_messages.recv().await {
//let b = Arc::clone(&bot);
// let mut bot = RefCell::new(&self);
// let mut bota = bot.clone().borrow();
// let boxed_bot = Rc::new(RefCell::new(self));
// let boxed_bot = Rc::new(self);
// let boxed_bot = Pin::new(Rc::new(self));
//let mut boxed_bot = Rc::new(RefCell::new(self));
// let mut a = (*boxed_bot).clone().into_inner();
// let mut a = Rc::clone(&boxed_bot).borrow_mut();
//let mut a = Rc::<Rc<RefCell<BotInstance>>>::Borrow(Rc::clone(&boxed_bot));
// while let Some(message) = Rc::clone(&boxed_bot).into_inner().incoming_messages.recv().await {
// while let Some(message) = Rc::<BotInstance>::borrow(Rc::<BotInstance>::as_ref(boxed_bot)) {
// let a = boxed_bot.borrow();
// let boxed_bota = boxed_bot.borrow_mut();
// let a = Rc::try_unwrap(boxed_bot).ok().unwrap().into_inner();
// let boxed_bot = RefCell::new(Rc::new(self));
//let boxed_bot = Rc::new(RefCell::new(self));
// Rc::try_unwrap(boxed_bot).ok().unwrap().into_inner().incoming_messages.recv().await;
// let a:Borrowed = boxed_bot.borrow();
// while let Some(message) = Rc::try_unwrap(boxed_bot).ok().unwrap().into_inner().incoming_messages.recv().await {
// while let Some(message) = RefCell::new(self).borrow_mut().incoming_messages.recv().await {
// while let Some(message) = Rc::try_unwrap(boxed_bot).ok().unwrap().into_inner().incoming_messages.recv().await {
// while let Some(message) = Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().rcv_helper().await {
// while let Some(message) = Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().incoming_messages.recv().await {
// let mut a = Arc::try_unwrap(boxed_bot.clone())
// .ok().unwrap()
// .into_inner()
// .ok().unwrap();
// let a = Arc::clone(&boxed_bot).into_inner().unwrap().incoming_messages;
// .into_inner()
// .try_into().
// .ok().unwrap();
// while let Some(message) = a.lock().unwrap().incoming_messages.recv().await {
// while let Some(message) = a.recv().await {
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap();
// let mut a = Arc::try_unwrap(boxed_bot.clone())
// .ok()
// .unwrap();
// .into_inner()
// .get_mut()
// .ok();
// .unwrap();
//let mut a = a.lock().unwrap();
// let a = *a;
// while let Some(message) = a.lock().ok().unwrap().incoming_messages.recv().await {
// while let Some(message) = a.get_mut().expect("Error").incoming_messages.recv().await {
//let tempbot = boxed_bot.clone();
// while let Some(message) = Arc::try_unwrap(tempbot.clone()).ok().unwrap().into_inner().ok().unwrap().incoming_messages.recv().await {
// while let Some(message) = Arc::try_unwrap(tempbot.clone()).ok().unwrap().incoming_messages.recv().await {
// while let Some(message) = boxed_bot.to_owned().incoming_messages.recv().await {
// while let Some(message) = self.incoming_messages.recv().await {
// let a:Arc<RefCell<BotInstance>> = Arc::clone(&boxed_bot);
// while let Some(message) = a.incoming_messages.recv().await {
// let a = Arc::clone(&boxed_bot).into_inner();
// while let Some(message) = a.incoming_messages.recv().await {
// let tempbot = boxed_bot.clone();
// while let Some(message) = Arc::try_unwrap(tempbot.clone()).ok().unwrap().into_inner().incoming_messages.recv().await {
// let tempbot = Arc::clone(&boxed_bot);
// while let Some(message) = tempbot.lock().await.incoming_messages.recv().await {
let a = bot.read().await;
let mut a = a.incoming_messages.write().await;
while let Some(message) = a.recv().await {
// while let Some(message) = tempbot.into_inner().incoming_messages.recv().await {
//while let Some(message) = boxed_bot.borrow().incoming_messages.recv().await {
// // Below can be used to debug if I want to capture all messages
// println!("Received message: {:?}", message);
// let boxed_bot = Arc::new(self);
match message {
ServerMessage::Notice(msg) => {
// if let Some(chnl) = msg.channel_login {
// println!("NOTICE : (#{}) {}", chnl, msg.message_text);
// }
match &msg.channel_login {
Some(chnl) => println!("NOTICE : (#{}) {}", chnl, msg.message_text),
None => println!("NOTICE : {}", msg.message_text),
@ -442,59 +287,8 @@ impl BotInstance
println!("Privmsg section");
// b.listener_main_prvmsg(&msg);
// self.listener_main_prvmsg(&msg).await;
// bot.into_inner().listener_main_prvmsg(&msg).await;
//let bot = Rc::<RefCell<&BotInstance>>::clone(&bot);
// bot.borrow().listener_main_prvmsg(&msg).await;
// let mut a = Rc::Clone(&bot);
// a.borrow_mut().listener_main_prvmsg(&msg).await;
// bot.borrow_mut().into_inner().listener_main_prvmsg(&msg).await;
// bot.listener_main_prvmsg(&msg).await;
// bot.lock().unwrap().listener_main_prvmsg(&msg).await;
// bot.borrow_mut().listener_main_prvmsg(&msg).await;
// Rc::clone(&boxed_bot).into_inner().listener_main_prvmsg(&msg).await;
// boxed_bot.borrow().listener_main_prvmsg(&msg).await;
// let bottemp = boxed_bot.borrow_mut();
// let a = **bottemp;
// Rc::try_unwrap(boxed_bot).ok().unwrap().into_inner().listener_main_prvmsg(&msg).await;
// Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().listener_main_prvmsg(&msg).await;
// Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().ok().unwrap().listener_main_prvmsg(&msg).await;
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap();
// let mut a = a.lock().unwrap();
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap();
// a.listener_main_prvmsg(&msg).await;
// (*a).listener_main_prvmsg(&msg).await;
// let a:Arc<RefCell<BotInstance>> = Arc::clone(&boxed_bot);
// a.into_inner().listener_main_prvmsg(&msg).await;
// let tempbot = boxed_bot.clone();
// Arc::try_unwrap(tempbot.clone()).ok().unwrap().into_inner().listener_main_prvmsg(&msg).await ;
// let tempbot = Arc::clone(&tempbot);
// // let a = tempbot.lock().await;
// tempbot.lock().await.listener_main_prvmsg(&msg).await;
// self.listener_main_prvmsg(&msg).await;
// bot.read().await.listener_main_prvmsg(&msg).await;
// let a = bot.read().await;
// a.listener_main_prvmsg(&msg).await;
// a.listener_main_prvmsg(&msg).await;
// let a = bot.read().await;
BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
// let a = bot.read().await;
// a.lis
//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);
@ -522,105 +316,31 @@ impl BotInstance
pub fn get_botmodules(self) -> Arc<ModulesManager> {
// let a = self.botmodules;
// Arc::clone(&Arc::new(Mutex::new(self.botmodules)))
// *self.botmodules
self.botmodules
}
// pub fn get_botactions(self:&Self) -> (Self,HashMap<botmodules::ModType,Vec<BotAction>>) {
// // self.get_botactions()
// // (*self,(*self).botmodules.rbotactions())
// (Self { bot_channel},(*self).botmodules.rbotactions())
// }
// pub fn get_botactions(&self) -> (Self,HashMap<botmodules::ModType,Vec<BotAction>>) {
// pub fn get_botactions(&self) -> HashMap<botmodules::ModType,Vec<BotAction>> {
// // self.get_botactions()
// // (*self,(*self).botmodules.rbotactions())
// // (self,self.botmodules.rbotactions())
// // (*self).botmodules.rbotactions()
// // let a = (*self).botmodules.rbotactions();
// let a =
// a
// }
}
pub async fn get_botmgrs(self) -> BotManagers {
// Arc::new(self.botmgrs)
// Arc::clone(&Arc::new(Mutex::new(self.botmgrs)))
let a = self.botmgrs;
// let a = *a.lock().await;
// let a = a.rIdentity();
a
}
// pub fn get_identity(self:&Self) -> (Self,IdentityManager) {
pub fn get_identity(&self) -> Arc<RwLock<IdentityManager>> {
// // let a = self.botmgrs;
// // Arc::clone(&Arc::new(Mutex::new(a.rIdentity())))
// // let a = self.botmgrs;
// // Arc::clone(&Arc::new(Mutex::new(a.rIdentity())))
// let a = self.get_botmgrs().await;
// let a = a.lock().await;
// // let a = a.rIdentity();
// let a = a.clone().identity;
// a.clone()
// let id = (*self).botmgrs.identity;
// id
Arc::clone(&self.botmgrs.identity)
}
// pub fn get_prefix(self) -> (Self,char) {
pub fn get_prefix(&self) -> char {
// self.prefix.to_string()
// let a = self.prefix;
// a.clone().to_string()
// (self,self.prefix)
(*self).prefix
}
// pub fn get_prefix(self:&Self) -> (Self,String) {
// (*self,(*self).prefix.to_string())
// }
// pub fn get_prefix(self:Self) -> (Self,String) {
// let str1 = self.prefix.to_string();
// (self,str1)
// }
// pub fn get_prefix(&self) -> String {
// // self.prefix.to_string()
// let a = self.prefix;
// a.clone().to_string()
// }
// pub fn get_prefix(self) -> (Self,String) {
// // self.prefix.to_string()
// // let a = self.prefix;
// // a.clone().to_string()
// (Self {
// prefix : self.prefix ,
// bot_channel : self.bot_channel ,
// incoming_messages : self.incoming_messages ,
// botmodules : self.botmodules,
// twitch_oauth : self.twitch_oauth,
// bot_channels : self.bot_channels ,
// // identity : IdentityManager::init(),
// botmgrs: self.botmgrs ,
// },
// self.prefix.to_string())
// }
// -----------------
// PRIVATE FUNCTIONS
// async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () {
// async fn listener_main_prvmsg(&mut self,msg:&PrivmsgMessage) -> () {
// async fn listener_main_prvmsg(self,msg:&PrivmsgMessage) -> () {
// async fn listener_main_prvmsg(self:Arc<Self>,msg:&PrivmsgMessage) -> () {
pub async fn listener_main_prvmsg(bot:BotAR,msg:&PrivmsgMessage) -> () {
println!(">> Inner listenermain_prvmsg()");
@ -629,51 +349,6 @@ impl BotInstance
// // [ ] 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)
// let botmgr = Rc::new(&self.botmgrs);
// let mut boxedbot = Rc::new(RefCell::new(self));
// let boxed_bot = Rc::new(RefCell::new(self));
// let boxed_bot = Arc::new(Mutex::new(self));
// let boxed_bot = Arc::new(self);
//let boxed_bot = Arc::clone(self);
// let mut boxed_bot = Arc::new(RefCell::new(self));
// let mut boxed_bot = Arc::new(RwLock::new(self));
// let boxed_bot = Arc::new(RwLock::new(self));
// let boxed_bot = Arc::new(Mutex::new(self));
//let boxed_bot = Arc::new(Mutex::new(self));
// let bot = Arc::new(RwLock::new(self));
// for (_m,acts) in &self.botmodules.botactions {
// for (_m,acts) in &self.botmodules.botactions {
// for (_m,acts) in bot.into_inner().botmodules.botactions {
// let mut bot = Rc::clone(&bot);
// for (_m,acts) in bot.into_inner().botmodules.botactions {
// for (_m,acts) in bot.into_inner().botmodules.botactions {
// for (_m,acts) in Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().botmodules.botactions {
// for (_m,acts) in Arc::try_unwrap(boxed_bot.clone()).ok() .unwrap().into_inner().ok().unwrap().botmodules.botactions {
// for (_m,acts) in Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().botmodules.botactions {
// for (_m,acts) in Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().botmodules.botactions {
// let a = Arc::try_unwrap(boxed_bot).ok().unwrap().read().unwrap().botmodules.botactions
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap();
// let b = a.read().unwrap();
// for (_m,acts) in a.read().unwrap().botmodules.botactions {
// for (_m,acts) in b.rbotmodules().botactions {
// for (_m,acts) in b.rbotactions() {
// for (_m,acts) in (*Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().read().unwrap()).rbotactions() {
// let a = boxed_bot.clone().into_inner();
// let a = boxed_bot.lock().await;
//let a = a.lock().in
// for (_m,acts) in self.rbotactions() {
// for (_m,acts) in a.read().ok().unwrap().rbotactions() {
// for (_m,acts) in a.into_inner().ok().unwrap().rbotactions() {
// let bot = self;
// let mut instr:char;
// let hacts = self.get_botactions();
// let hacts = boxed_bot.clone().lock().await.get_botactions();
// let hacts = bot.read().await.get_botactions();
let botlock = bot.read().await;
let hacts = Arc::clone(&botlock.botmodules.botactions);
// let hacts = hacts.read().await;
@ -681,9 +356,7 @@ impl BotInstance
println!("hacts size : {}",(*a).len());
println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
// println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions : {:?}",*hacts);
// let hacts = hacts
// let l = *hacts;
for (_m,acts) in &*hacts.read().await {
println!(">> Inner listenermain_prvmsg() >> checking bot actions");
@ -725,28 +398,6 @@ impl BotInstance
let mut confirmed_bot_command = false;
// if inpt == self.prefix.to_string() + c.command.as_str() {
// if inpt == Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().prefix.to_string() + c.command.as_str() {
// let a = Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().prefix.to_string();
// let a = Arc::try_unwrap(boxed_bot.clone()).ok() .unwrap().into_inner().ok().unwrap().prefix.to_string();
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().prefix.to_string();
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().prefix.to_string();
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap();
// let a = (*Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().read().unwrap());
// let a = (*Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().read().unwrap()).prefix.to_string();
// let a = self.prefix.to_string();
// let a = boxed_bot.clone();
// if inpt == a.into_inner().ok().unwrap().prefix.to_string() + c.command.as_str() {
// if inpt == a.into_inner().ok().unwrap().prefix.to_string() + c.command.as_str()
// let a = boxed_bot.lock().await;
//
// if inpt == a.into_inner().prefix.to_string() + c.command.as_str() {
// if inpt == a.get_prefix() + c.command.as_str() {
// if inpt == self.get_prefix() + c.command.as_str() {
// let instr = self.get_prefix();
// let instr = boxed_bot.clone().lock().await.get_prefix();
// let instr = bot.read().await.get_prefix();
let instr = bot.read().await.get_prefix();
if inpt == String::from(instr) + c.command.as_str() {
confirmed_bot_command = true;
@ -754,23 +405,7 @@ impl BotInstance
// [x] prefix + alias
for alias in &c.alias {
// if inpt == self.prefix.to_string() + alias.as_str() {
// if inpt == Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().prefix.to_string() + alias.as_str() {
//
// if inpt == Arc::try_unwrap(boxed_bot.clone()).ok() .unwrap().into_inner().ok().unwrap().prefix.to_string() + alias.as_str() {
// Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner()
// if inpt == Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().prefix.to_string() + alias.as_str() {
// if inpt == Arc::try_unwrap(boxed_bot).ok().unwrap().read().unwrap().prefix.to_string() + alias.as_str() {
// if inpt == self.prefix.to_string() + alias.as_str() {
// let a = boxed_bot.clone();
// let a = boxed_bot.lock().await;
// if inpt == a.into_inner().ok().unwrap().prefix.to_string() + alias.as_str() {
// if inpt == a.into_inner().prefix.to_string() + alias.as_str() {
// if inpt == a.get_prefix() + alias.as_str() {
// if inpt == self.get_prefix() + alias.as_str() {
// let instr = self.get_prefix();
// let instr = boxed_bot.clone().lock().await.get_prefix();
// let instr = bot.read().await.get_prefix();
let instr = bot.read().await.get_prefix();
if inpt == String::from(instr) + alias.as_str() {
confirmed_bot_command = true;
@ -779,72 +414,12 @@ impl BotInstance
if confirmed_bot_command {
println!("Confirmed bot command");
// self.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone());
// [ ] Around here, validate if permissable before executing
// match self.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// Ok(Permissible::Allow) => c.execute(self.chat.clone(), msg.clone()).await,
// Ok(Permissible::Block) => println!("User Not allowed to run command"),
// _ => (),
// }
// match self.botmgrs.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match self.botmgrs.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// let botref = Rc::clone(&botmgr);
// if let Rc(botmgr) = botref {
// ()
// }
// match self.botmgrs.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match boxed_bot.clone().into_inner().botmgrs.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match Rc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner().botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
//let boxed_bot1 = Arc::clone(&boxed_bot);
//let a = boxed_bot1.into_inner().ok().unwrap();
// match boxed_bot1.into_inner().ok().unwrap().botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match Arc::try_unwrap(boxed_bot.clone())
// .ok()
// .unwrap().into_inner().ok().unwrap().botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// let a = Arc::try_unwrap(boxed_bot.clone()).ok() .unwrap().into_inner();
// let a = Arc::try_unwrap(boxed_bot.clone()).ok().unwrap();
// Arc::try_unwrap(boxed_bot.clone()).ok().unwrap().into_inner()
// match a.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match Arc::try_unwrap(boxed_bot).ok().unwrap().read().unwrap().botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match (boxed_bot.clone().into_inner().ok().unwrap()).botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// let a = boxed_bot.clone();
// let a = boxed_bot.lock().await;
// // let a = a.read().ok().unwrap().botmgrs.identity;
// let a = a.get_identity();
// // let a = a.lock().await.can_user_run_PRVMSG(&msg, c.required_roles.clone()) ;
// match a.lock().await.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await {
// let le = boxed_bot.lock().await;
// // let le = le.lock().await;
// let le = le.get_identity().await;
// let le = *le;
// let le = le.lock().await;
// let le = le.clone();
// let le = le.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await;
// let le = self.get_identity().await.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await;
// let le = self.botmgrs;
// let le = le.identity;
// let (bot,id) = self.get_identity();
// let id = boxed_bot.clone().lock().await.get_identity();
// let id = bot.read().await.get_identity();
// let id = Arc::clone(&self.botmgrs.identity);
// let id = id.write().await;
// let id = &(*self.get_identity());
println!("Going for botlock");
let botlock = bot.read().await;
println!("Going for identity");
let id = botlock.get_identity();
// let mut id = id.write().await;
// println!("Unlocking identity");
// let eval= id.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await;
let eval = {
let mut id = id.write().await;
println!("Unlocking identity");
@ -852,22 +427,9 @@ impl BotInstance
};
println!("Checking if permissible");
match eval {
// Ok(Permissible::Allow) => (),
Permissible::Allow => {
println!("Executed as permissible");
// c.execute(bot, msg.clone()).await;
// if let bot = Rc::<RefCell<BotInstance>>::clone(*bot) {
// c.execute(bot, msg.clone()).await;
// }
// let boxed_bot = Arc::new(RwLock::new(self));
// c.execute(boxed_bot.clone(), msg.clone()).await;
// c.execute(self, msg.clone()).await;
//let mut a = *self;
// c.execute(self, msg.clone());
// let a = self;
// let a = Arc::clone(&self);
let a = Arc::clone(&bot);
// let a = Arc::clone(&bot);
c.execute(a, msg.clone()).await;
println!("exit out of execution");
@ -879,21 +441,12 @@ impl BotInstance
};
};
// c.execute(self.chat.clone(), msg.clone()).await;
}
// None::<&PrivmsgMessage> // [ ] Command not confirmed?
},
crate::core::botmodules::BotAction::L(l) => {
// if let bot = Rc::clone(&bot) {
// l.into_inner().execute(bot, msg.clone()).await
// }
//let bot = Rc::clone(&bot).into_inner();
// l.execute(boxed_bot.clone(), msg.clone()).await
// let boxed_bot = Arc::new(RwLock::new(self));
// l.execute(boxed_bot.clone(), msg.clone()).await;
// let a = Arc::clone(&self);
let a = Arc::clone(&bot);
l.execute(a, msg.clone()).await;
},
@ -904,7 +457,6 @@ impl BotInstance
};
// // [ ] There should be a BotCommand Listener to check for prefixes ran
println!("End of Separate Listener Main prvmsg");

View file

@ -88,7 +88,7 @@ pub enum BotAction
}
impl BotAction {
// pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){
pub async fn execute(&self,m:BotAR,n:PrivmsgMessage) -> ()
{
@ -105,7 +105,6 @@ impl BotAction {
pub trait BotActionTrait
{
async fn add_to_bot(self, bot:BotInstance);
// async fn add_to_modmgr(self,modmgr:&'static ModulesManager);
async fn add_to_modmgr(self,modmgr:Arc<ModulesManager>);
}
@ -122,20 +121,8 @@ pub struct BotCommand {
impl BotCommand
{
// pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){
// pub async fn execute(&self,m:Rc<&botinstance::BotManagers>,n:PrivmsgMessage){
// pub async fn execute(&self,m:BotInstance,n:PrivmsgMessage){
// (self.exec_body)(m,n).await;
// }
// pub fn execute(&self,m:&mut BotInstance,n:PrivmsgMessage) -> () {
// pub fn execute(&self,m:actions_util::BotAR,n:PrivmsgMessage) -> () {
pub async fn execute(&self,m:BotAR,n:PrivmsgMessage) -> () {
// ((*self).exec_body)(m,n);
// ((*self).exec_body)(*m,n);
// m
// ((*self).exec_body)(
((*self).exec_body)(m,n).await;
// m
}
}
@ -143,18 +130,11 @@ impl BotCommand
impl BotActionTrait for BotCommand
{
async fn add_to_bot(self, bot:BotInstance) {
// let mgr = &mut bot.botmodules;
// let mut mgr = *mgr.lock().await;
// let mut mgr = &mut mgr;
// (*self).add_to_modmgr(bot.botmodules);
self.add_to_modmgr(bot.botmodules).await;
}
// async fn add_to_modmgr(self, modmgr:Arc<Mutex<ModulesManager>>) {
async fn add_to_modmgr(self, modmgr:Arc<ModulesManager>) {
// modmgr.add_botaction(self.module.clone(), BotAction::C(self))
// let modmgr = *modmgr.lock().await;
// modmgr.add_botaction(self.module.clone(), BotAction::C(self))
modmgr.add_botaction(self.module.clone(), BotAction::C(self)).await
}
@ -183,55 +163,10 @@ pub mod bot_actions {
pub type BotAM = Arc<Mutex<BotInstance>>;
pub type BotAR = Arc<RwLock<BotInstance>>;
// pub type ExecBody = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
//pub type ExecBody<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output=F> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(BotManagers,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Rc<&BotManagers>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Rc<&BotInstance>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Rc<RefCell<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Rc<RefCell<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Rc<RefCell<&BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<&BotInstance>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<RefCell<&BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(RefCell<&BotInstance>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Rc<RefCell<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<Mutex<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<BotInstance>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<RefCell<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<RwLock<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<Mutex<BotInstance>>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(BotInstance,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody<F> = Box<dyn Fn(&BotInstance,PrivmsgMessage) -> Pin<Box<dyn Future<Output=F> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(&'static BotInstance,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(&mut BotInstance,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
pub type ExecBody = Box<dyn Fn(BotAR,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub type ExecBody = Box<dyn Fn(Arc<BotInstance>,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
pub type ExecBody = Box<dyn Fn(BotAR,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
//pub fn asyncbox<T,F>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody<F>
// pub fn asyncbox<T>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(BotManagers,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Rc<&BotManagers>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Rc<RefCell<BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Rc<RefCell<&BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<&BotInstance>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<RefCell<&BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Rc<RefCell<BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<Mutex<BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<BotInstance>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<RefCell<BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<RwLock<BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(Arc<Mutex<BotInstance>>,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(BotInstance,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(&'static BotInstance,PrivmsgMessage) -> T) -> ExecBody
// pub fn asyncbox<T>(f: fn(&mut BotInstance,PrivmsgMessage) -> T) -> ExecBody
pub fn asyncbox<T>(f: fn(BotAR,PrivmsgMessage) -> T) -> ExecBody
where
//T: Future<Output=()> + Send + 'static
// T: Future<Output=F> + Send + 'static
T: Future<Output=()> + Send + 'static
{
Box::new(move |a,b| Box::pin(f(a,b)))
@ -253,19 +188,9 @@ pub struct Listener
impl Listener
{
// pub async fn execute(&self,m:BotInstance,n:PrivmsgMessage){
// (self.exec_body)(m,n).await;
// }
// pub fn execute(&self,m:BotInstance,n:PrivmsgMessage){
// (self.exec_body)(m,n);
// }
// pub fn execute(&self,m:&BotInstance,n:PrivmsgMessage) -> &BotInstance {
// pub fn execute(&self,m:actions_util::BotAR,n:PrivmsgMessage) -> () {
pub async fn execute(&self,m:BotAR,n:PrivmsgMessage) -> () {
// let mut m = Arc::*m;
((*self).exec_body)(m,n).await;
// *self
// &m
}
}
@ -274,22 +199,14 @@ impl BotActionTrait for Listener
{
async fn add_to_bot(self, bot:BotInstance) {
// let mgr = &mut bot.botmodules;
// let mgr = bot.botmodules;
// self.add_to_modmgr(Arc::new(*mgr));
println!("Adding action to bot");
self.add_to_modmgr(bot.botmodules).await;
}
// fn add_to_modmgr(self, modmgr:&mut ModulesManager) {
// async fn add_to_modmgr(self, modmgr:Arc<Mutex<ModulesManager>>) {
// async fn add_to_modmgr(self, modmgr:&'static ModulesManager) {
// async fn add_to_modmgr(self, modmgr:&'static ModulesManager) {
async fn add_to_modmgr(self, modmgr:Arc<ModulesManager>) {
// let modmgr = *modmgr.lock().await;
println!("Adding action to module manager");
modmgr.add_botaction(self.module.clone(), BotAction::L(self)).await;
// modmgr.add_botaction(self.module.clone(), BotAction:L(self))
}
}
@ -303,16 +220,13 @@ struct Routine {}
pub struct ModulesManager
{
// statusdb: HashMap<ModType,Vec<ModStatusType>>,
statusdb: Arc<RwLock<HashMap<ModType,Vec<ModStatusType>>>>,
// pub botactions: HashMap<ModType,Vec<BotAction>>,
pub botactions: Arc<RwLock<HashMap<ModType,Vec<BotAction>>>>,
}
impl ModulesManager
{
// pub fn init() -> Arc<Mutex<ModulesManager>>
pub async fn init() -> Arc<ModulesManager>
{
@ -326,38 +240,21 @@ impl ModulesManager
};
// :: [x] initialize core modules
// crate::core::identity::init(&mut mgr);
// let a = Arc::new(Mutex::new(mgr));
// // let a = a.clone();
// crate::core::identity::init(a.clone());
// crate::core::identity::init(&mgr);
println!("ModulesManager > init() > Adding modules");
let mgra = Arc::new(mgr);
crate::core::identity::init(Arc::clone(&mgra)).await;
// initialize custom crate modules
// crate::modules::init(&mut mgr);
// let a = a.clone();
// crate::modules::init(a.clone());
crate::modules::init(Arc::clone(&mgra)).await;
println!(">> Modules Manager : End of Init");
// mgr
mgra
}
// pub async fn rbotactions(&self) -> HashMap<ModType,Vec<BotAction>> {
// // (*self).botactions
// let a = self.botactions.read().await;
// *a
// }
pub fn modstatus(&self, _:ModType, _:ChType) -> ModStatusType {
// Example usage : botmanager.modstatus(
// BotModule("GambaCore"),
@ -382,9 +279,7 @@ impl ModulesManager
Ok("")
}
//pub fn add_botaction(mut self, in_module:ModType, in_action:BotAction ) -> ModulesManager {
// pub fn add_botaction(mut self, in_module:ModType, in_action:BotAction<F> ) -> ModulesManager<F> {
//pub fn add_botaction(&mut self, in_module:ModType, in_action:BotAction ) -> () {
pub async fn add_botaction(&self, in_module:ModType, in_action:BotAction ) {
println!("Add botaction called");
/*
@ -510,14 +405,6 @@ impl ModulesManager
None => (),
}
// {
// let mut lala = self;
// let statusvector = (*lala).statusdb
// // .entry(BotModule(String::from("experiments")))
// .entry(in_module.clone())
// .or_insert(Vec::new());
// }
let mut dbt = self.statusdb.write().await;
let statusvector = dbt
// .entry(BotModule(String::from("experiments")))
@ -537,14 +424,7 @@ impl ModulesManager
println!(">> Modules Manager : Called Add bot Action");
println!("add_botaction - botactions size : {}",modactions.len());
//println!(">> Modules Manager : {:?}",&self);
//();
//let mgr = self;
//mgr
//self
}

View file

@ -54,8 +54,6 @@ pub async fn init(mgr:Arc<ModulesManager>)
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
// async fn cmd_promote(mut bot:Arc<Mutex<BotInstance>>,msg:PrivmsgMessage)
// async fn cmd_promote(mut bot:&BotInstance,msg:PrivmsgMessage) -> &BotInstance
async fn cmd_promote(bot:BotAR,msg:PrivmsgMessage) -> ()
{
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
@ -88,7 +86,6 @@ pub async fn init(mgr:Arc<ModulesManager>)
*/
//let bot = Rcbot;
println!("{}",msg.message_text);
let mut argv = msg.message_text.split(" ");
@ -113,42 +110,7 @@ pub async fn init(mgr:Arc<ModulesManager>)
match arg1 {
Some(a1) if a1 == String::from("admin") => {
// - BotAdmins can promote admin to give BotAdmin UserRole
//let mut bot = Rc::clone(&bot);
// let a = bot.botmgrs.identity.getspecialuserroles(msg.sender.name.to_lowercase(), Some(ChType::Channel(msg.channel_login.to_lowercase())));
// let a = Rc::try_unwrap(bot).ok().unwrap().into_inner().botmgrs.identity.getspecialuserroles(msg.sender.name.to_lowercase(), Some(ChType::Channel(msg.channel_login.to_lowercase())));
// let a = Rc::try_unwrap(bot.clone()).ok().unwrap().into_inner().botmgrs.identity.getspecialuserroles(msg.sender.name.to_lowercase(), Some(ChType::Channel(msg.channel_login.to_lowercase())));
// let a = Rc::try_unwrap(bot).ok().unwrap()
// // .borrow_mut()
// .into_inner()
// .botmgrs
// .identity
// .getspecialuserroles(msg.sender.name.to_lowercase(),
// Some(ChType::Channel(msg.channel_login.to_lowercase())));
// let p = Rc::try_unwrap(bot.clone())
// let p = Arc::try_unwrap(bot.clone())
// .ok()
// .unwrap()
// //.into_inner()
// //.to_owned()
// // .get_mut()
// .into_inner();
// // .ok()
// // .unwrap();
// // let p = p.ok().unwrap();
// let p = bot.lock().await.get_identity();
// let p = p.lock().await;
// let ta = p.getspecialuserroles(String::from("Hello"), Some(ChType::Channel(msg.channel_login.to_lowercase()))).await;
// // let ta = *ta.await;
// let ta = *ta.lock().await;
// if let Some(a) = ta {
// let p = bot.lock().await.get_identity();
// let mut p = p.lock().await;
// let ta = p.getspecialuserroles(String::from("Hello"), Some(ChType::Channel(msg.channel_login.to_lowercase()))).await;
let botlock = bot.read().await;
let ta = botlock.get_identity();
let ta = ta.read().await;
@ -161,60 +123,14 @@ pub async fn init(mgr:Arc<ModulesManager>)
if a.contains(&UserRole::BotAdmin) {
println!("BotAdmin allowed to promote admin");
// let bota = Rc::clone(&bot);
// let bota = Rc::get_mut(&bota);
// match bota.botmgrs.identity.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
//let mut bot = Rc::clone(&bot);
// let bot = Rc::<&botinstance::BotInstance>::get_mut(&mut bot);
// let mut bot = Rc::make_mut(&mut bot);
// let mut bot = Rc::make_mut(&bot);
// match Rc::<&botinstance::BotInstance>::get_mut(bot) {
// Some(bot) => {
// match bot.botmgrs.identity.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// // Success(_) => {
// // ;
// // },
// ChangeResult::Success(a) => println!("Succesfully promoted : {a} ;"),
// ChangeResult::Failed(a) => println!("Failed to promote : {a} ; "),
// ChangeResult::NoChange(a) => println!("No Changes Made : {a} ; "),
// }
// },
// None => (),
// }
//let bot = Rc::<botinstance::BotInstance>::make_mut(bot);
// match Rc::<IdentityManager>::make_mut(&mut Rc::new(bot.botmgrs.identity)).promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// match Rc::try_unwrap(bot.clone()).ok().unwrap().into_inner().botmgrs.identity.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// match Arc::try_unwrap(bot.clone()).ok().unwrap().into_inner().ok().unwrap().botmgrs.identity.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// match Arc::try_unwrap(bot.clone()).ok().unwrap().into_inner().botmgrs.identity.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// match bot.read().ok().unwrap().get_identity().promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// let a = bot.get_mut();
// match a.get_identity().promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// let a = (*bot).clone();
{
// let a = bot.lock().await.get_botmgrs().clone();
// let a = bot.lock().await;
// let mut mutex = Arc::clone(&bot);
// match mutex.get_mut().get_identity().promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)) {
// slet ee = ArcBox(bot);
// println!("tester: {:?}",(*bot).lock().await.get_prefix());
// let mutex = Arc::clone(&bot);
// let mut mutex2 = Arc::new(*mutex).into_inner().get_identity();
// let mut mutex2 = Arc::clone(&mutex).into_inner().get_identity();
// let a = (*bot).lock().await.get_identity();
// let mut a = a.lock().await;
// let p = bot.lock().await.get_identity();
// let mut p = p.lock().await;
// let ta = p.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)).await;
let botlock = Arc::clone(&bot.read().await.get_identity());
let idlock = botlock.write().await;
// let mut idlock = *idlock;
let ta = idlock.promote(msg.sender.name.to_lowercase(), None, Some(UserRole::BotAdmin)).await;
match ta {
// Success(_) => {
// ;
// },
ChangeResult::Success(a) => println!("Succesfully promoted : {a} ;"),
ChangeResult::Failed(a) => println!("Failed to promote : {a} ; "),
ChangeResult::NoChange(a) => println!("No Changes Made : {a} ; "),
@ -223,38 +139,18 @@ pub async fn init(mgr:Arc<ModulesManager>)
}
}
}
// },
// Some(_) => {
// // -
// },
_ => (),
}
// match String::from(arg1) {
// a if a == String::from("admin") => (),
// _ => (),
// }
// match argv[1] {
// String::from("admin") => (),
// }
let arg2 = argv.next();
let targetchnl = arg2;
// bot
}
// BotCommand {
@ -888,38 +784,9 @@ impl IdentityManager {
Note : Ideally this be called for a given chatter name ?
*/
// let a = chattername.to_lowercase();
// self.special_roles_users.get(&a)
// for k in self.special_roles_users.keys() {
// println!("Special Roles Keys {k}");
// for v in
// }
// for (k,v) in &self.special_roles_users {
// println!("User {k}");
// println!("> Roles : {:?}",v);
// }
let chattername = chattername.to_lowercase();
// println!("{a}");
// let b = self.special_roles_users.lock().await.get(&a);
// match b
// {
// Some(b) => Some(*b),
// None => None,
// }
// println!("Write Lock on Special Roles @ Getspecialuserroles()");
// let b = self.special_roles_users.write().await.remove(&a);
// let outp = b;
// // let b = Arc::new(Mutex::new(outp));
// outp
let rolesa = Arc::clone(&self.special_roles_users);
let a = rolesa.read().await;
@ -933,14 +800,6 @@ impl IdentityManager {
}
// Arc::new(RwLock::new(outr))
// let b = Arc::new(Mutex::new(b));
// b
// Some(vec![UserRole::Mod(ChType::Channel(String::from("modulatingforcebot")))])
}

View file

@ -20,13 +20,6 @@ mod experiments;
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
// pub fn init<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// pub fn init<F>(mgr:ModulesManager<F>)
// where
// // F: std::future::Future + Send,
// // F : Send,
// F : Send + ?Sized,
// pub fn init(mgr:&mut ModulesManager)
pub async fn init(mgr:Arc<ModulesManager>)
{
// Modules initializer loads modules into the bot

View file

@ -86,56 +86,16 @@ async fn good_girl(mut bot:BotAR,msg:PrivmsgMessage)
// - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator)
// - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio
//let mut rng = thread_rng();
// let roll = rand::thread_rng().gen_range(1..=5);
// let mut bot = Rc::clone(&bot);
// let mut bot = Rc::get_mut(&mut bot);
// let bot = match bot {
// Some(bot) => bot,
// None => (),
// }
if msg.sender.name == "ModulatingForce" // && msg.message_text.contains("GoodGirl")
if msg.sender.name == "ModulatingForce" || msg.sender.name == "mzNToRi" // && msg.message_text.contains("GoodGirl")
{
// chat.say_in_reply_to(&msg,String::from("GoodGirl")).await;
//if rng.gen_ratio(1,5) {
println!("In GoodGirl() > Pausechamp");
let rollwin = rand::thread_rng().gen_ratio(1,5);
let rollwin = rand::thread_rng().gen_ratio(1,10);
if rollwin {
println!("In GoodGirl() > Win");
// let bot = Rc::get_mut(&bot).expect("Error");
// bot.botmgrs.chat.say_in_reply_to(&msg,String::from("GoodGirl xdd ")).await;
// Rc::<botinstance::BotInstance>::get_mut(mut bot)
// if let Some(bot) = Rc::<&botinstance::BotInstance>::get_mut(bot) {
// match bot{
// Some(bot) => {
// bot
// .botmgrs
// .chat
// .say_in_reply_to(&msg,String::from("GoodGirl xdd ")).await;
// }
// None => (),
// }
// Arc::try_unwrap(bot).ok().unwrap().botmgrs.chat.say_in_reply_to(&msg, String::from("GoodGirl xdd ")).await;
// let a = bot.clone();
let a = Arc::clone(&bot);
// let a = a.read().ok().unwrap();
// let a = a.lock().await.get_botmgrs();
// let a = a.lock().await.rChat();
// let a = (*bot).lock().await.get_botmgrs();
// let a = a.lock().await.rChat();
// let mut a = (*a).lock().await;
// let a = a.botmgrs.chat.say_in_reply_to(&msg, outmsg)
// a.rbotmgrs().chat.say_in_reply_to(&msg, String::from("GoodGirl xdd ")).await;
// a.lock().await.say_in_reply_to(&msg, String::from("GoodGirl xdd ")).await;
// a.botmgrs.chat.say_in_reply_to(&msg, String::from("GoodGirl xdd ")).await;
let botlock = a.read().await;
botlock.botmgrs.chat.say_in_reply_to(&msg, String::from("GoodGirl xdd ")).await;
}