use std::collections::HashMap; use std::error::Error; use crate::core::botmodules::{ModulesManager,Listener,BotModule,BotActionTrait, BotCommand}; use crate::core::botmodules::bot_actions::actions_util; use crate::core::botinstance::{self}; use twitch_irc::message::PrivmsgMessage; use crate::core::botmodules::ChType; fn adminvector() -> Vec { vec![String::from("ModulatingForce")] } pub fn init(mgr:&mut ModulesManager) { BotCommand { module : BotModule(String::from("identity")), command : String::from("promote"), // command call name alias : vec![], // String of alternative names exec_body : actions_util::asyncbox(cmd_promote) , help : String::from("promote"), required_roles : vec![], }.add_to_modmgr(mgr); async fn cmd_promote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); } 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![], }.add_to_modmgr(mgr); async fn cmd_demote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { } } pub enum UserRole { Chatter, Mod(ChType), // String specifies Channel SupMod(ChType), // String specifies Channel Broadcaster, BotAdmin, } enum Permissible { Allow, Block } pub struct IdentityManager { special_roles_users : HashMap>, } enum ChatBadge { Broadcaster, Mod, } impl IdentityManager { pub fn init() -> IdentityManager { let mut a = HashMap::new(); for admn in adminvector() { a.insert(admn.to_lowercase(),vec![UserRole::BotAdmin]); }; IdentityManager { special_roles_users : a, } } pub fn canUserRun(self, usr:String, channelname:ChType, chatBadge:ChatBadge, cmdreqroles:Vec ) -> Result> { /* canUserRun - Input : usr:String, channelname:ChType, chatBadge:ChatBadge, cmdreqroles:Vec Output : Result> Some Possible outcomes : Ok(Permissible::Allow) , Ok(Permissible::Block) Description For a Given Chatter (with any special ChatBadge) who ran the Command at a Given Channel , check if that user can run the command based on the given cmdreqroles required by the command Inputs and business logic determine if the user can run the command based on the command's required roles */ // Requirements /* [ ] If cmdreqroles is empty vector , automatically assume Ok(Permissible::Allow) [ ] If chatBadge::Broadcaster ... [ ] and cmdreqroles includes UserRole::Broadcaster , Ok(Permissible::Allow) [ ] and cmdreqroles includes UserRole::Mod("") OR UserRole::SupMod("") , Ok(Permissible::Allow) [ ] If cmdreqroles includes UserRole::Mod("") , checks if chatter has UserRole::Mod(channelname::ChType) to determine if Ok(Permissible::Allow) [ ] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow) [ ] If cmdreqroles includes UserRole::BotAdmin and chatter has UserRole::BotAdmin , Ok(Permissible::Allow) [ ] Otherwise, Ok(Permissible::Block) */ Ok(Permissible::Allow) } }