2024.02.12 - GetRole() Works

This commit is contained in:
ModulatingForce 2024-02-12 02:34:32 -05:00
parent eedf90907e
commit d6139664e1
4 changed files with 91 additions and 25 deletions

View file

@ -240,7 +240,7 @@ impl BotInstance
// pub fn init() -> BotInstance
// pub fn init() -> Arc<BotInstance>
pub fn init() -> BotInstance
pub async fn init() -> BotInstance
{
dotenv().ok();
@ -295,7 +295,7 @@ impl BotInstance
// ratelimiters : ratelimiters,
// client : client,
// } ,
botmodules : ModulesManager::init(),
botmodules : ModulesManager::init().await,
twitch_oauth : oauth_token,
bot_channels : botchannels,
// identity : IdentityManager::init(),
@ -620,6 +620,7 @@ impl BotInstance
// 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()");
// let a = a;
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
@ -672,18 +673,25 @@ impl BotInstance
// let hacts = boxed_bot.clone().lock().await.get_botactions();
// let hacts = bot.read().await.get_botactions();
let botlock = bot.read().await;
let hacts = botlock.botmodules.botactions.read().await;
// let hacts = hacts
for (_m,acts) in &(*hacts) {
let hacts = Arc::clone(&botlock.botmodules.botactions);
// let hacts = hacts.read().await;
let a = hacts.read().await;
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");
// let bot = bot;
for a in acts {
println!(">> Inner listenermain_prvmsg() >> checking bot actions >> 2");
let _act = match a {
@ -702,6 +710,8 @@ impl BotInstance
// println!("args : {v}");
// }
println!("Reviewing internal commands");
let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
let inpt = msg.message_text.split(" ").next().expect("ERROR during BotCommand");
@ -829,7 +839,7 @@ impl BotInstance
let botlock = bot.read().await;
let id = botlock.get_identity();
let id = id.read().await;
let eval= id.can_user_run_PRVMSG(&msg, c.required_roles.clone());
let eval= id.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await;
match eval {
// Ok(Permissible::Allow) => (),
Permissible::Allow => {

View file

@ -277,7 +277,8 @@ impl BotActionTrait for Listener
// let mgr = &mut bot.botmodules;
// let mgr = bot.botmodules;
// self.add_to_modmgr(Arc::new(*mgr));
self.add_to_modmgr(bot.botmodules);
println!("Adding action to bot");
self.add_to_modmgr(bot.botmodules).await;
}
// fn add_to_modmgr(self, modmgr:&mut ModulesManager) {
@ -286,6 +287,7 @@ impl BotActionTrait for Listener
// 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))
}
@ -311,7 +313,7 @@ impl ModulesManager
{
// pub fn init() -> Arc<Mutex<ModulesManager>>
pub fn init() -> Arc<ModulesManager>
pub async fn init() -> Arc<ModulesManager>
{
@ -331,8 +333,9 @@ impl ModulesManager
// 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));
crate::core::identity::init(Arc::clone(&mgra)).await;
// initialize custom crate modules
// crate::modules::init(&mut mgr);
@ -340,7 +343,7 @@ impl ModulesManager
// crate::modules::init(a.clone());
crate::modules::init(Arc::clone(&mgra));
println!(">> Modules Manager : End of Init");
@ -383,6 +386,7 @@ impl 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");
/*
adds a BotAction to the Modules Manager - This will require a BotModule passed as well
This will including the logic of a valid add

View file

@ -29,12 +29,14 @@ fn adminvector() -> Vec<String> {
// pub fn init(mgr:&mut ModulesManager)
pub fn init(mgr:Arc<ModulesManager>)
pub async fn init(mgr:Arc<ModulesManager>)
{
let a = actions_util::asyncbox(cmd_promote) ;
println!("Went into Identiy Module init");
BotCommand {
// let a = actions_util::asyncbox(cmd_promote) ;
let tempb = BotCommand {
module : BotModule(String::from("identity")),
command : String::from("promote"), // command call name
alias : vec![], // String of alternative names
@ -46,7 +48,9 @@ pub fn init(mgr:Arc<ModulesManager>)
UserRole::Broadcaster,
UserRole::BotAdmin,
],
}.add_to_modmgr(Arc::clone(&mgr));
};
tempb.add_to_modmgr(Arc::clone(&mgr));
// async fn cmd_promote(mut bot:Arc<Mutex<BotInstance>>,msg:PrivmsgMessage)
// async fn cmd_promote(mut bot:&BotInstance,msg:PrivmsgMessage) -> &BotInstance
@ -246,7 +250,21 @@ pub fn init(mgr:Arc<ModulesManager>)
}
BotCommand {
// BotCommand {
// module : BotModule(String::from("identity")),
// command : String::from("demote"), // command call name
// alias : vec![], // String of alternative names
// exec_body : actions_util::asyncbox(cmd_demote) ,
// help : String::from("demote"),
// required_roles : vec![
// UserRole::Mod(ChType::Channel(String::new())),
// UserRole::SupMod(ChType::Channel(String::new())),
// UserRole::Broadcaster,
// UserRole::BotAdmin,
// ],
// }.add_to_modmgr(Arc::clone(&mgr));
let tempb = BotCommand {
module : BotModule(String::from("identity")),
command : String::from("demote"), // command call name
alias : vec![], // String of alternative names
@ -258,8 +276,9 @@ pub fn init(mgr:Arc<ModulesManager>)
UserRole::Broadcaster,
UserRole::BotAdmin,
],
}.add_to_modmgr(Arc::clone(&mgr));
};
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_msg:PrivmsgMessage) {
async fn cmd_demote(mut _chat:BotAR,_msg:PrivmsgMessage) {
@ -268,7 +287,21 @@ pub fn init(mgr:Arc<ModulesManager>)
BotCommand {
// BotCommand {
// module : BotModule(String::from("identity")),
// command : String::from("getroles"), // command call name
// alias : vec![], // String of alternative names
// exec_body : actions_util::asyncbox(getroles) ,
// help : String::from("getroles"),
// required_roles : vec![
// UserRole::Mod(ChType::Channel(String::new())),
// UserRole::SupMod(ChType::Channel(String::new())),
// UserRole::Broadcaster,
// UserRole::BotAdmin,
// ],
// }.add_to_modmgr(Arc::clone(&mgr));
let tempcomm = BotCommand {
module : BotModule(String::from("identity")),
command : String::from("getroles"), // command call name
alias : vec![], // String of alternative names
@ -280,7 +313,9 @@ pub fn init(mgr:Arc<ModulesManager>)
UserRole::Broadcaster,
UserRole::BotAdmin,
],
}.add_to_modmgr(Arc::clone(&mgr));
};
tempcomm.add_to_modmgr(Arc::clone(&mgr)).await;
// async fn getroles(bot:Arc<Mutex<BotInstance>>,msg:PrivmsgMessage) {
@ -401,7 +436,7 @@ pub fn init(mgr:Arc<ModulesManager>)
println!("End of Init MOdule add");
}
@ -467,7 +502,7 @@ impl IdentityManager {
// pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>>
// pub fn can_user_run_PRVMSG(&self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
// pub async fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
pub fn can_user_run_PRVMSG(&self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
pub async fn can_user_run_PRVMSG(&self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
{
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
@ -513,7 +548,7 @@ impl IdentityManager {
ChType::Channel(msg.channel_login.to_owned()),
sender_badge,
cmdreqroles
) ;
).await ;
}

View file

@ -14,7 +14,24 @@ pub type BotAR = Arc<RwLock<BotInstance>>;
#[tokio::main]
pub async fn main() {
let bot = BotInstance::init();
let bot = BotInstance::init().await;
let a = Arc::clone(&bot.botmodules.botactions);
let a = a.read().await;
// let a = *a;
for (_,acts) in &*a {
for act in acts {
match act {
crate::core::botmodules::BotAction::C(b) => println!("bot actiions: {}",b.command),
crate::core::botmodules::BotAction::L(l) => println!("bot actiions: {}",l.name),
_ => println!("Not a valid match??"),
}
}
};
println!("Starting runner..");
bot.runner().await;