(cont) promote
This commit is contained in:
parent
618c7284fd
commit
740a637c99
1 changed files with 176 additions and 7 deletions
|
@ -32,7 +32,7 @@ pub fn init(mgr:&mut ModulesManager)
|
|||
],
|
||||
}.add_to_modmgr(mgr);
|
||||
|
||||
async fn cmd_promote(bot: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");
|
||||
|
||||
|
@ -63,6 +63,73 @@ pub fn init(mgr:&mut ModulesManager)
|
|||
|
||||
*/
|
||||
|
||||
println!("{}",msg.message_text);
|
||||
let mut argv = msg.message_text.split(" ");
|
||||
|
||||
argv.next(); // Skip the command name
|
||||
|
||||
let arg1 = argv.next();
|
||||
|
||||
let arg2 = argv.next();
|
||||
|
||||
let mut sender_badge:Option<ChatBadge> = None;
|
||||
|
||||
for b in &msg.badges {
|
||||
if b.name == "moderator" {
|
||||
sender_badge = Some(ChatBadge::Mod);
|
||||
} else if b.name == "broadcaster" {
|
||||
sender_badge = Some(ChatBadge::Broadcaster);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
match arg1 {
|
||||
Some(a) if a == String::from("admin") => {
|
||||
// - BotAdmins can promote admin to give BotAdmin UserRole
|
||||
let a = bot.identity.getspecialuserroles(msg.sender.name.to_lowercase(), Some(ChType::Channel(msg.channel_login.to_lowercase())));
|
||||
|
||||
if let Some(a) = a {
|
||||
if a.contains(&UserRole::BotAdmin) {
|
||||
println!("BotAdmin allowed to promote admin");
|
||||
match bot.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} ; "),
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
Some(_) => {
|
||||
// -
|
||||
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
||||
|
||||
// match String::from(arg1) {
|
||||
// a if a == String::from("admin") => (),
|
||||
// _ => (),
|
||||
// }
|
||||
|
||||
|
||||
// match argv[1] {
|
||||
// String::from("admin") => (),
|
||||
|
||||
// }
|
||||
|
||||
let arg2 = argv.next();
|
||||
|
||||
let targetchnl = arg2;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -120,7 +187,7 @@ pub fn init(mgr:&mut ModulesManager)
|
|||
// ServerMessage::Privmsg(msg) => {
|
||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
|
||||
println!("{}",msg.message_text);
|
||||
// println!("{}",msg.message_text);
|
||||
let mut argv = msg.message_text.split(" ");
|
||||
|
||||
// for v in argv {
|
||||
|
@ -128,7 +195,7 @@ pub fn init(mgr:&mut ModulesManager)
|
|||
// }
|
||||
|
||||
|
||||
let arg = argv.next(); // Skip the command name
|
||||
argv.next(); // Skip the command name
|
||||
|
||||
let arg1 = argv.next();
|
||||
|
||||
|
@ -436,14 +503,116 @@ impl IdentityManager {
|
|||
Permissible::Block
|
||||
}
|
||||
|
||||
pub fn promote(self,trgchatter:String,channel:ChType) -> ChangeResult {
|
||||
pub fn promote(mut self,trgchatter:String,channel:Option<ChType>,trg_role:Option<UserRole>) -> ChangeResult {
|
||||
|
||||
ChangeResult::Success(String::from("Promotion Successful"))
|
||||
// Note : If channel is none, getspecialuserroles() returns all roles for the user
|
||||
|
||||
// let chatterroles = self.getspecialuserroles(trgchatter, channel);
|
||||
|
||||
let chatterroles = self.getspecialuserroles(trgchatter.clone(), channel.clone());
|
||||
|
||||
let emptyvec = vec![];
|
||||
|
||||
let chatterroles = match chatterroles {
|
||||
Some(a) => a,
|
||||
_ => &(emptyvec),
|
||||
};
|
||||
|
||||
|
||||
match trg_role {
|
||||
Some(UserRole::Mod(a)) => {
|
||||
if let Some(trg_chnl) = channel {
|
||||
if chatterroles.contains(&UserRole::Mod(trg_chnl.clone())) {
|
||||
return ChangeResult::NoChange(String::from("Target User already has Target Role"));
|
||||
}
|
||||
// # otherwise, trg_role for the given chnl is not assigned to the trgchatter
|
||||
// chatterroles.push(UserRole::Mod(trg_chnl.clone()));
|
||||
self.special_roles_users
|
||||
.get_mut(&trgchatter)
|
||||
.expect("Error getting roles")
|
||||
.push(UserRole::Mod(trg_chnl));
|
||||
|
||||
return ChangeResult::Success(String::from("Promotion Successful"));
|
||||
}
|
||||
|
||||
pub fn demote(self,trgchatter:String,channel:ChType) -> ChangeResult {
|
||||
|
||||
ChangeResult::Success(String::from("Promotion Successful"))
|
||||
},
|
||||
Some(UserRole::SupMod(a)) => (),
|
||||
Some(UserRole::BotAdmin) => (),
|
||||
Some(_) => (),
|
||||
None => (),
|
||||
}
|
||||
|
||||
|
||||
// match chatterroles {
|
||||
// Some(chatterroles) => {
|
||||
|
||||
// // [x] chatter already has the target role
|
||||
// if chatterroles.contains(&trg_role) {
|
||||
// return ChangeResult::NoChange(String::from("Target User already has Target Role"));
|
||||
// }
|
||||
|
||||
// // By this point, chatteroles does not contain target role
|
||||
// // match trgRole {
|
||||
// // Some(trgRole) => {
|
||||
// // match trgRole {
|
||||
// // UserRole::Mod(a) => {
|
||||
|
||||
// // },
|
||||
// // UserRole::SupMod(a) => (),
|
||||
// // UserRole::BotAdmin => (),
|
||||
// // _ => (), // <-- do nothing with al other options
|
||||
// // }
|
||||
// // },
|
||||
// // None => {
|
||||
// // /*
|
||||
// // - If trgRole is None , then promote by implicit rules . For example,
|
||||
// // - For UserRoles without Mod or SupMod & Caller is SupMod | Broadcaster | BotAdmin > To Mod
|
||||
// // - For Mod & Caller is SupMod | Broadcaster | BotAdmin > To SupMod
|
||||
// // - For UserRoles without BotAdmin & Caller is BotAdmin > To BotAdmin
|
||||
// // */
|
||||
// // },
|
||||
|
||||
// // }
|
||||
|
||||
// // let trgRole = match trgRole {
|
||||
// // Some(UserRole::Mod(a)) => a,
|
||||
// // Some(UserRole::SupMod(a)) => a,
|
||||
// // Some(UserRole::BotAdmin) => UserRole::BotAdmin,
|
||||
// // None => {
|
||||
// // /*
|
||||
// // - If trgRole is None , then promote by implicit rules . For example,
|
||||
// // - For UserRoles without Mod or SupMod & Caller is SupMod | Broadcaster | BotAdmin > To Mod
|
||||
// // - For Mod & Caller is SupMod | Broadcaster | BotAdmin > To SupMod
|
||||
// // - For UserRoles without BotAdmin & Caller is BotAdmin > To BotAdmin
|
||||
// // */
|
||||
// // },
|
||||
|
||||
// // };
|
||||
|
||||
|
||||
|
||||
// // if let Some(trgRole) = trgRole {
|
||||
|
||||
// // // [x] chatter already has the target role
|
||||
// // if chatterroles.contains(&trgRole) {
|
||||
// // return ChangeResult::NoChange(String::from("Target User already has Target Role"));
|
||||
// // }
|
||||
|
||||
// // // [ ] trgRole should be assigned based on the input channel
|
||||
// // let roletoassign = UserRole::
|
||||
// // }
|
||||
|
||||
// },
|
||||
// _ => (),
|
||||
// }
|
||||
|
||||
ChangeResult::Success(String::from("TEST > Promotion Successful"))
|
||||
}
|
||||
|
||||
pub fn demote(self,trgchatter:String,channel:Option<ChType>,trgRole:Option<UserRole>) -> ChangeResult {
|
||||
|
||||
ChangeResult::Success(String::from("TEST > Promotion Successful"))
|
||||
}
|
||||
|
||||
pub fn getspecialuserroles(&self,chattername:String,channel:Option<ChType>) -> Option<&Vec<UserRole>> {
|
||||
|
|
Loading…
Reference in a new issue