(init) identity > canUserRun()

This commit is contained in:
ModulatingForce 2024-01-29 12:41:26 -05:00
parent fa0b219c34
commit 39033f4178

View file

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error;
use crate::core::botmodules::{ModulesManager,Listener,BotModule,BotActionTrait, BotCommand}; use crate::core::botmodules::{ModulesManager,Listener,BotModule,BotActionTrait, BotCommand};
use crate::core::botmodules::bot_actions::actions_util; use crate::core::botmodules::bot_actions::actions_util;
@ -8,6 +8,8 @@ use crate::core::botmodules::bot_actions::actions_util;
use crate::core::botinstance::{self}; use crate::core::botinstance::{self};
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
use crate::core::botmodules::ChType;
fn adminvector() -> Vec<String> { fn adminvector() -> Vec<String> {
vec![String::from("ModulatingForce")] vec![String::from("ModulatingForce")]
} }
@ -27,6 +29,8 @@ pub fn init(mgr:&mut ModulesManager)
async fn cmd_promote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { async fn cmd_promote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) {
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
} }
BotCommand { BotCommand {
@ -53,13 +57,24 @@ pub enum UserRole {
SupMod(String), // String specifies Channel SupMod(String), // String specifies Channel
Broadcaster, Broadcaster,
BotAdmin, BotAdmin,
} }
enum Permissible {
Allow,
Block
}
pub struct IdentityManager { pub struct IdentityManager {
special_roles_users : HashMap<String,Vec<UserRole>>, special_roles_users : HashMap<String,Vec<UserRole>>,
} }
enum ChatBadge {
Broadcaster,
Mod,
}
impl IdentityManager { impl IdentityManager {
@ -73,5 +88,37 @@ impl IdentityManager {
special_roles_users : a, special_roles_users : a,
} }
} }
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
*/
Ok(Permissible::Allow)
}
} }