(init) Identity Module

This commit is contained in:
ModulatingForce 2024-01-29 06:18:27 -05:00
parent 45564cceed
commit 422cd93303
3 changed files with 50 additions and 2 deletions

View file

@ -1,6 +1,7 @@
pub mod botinstance; pub mod botinstance;
pub mod ratelimiter; pub mod ratelimiter;
pub mod botmodules; pub mod botmodules;
pub mod identity;
// pub fn init() -> () // pub fn init() -> ()
// { // {

View file

@ -22,6 +22,8 @@ use crate::core::ratelimiter;
use crate::core::botmodules; use crate::core::botmodules;
use crate::core::botmodules::ModulesManager; use crate::core::botmodules::ModulesManager;
use crate::core::identity::IdentityManager;
#[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum ChType { pub enum ChType {
@ -137,6 +139,7 @@ pub struct BotInstance
pub botmodules : ModulesManager, pub botmodules : ModulesManager,
twitch_oauth : String, twitch_oauth : String,
pub bot_channels : Vec<ChType>, pub bot_channels : Vec<ChType>,
pub identity : IdentityManager,
} }
@ -203,6 +206,7 @@ impl BotInstance
botmodules : ModulesManager::init(), botmodules : ModulesManager::init(),
twitch_oauth : oauth_token, twitch_oauth : oauth_token,
bot_channels : botchannels, bot_channels : botchannels,
identity : IdentityManager::init(),
}; };
@ -288,19 +292,26 @@ impl BotInstance
// [x] Check if a bot command based on ... // [x] Check if a bot command based on ...
// [x] prefix + command // [x] prefix + command
let mut exec_bot_command = false;
if inpt == self.prefix.to_string() + c.command.as_str() { if inpt == self.prefix.to_string() + c.command.as_str() {
c.execute(self.chat.clone(), msg.clone()).await; exec_bot_command = true;
} }
// [x] prefix + alias // [x] prefix + alias
for alias in &c.alias { for alias in &c.alias {
if inpt == self.prefix.to_string() + alias.as_str() { if inpt == self.prefix.to_string() + alias.as_str() {
c.execute(self.chat.clone(), msg.clone()).await; exec_bot_command = true;
} }
} }
if exec_bot_command {
c.execute(self.chat.clone(), msg.clone()).await;
}
}, },
crate::core::botmodules::BotAction::L(l) => l.execute(self.chat.clone(), msg.clone()).await, crate::core::botmodules::BotAction::L(l) => l.execute(self.chat.clone(), msg.clone()).await,
_ => (), _ => (),
} }
} }

36
src/core/identity.rs Normal file
View file

@ -0,0 +1,36 @@
use std::collections::HashMap;
fn adminvector() -> Vec<String> {
vec![String::from("ModulatingForce")]
}
enum userRole {
Chatter,
Mod(String), // String specifies Channel
SupMod(String), // String specifies Channel
Broadcaster,
BotAdmin,
}
pub struct IdentityManager {
specialRolesUsers : HashMap<String,Vec<userRole>>,
}
impl IdentityManager {
pub fn init() -> IdentityManager {
let mut a = HashMap::new();
for admn in adminvector() {
a.insert(admn.to_lowercase(),vec![userRole::BotAdmin]);
};
IdentityManager {
specialRolesUsers : a,
}
}
}