added identity > getroles

This commit is contained in:
ModulatingForce 2024-01-31 21:30:08 -05:00
parent 2af424f437
commit 618c7284fd
3 changed files with 163 additions and 6 deletions

View file

@ -326,7 +326,15 @@ impl BotInstance
_cmdreqroles:Vec<UserRole>)
*/
// for v in msg.message_text.split(" ") {
// println!("args : {v}");
// }
let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
let inpt = msg.message_text.split(" ").next().expect("ERROR during BotCommand");
// [x] Check if a bot command based on ...
// [x] prefix + command

View file

@ -32,11 +32,12 @@ pub fn init(mgr:&mut ModulesManager)
],
}.add_to_modmgr(mgr);
async fn cmd_promote(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) {
async fn cmd_promote(bot:botinstance::BotManagers,_msg:PrivmsgMessage) {
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
println!("Called cmd promote");
// -- If the BotCommand.command was called (e.g., promote), this is the current function body to execute
// -- If the BotCommand.command was called (e.g., promote) & required roles were validated OUTSIDE of this call
// , this is the current function body to execute
/*
- `promote` / `demote`
@ -51,7 +52,18 @@ pub fn init(mgr:&mut ModulesManager)
*/
// [ ] Split message based on arguments
/*
Usage :
promote <user> <channel>
demote <user> <channel>
promote admin <user>
*/
@ -77,6 +89,95 @@ pub fn init(mgr:&mut ModulesManager)
}
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(mgr);
async fn getroles(bot:botinstance::BotManagers,msg:PrivmsgMessage) {
println!("Called cmd getroles");
/*
Usage
getroles <user> <Channel>
- If channel is provided, provide roles for that channel specifically
*/
// IN other code areas , I see this
// ServerMessage::Privmsg(msg) => {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
println!("{}",msg.message_text);
let mut argv = msg.message_text.split(" ");
// for v in argv {
// println!("args : {v}");
// }
let arg = argv.next(); // Skip the command name
let arg1 = argv.next();
// if arg == None {
// return ; // Do nothing if no arguments
// }
let targetuser = match arg1 {
None => return , // exit if no arguments
Some(arg) => arg,
};
// match String::from(arg1) {
// a if a == String::from("admin") => (),
// _ => (),
// }
// match argv[1] {
// String::from("admin") => (),
// }
let arg2 = argv.next();
let targetchnl = arg2;
match targetchnl {
None => {
let a = bot.identity.getspecialuserroles(String::from(targetuser),None);
println!("Retrieved User Roles >> {:?}",a);
},
Some(targetchnl) => {
let a = bot.identity.getspecialuserroles(String::from(targetuser), Some(ChType::Channel(String::from(targetchnl))));
println!("Retrieved User Roles >> {:?}",a);
},
}
// let a = bot.identity.getuserroles(String::from("ModulatingForce"), Some(ChType::Channel(String::from("ModulatingForcebot"))));
// println!("{:?}",a);
}
}
@ -105,7 +206,7 @@ pub enum Permissible {
pub struct IdentityManager {
special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
// parent_mgr : Box<crate::core::botinstance::BotManagers>,
parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
//parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
}
pub enum ChatBadge {
@ -114,6 +215,13 @@ pub enum ChatBadge {
}
enum ChangeResult {
Success(String),
Failed(String),
NoChange(String),
}
impl IdentityManager {
pub fn init() -> IdentityManager {
@ -124,7 +232,7 @@ impl IdentityManager {
IdentityManager {
special_roles_users : a,
parent_mgr : None,
//parent_mgr : None,
}
}
@ -327,4 +435,45 @@ impl IdentityManager {
Permissible::Block
}
pub fn promote(self,trgchatter:String,channel:ChType) -> ChangeResult {
ChangeResult::Success(String::from("Promotion Successful"))
}
pub fn demote(self,trgchatter:String,channel:ChType) -> ChangeResult {
ChangeResult::Success(String::from("Promotion Successful"))
}
pub fn getspecialuserroles(&self,chattername:String,channel:Option<ChType>) -> Option<&Vec<UserRole>> {
// 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 a = chattername.to_lowercase();
// println!("{a}");
self.special_roles_users.get(&a)
// Some(vec![UserRole::Mod(ChType::Channel(String::from("modulatingforcebot")))])
}
}

View file

@ -71,7 +71,7 @@ pub fn init(mgr:&mut ModulesManager)
async fn good_girl(mut bot:botinstance::BotManagers,msg:PrivmsgMessage)
{
println!("In GoodGirl()");
println!("In GoodGirl() Listener");
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// [ ] Uses gen_ratio() to output bool based on a ratio probability .