2024-01-29 06:18:27 -05:00
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2024-01-29 12:41:26 -05:00
|
|
|
use std::error::Error;
|
2024-01-29 11:09:33 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-01-29 12:41:26 -05:00
|
|
|
use crate::core::botmodules::ChType;
|
|
|
|
|
2024-01-29 06:18:27 -05:00
|
|
|
fn adminvector() -> Vec<String> {
|
|
|
|
vec![String::from("ModulatingForce")]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-29 11:09:33 -05:00
|
|
|
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);
|
2024-01-29 12:41:26 -05:00
|
|
|
|
|
|
|
|
2024-01-29 11:09:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2024-01-29 06:18:27 -05:00
|
|
|
Chatter,
|
2024-01-29 13:08:35 -05:00
|
|
|
Mod(ChType), // String specifies Channel
|
|
|
|
SupMod(ChType), // String specifies Channel
|
2024-01-29 06:18:27 -05:00
|
|
|
Broadcaster,
|
|
|
|
BotAdmin,
|
2024-01-29 12:41:26 -05:00
|
|
|
|
2024-01-29 06:18:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-29 12:41:26 -05:00
|
|
|
enum Permissible {
|
|
|
|
Allow,
|
|
|
|
Block
|
|
|
|
}
|
|
|
|
|
2024-01-29 06:18:27 -05:00
|
|
|
pub struct IdentityManager {
|
2024-01-29 11:09:33 -05:00
|
|
|
special_roles_users : HashMap<String,Vec<UserRole>>,
|
2024-01-29 06:18:27 -05:00
|
|
|
}
|
|
|
|
|
2024-01-29 12:41:26 -05:00
|
|
|
enum ChatBadge {
|
|
|
|
Broadcaster,
|
|
|
|
Mod,
|
|
|
|
}
|
|
|
|
|
2024-01-29 06:18:27 -05:00
|
|
|
|
|
|
|
impl IdentityManager {
|
|
|
|
|
|
|
|
pub fn init() -> IdentityManager {
|
|
|
|
let mut a = HashMap::new();
|
|
|
|
for admn in adminvector() {
|
2024-01-29 11:09:33 -05:00
|
|
|
a.insert(admn.to_lowercase(),vec![UserRole::BotAdmin]);
|
2024-01-29 06:18:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
IdentityManager {
|
2024-01-29 11:09:33 -05:00
|
|
|
special_roles_users : a,
|
2024-01-29 06:18:27 -05:00
|
|
|
}
|
|
|
|
}
|
2024-01-29 12:41:26 -05:00
|
|
|
|
|
|
|
pub fn canUserRun(self,
|
|
|
|
usr:String,
|
|
|
|
channelname:ChType,
|
|
|
|
chatBadge:ChatBadge,
|
|
|
|
cmdreqroles:Vec<UserRole>
|
|
|
|
) -> Result<Permissible,Box<dyn Error>> {
|
|
|
|
/*
|
|
|
|
canUserRun -
|
|
|
|
|
|
|
|
Input :
|
|
|
|
usr:String,
|
|
|
|
channelname:ChType,
|
|
|
|
chatBadge:ChatBadge,
|
|
|
|
cmdreqroles:Vec<UserRole>
|
|
|
|
|
|
|
|
Output : Result<Permissible,Box<dyn Error>>
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2024-01-29 13:08:35 -05:00
|
|
|
// 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)
|
|
|
|
*/
|
2024-01-29 12:41:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
Ok(Permissible::Allow)
|
|
|
|
}
|
2024-01-29 06:18:27 -05:00
|
|
|
}
|
|
|
|
|