Merge pull request 'Simplify enum objects' (#39) from Simplify-objects into main
All checks were successful
ci/woodpecker/push/cargo-checks Pipeline was successful
All checks were successful
ci/woodpecker/push/cargo-checks Pipeline was successful
Reviewed-on: #39
This commit is contained in:
commit
e104268f8e
6 changed files with 148 additions and 137 deletions
|
@ -1,4 +1,4 @@
|
|||
|
||||
[env]
|
||||
# Based on https://doc.rust-lang.org/cargo/reference/config.html
|
||||
OtherBots = "Supibot,buttsbot,PotatBotat,StreamElements"
|
||||
OtherBots = "Supibot,buttsbot,PotatBotat,StreamElements,yuumeibot"
|
||||
|
|
|
@ -35,11 +35,15 @@ pub enum ChangeResult {
|
|||
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub enum ChType {
|
||||
Channel(String),
|
||||
}
|
||||
|
||||
pub use ChType::Channel;
|
||||
// pub enum ChType {
|
||||
// Channel(String),
|
||||
// }
|
||||
//
|
||||
// pub use ChType::Channel;
|
||||
//
|
||||
//simplifying from enum to struct
|
||||
pub struct Channel(pub String);
|
||||
|
||||
use super::botmodules::StatusType;
|
||||
|
||||
|
@ -51,7 +55,7 @@ pub struct BotManagers {
|
|||
|
||||
impl BotManagers {
|
||||
pub fn init(
|
||||
ratelimiters: HashMap<ChType, RateLimiter>,
|
||||
ratelimiters: HashMap<Channel, RateLimiter>,
|
||||
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||
) -> BotManagers {
|
||||
BotManagers {
|
||||
|
@ -75,11 +79,11 @@ impl<T: Clone> ArcBox<T> {
|
|||
|
||||
pub struct BotInstance {
|
||||
pub prefix: char,
|
||||
pub bot_channel: ChType,
|
||||
pub bot_channel: Channel,
|
||||
pub incoming_messages: Arc<RwLock<UnboundedReceiver<ServerMessage>>>,
|
||||
pub botmodules: Arc<ModulesManager>,
|
||||
pub twitch_oauth: String,
|
||||
pub bot_channels: Vec<ChType>,
|
||||
pub bot_channels: Vec<Channel>,
|
||||
pub botmgrs: BotManagers,
|
||||
//modesmgr : ModesManager, // [FUTURE] Silent/Quiet , uwu , frisky/horny
|
||||
}
|
||||
|
@ -299,7 +303,7 @@ impl BotInstance {
|
|||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
let modstatus = modmgr.modstatus(
|
||||
c.module.clone(),
|
||||
ChType::Channel(msg.channel_login.to_string())).await;
|
||||
Channel(msg.channel_login.to_string())).await;
|
||||
|
||||
|
||||
if let StatusType::Disabled(a) = modstatus {
|
||||
|
@ -314,7 +318,7 @@ impl BotInstance {
|
|||
);
|
||||
|
||||
|
||||
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
let elevated_access = {
|
||||
let mut idlock = id.write().await;
|
||||
|
@ -417,7 +421,7 @@ impl BotInstance {
|
|||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
let modstatus = modmgr.modstatus(
|
||||
l.module.clone(),
|
||||
ChType::Channel(msg.channel_login.to_string())).await;
|
||||
Channel(msg.channel_login.to_string())).await;
|
||||
|
||||
|
||||
if let StatusType::Disabled(a) = modstatus {
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
ModulesManager is used to manage Modules and BotActions associated with those modules
|
||||
|
||||
pub struct ModulesManager {
|
||||
statusdb: HashMap<ModType,Vec<ModStatusType>>,
|
||||
botactions: HashMap<ModType,Vec<BotAction>>,
|
||||
statusdb: HashMap<BotModule,Vec<ModStatusType>>,
|
||||
botactions: HashMap<BotModule,Vec<BotAction>>,
|
||||
}
|
||||
|
||||
- statusdb: HashMap<ModType,Vec<ModStatusType>> - Defines Modules and their ModStatusType (e.g., Enabled at an Instance level, Disabled at a Channel Level)
|
||||
- botactions: HashMap<ModType,Vec<BotAction>> - Defines Modules and their BotActions (e.g., BotCommand , Listener, Routine)
|
||||
- statusdb: HashMap<BotModule,Vec<ModStatusType>> - Defines Modules and their ModStatusType (e.g., Enabled at an Instance level, Disabled at a Channel Level)
|
||||
- botactions: HashMap<BotModule,Vec<BotAction>> - Defines Modules and their BotActions (e.g., BotCommand , Listener, Routine)
|
||||
|
||||
Example
|
||||
{
|
||||
|
@ -34,13 +34,11 @@ use async_trait::async_trait;
|
|||
|
||||
use self::bot_actions::actions_util::BotAR;
|
||||
use crate::core::bot_actions::actions_util;
|
||||
use crate::core::botinstance::{BotInstance, ChType,ChangeResult};
|
||||
use crate::core::botinstance::{BotInstance, Channel,ChangeResult};
|
||||
use crate::core::botlog;
|
||||
use crate::core::identity::{self, Permissible,IdentityManager};
|
||||
|
||||
use crate::core::bot_actions;
|
||||
pub use ChType::Channel;
|
||||
pub use ModType::BotModule;
|
||||
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
|
@ -49,7 +47,7 @@ use super::identity::ChatBadge;
|
|||
|
||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||
|
||||
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
// 1. Define the BotAction
|
||||
let botc1 = BotCommand {
|
||||
|
@ -126,8 +124,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
&self,
|
||||
requestor: String,
|
||||
requestor_badge: Option<ChatBadge>,
|
||||
trg_module: ModType,
|
||||
// channel: Option<ChType>,
|
||||
trg_module: BotModule,
|
||||
// channel: Option<Channel>,
|
||||
trg_level: StatusLvl,
|
||||
bot: BotAR,
|
||||
) -> ChangeResult
|
||||
|
@ -153,8 +151,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let requestor_badge = requestor_badge_mut;
|
||||
|
||||
|
||||
// [x] trg_module: ModType,
|
||||
// - [x] Need to validate an actual ModType - otherwise, fail or exit the cmd
|
||||
// [x] trg_module: BotModule,
|
||||
// - [x] Need to validate an actual BotModule - otherwise, fail or exit the cmd
|
||||
|
||||
let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 };
|
||||
|
||||
|
@ -190,7 +188,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let trg_level =
|
||||
if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
|
||||
// else if arg1 == Some("-f") { StatusLvl::Instance }
|
||||
else { StatusLvl::Ch(ChType::Channel(currchnl)) }
|
||||
else { StatusLvl::Ch(Channel(currchnl)) }
|
||||
;
|
||||
|
||||
|
||||
|
@ -204,7 +202,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let rslt = modmgr.exec_enable(
|
||||
requestor,
|
||||
requestor_badge,
|
||||
ModType::BotModule(trg_module.unwrap().to_string()),
|
||||
BotModule(trg_module.unwrap().to_string()),
|
||||
trg_level,
|
||||
id).await;
|
||||
|
||||
|
@ -302,8 +300,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
&self,
|
||||
requestor: String,
|
||||
requestor_badge: Option<ChatBadge>,
|
||||
trg_module: ModType,
|
||||
// channel: Option<ChType>,
|
||||
trg_module: BotModule,
|
||||
// channel: Option<Channel>,
|
||||
trg_level: StatusLvl,
|
||||
force: bool,
|
||||
// bot: BotAR,
|
||||
|
@ -330,8 +328,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let requestor_badge = requestor_badge_mut;
|
||||
|
||||
// [x] trg_module: ModType,
|
||||
// - [x] Need to validate an actual ModType - otherwise, fail or exit the cmd
|
||||
// [x] trg_module: BotModule,
|
||||
// - [x] Need to validate an actual BotModule - otherwise, fail or exit the cmd
|
||||
|
||||
let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 };
|
||||
|
||||
|
@ -368,7 +366,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let trg_level =
|
||||
if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
|
||||
// else if arg1 == Some("-f") { StatusLvl::Instance }
|
||||
else { StatusLvl::Ch(ChType::Channel(currchnl)) }
|
||||
else { StatusLvl::Ch(Channel(currchnl)) }
|
||||
;
|
||||
|
||||
|
||||
|
@ -383,7 +381,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let rslt = modmgr.exec_disable(
|
||||
requestor,
|
||||
requestor_badge,
|
||||
ModType::BotModule(trg_module.unwrap().to_string()),
|
||||
BotModule(trg_module.unwrap().to_string()),
|
||||
trg_level,
|
||||
force,
|
||||
id).await;
|
||||
|
@ -411,20 +409,23 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ModType {
|
||||
BotModule(String),
|
||||
}
|
||||
// pub enum BotModule {
|
||||
// BotModule(String),
|
||||
// }
|
||||
|
||||
impl PartialEq for ModType {
|
||||
pub struct BotModule(pub String);
|
||||
|
||||
|
||||
impl PartialEq for BotModule {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let BotModule(name1) = self.clone();
|
||||
let BotModule(name2) = other.clone();
|
||||
name1.to_lowercase() == name2.to_lowercase()
|
||||
}
|
||||
}
|
||||
impl Eq for ModType {}
|
||||
impl Eq for BotModule {}
|
||||
|
||||
impl Hash for ModType{
|
||||
impl Hash for BotModule{
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// self.id.hash(state);
|
||||
// self.phone.hash(state);
|
||||
|
@ -443,7 +444,7 @@ pub enum ModGroup {
|
|||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub enum StatusLvl {
|
||||
Instance,
|
||||
Ch(ChType),
|
||||
Ch(Channel),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
|
@ -477,7 +478,7 @@ pub trait BotActionTrait {
|
|||
}
|
||||
|
||||
pub struct BotCommand {
|
||||
pub module: ModType,
|
||||
pub module: BotModule,
|
||||
pub command: String, // command call name
|
||||
pub alias: Vec<String>, // String of alternative names
|
||||
pub exec_body: bot_actions::actions_util::ExecBody,
|
||||
|
@ -515,7 +516,7 @@ impl BotActionTrait for BotCommand {
|
|||
}
|
||||
|
||||
pub struct Listener {
|
||||
pub module: ModType,
|
||||
pub module: BotModule,
|
||||
pub name: String,
|
||||
pub exec_body: bot_actions::actions_util::ExecBody,
|
||||
pub help: String,
|
||||
|
@ -567,20 +568,20 @@ pub struct Routine {}
|
|||
type StatusdbEntry = (ModGroup, Vec<StatusType>);
|
||||
|
||||
pub struct ModulesManager {
|
||||
statusdb: Arc<RwLock<HashMap<ModType, StatusdbEntry>>>,
|
||||
pub botactions: Arc<RwLock<HashMap<ModType, Vec<BotAction>>>>,
|
||||
statusdb: Arc<RwLock<HashMap<BotModule, StatusdbEntry>>>,
|
||||
pub botactions: Arc<RwLock<HashMap<BotModule, Vec<BotAction>>>>,
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
statusdb
|
||||
<HashMap
|
||||
<ModType, <-- e.g., BotModule(String::from("experiments001"))
|
||||
<BotModule, <-- e.g., BotModule(String::from("experiments001"))
|
||||
Vec<ModStatusType> <-- shows Enabled/Disabled per Status level
|
||||
|
||||
botactions
|
||||
HashMap<
|
||||
ModType, <-- e.g., BotModule(String::from("experiments001"))
|
||||
BotModule, <-- e.g., BotModule(String::from("experiments001"))
|
||||
Vec<BotAction>> BotCommand, Listener
|
||||
|
||||
*/
|
||||
|
@ -618,7 +619,7 @@ impl ModulesManager {
|
|||
}
|
||||
|
||||
|
||||
pub async fn moduleslist(&self) -> HashMap<ModType,ModGroup>
|
||||
pub async fn moduleslist(&self) -> HashMap<BotModule,ModGroup>
|
||||
{
|
||||
|
||||
// let db = Arc::clone(&self.statusdb);
|
||||
|
@ -635,7 +636,7 @@ impl ModulesManager {
|
|||
outmap
|
||||
}
|
||||
|
||||
pub async fn modstatus(&self, in_module: ModType, in_chnl: ChType) -> StatusType {
|
||||
pub async fn modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType {
|
||||
// Example usage : botmanager.modstatus(
|
||||
// BotModule("GambaCore"),
|
||||
// Channel("modulatingforce")
|
||||
|
@ -714,7 +715,7 @@ impl ModulesManager {
|
|||
&self,
|
||||
requestor: String,
|
||||
requestor_badge: Option<ChatBadge>,
|
||||
trg_module: ModType,
|
||||
trg_module: BotModule,
|
||||
trg_level: StatusLvl,
|
||||
id: Arc<RwLock<IdentityManager>>,
|
||||
) -> ChangeResult
|
||||
|
@ -764,11 +765,11 @@ impl ModulesManager {
|
|||
// if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's
|
||||
|
||||
let arb_chnl = match trg_level.clone() {
|
||||
StatusLvl::Instance => ChType::Channel(requestor.to_lowercase()),
|
||||
StatusLvl::Instance => Channel(requestor.to_lowercase()),
|
||||
StatusLvl::Ch(a) => a,
|
||||
};
|
||||
|
||||
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
let (admin_level_access,_) = idlock.can_user_run(requestor.clone(), arb_chnl.clone(), requestor_badge.clone(),
|
||||
vec![
|
||||
|
@ -903,7 +904,7 @@ impl ModulesManager {
|
|||
&self,
|
||||
requestor: String,
|
||||
requestor_badge: Option<ChatBadge>,
|
||||
trg_module: ModType,
|
||||
trg_module: BotModule,
|
||||
trg_level: StatusLvl,
|
||||
force: bool,
|
||||
id: Arc<RwLock<IdentityManager>>,
|
||||
|
@ -946,11 +947,11 @@ impl ModulesManager {
|
|||
// if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's
|
||||
|
||||
let arb_chnl = match trg_level.clone() {
|
||||
StatusLvl::Instance => ChType::Channel(requestor.to_lowercase()),
|
||||
StatusLvl::Instance => Channel(requestor.to_lowercase()),
|
||||
StatusLvl::Ch(a) => a,
|
||||
};
|
||||
|
||||
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
let (admin_level_access,_) = idlock.can_user_run(requestor.clone(), arb_chnl.clone(), requestor_badge.clone(),
|
||||
vec![
|
||||
|
@ -1080,7 +1081,7 @@ impl ModulesManager {
|
|||
ChangeResult::Failed("ERROR : Not implemented yet".to_string())
|
||||
}
|
||||
|
||||
pub async fn set_instance_disabled(&self, in_module: ModType) -> (StatusType,ChangeResult) {
|
||||
pub async fn set_instance_disabled(&self, in_module: BotModule) -> (StatusType,ChangeResult) {
|
||||
// at Instance level
|
||||
// - If core module, do nothing
|
||||
|
||||
|
@ -1115,7 +1116,7 @@ impl ModulesManager {
|
|||
// (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn force_disable(&self, in_module: ModType) -> (StatusType,ChangeResult) {
|
||||
pub async fn force_disable(&self, in_module: BotModule) -> (StatusType,ChangeResult) {
|
||||
// Disables the module at Instance level, and removes all Enabled at Channel level
|
||||
// - Bot Moderators MUST Re-enable if they were enabled before
|
||||
// - If core module, do nothing
|
||||
|
@ -1159,7 +1160,7 @@ impl ModulesManager {
|
|||
// (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn set_instance_enabled(&self, in_module: ModType) -> (StatusType,ChangeResult) {
|
||||
pub async fn set_instance_enabled(&self, in_module: BotModule) -> (StatusType,ChangeResult) {
|
||||
// at Instance level
|
||||
// - If core module, do nothing
|
||||
|
||||
|
@ -1194,7 +1195,7 @@ impl ModulesManager {
|
|||
// (StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn set_ch_disabled(&self, in_module: ModType , in_chnl: ChType) -> (StatusType,ChangeResult) {
|
||||
pub async fn set_ch_disabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) {
|
||||
// at Instance level
|
||||
// - If core module, do nothing
|
||||
|
||||
|
@ -1232,7 +1233,7 @@ impl ModulesManager {
|
|||
// (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn set_ch_enabled(&self, in_module: ModType , in_chnl: ChType) -> (StatusType,ChangeResult) {
|
||||
pub async fn set_ch_enabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) {
|
||||
// at Instance level
|
||||
// - If core module, do nothing
|
||||
|
||||
|
@ -1272,16 +1273,16 @@ impl ModulesManager {
|
|||
|
||||
|
||||
|
||||
pub async fn add_botaction(&self, in_module: ModType, in_action: BotAction) {
|
||||
pub async fn add_botaction(&self, in_module: BotModule, in_action: BotAction) {
|
||||
self.int_add_botaction(in_module,ModGroup::Custom,in_action).await;
|
||||
}
|
||||
|
||||
pub async fn add_core_act(&self, in_module: ModType, in_action: BotAction) {
|
||||
pub async fn add_core_act(&self, in_module: BotModule, in_action: BotAction) {
|
||||
self.int_add_botaction(in_module,ModGroup::Core,in_action).await;
|
||||
}
|
||||
|
||||
|
||||
pub async fn affirm_in_statusdb(&self,in_module:ModType,in_modgroup: ModGroup) {
|
||||
pub async fn affirm_in_statusdb(&self,in_module:BotModule,in_modgroup: ModGroup) {
|
||||
|
||||
let mut dbt = self.statusdb.write().await;
|
||||
|
||||
|
@ -1297,7 +1298,7 @@ impl ModulesManager {
|
|||
|
||||
}
|
||||
|
||||
async fn int_add_botaction(&self, in_module: ModType, in_modgroup: ModGroup, in_action: BotAction) {
|
||||
async fn int_add_botaction(&self, in_module: BotModule, in_modgroup: ModGroup, in_action: BotAction) {
|
||||
botlog::trace(
|
||||
"Add botaction called",
|
||||
Some("ModulesManager > init()".to_string()),
|
||||
|
@ -1320,7 +1321,7 @@ impl ModulesManager {
|
|||
// - If BotAction to Add is a BotCommand , In Module Manager DB (botactions),
|
||||
// Check All Other BotAction Command Names & Aliases to ensure they don't conflict
|
||||
|
||||
async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option<ModType> {
|
||||
async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option<BotModule> {
|
||||
if let BotAction::C(incmd) = act {
|
||||
let actdb = mgr.botactions.read().await;
|
||||
|
||||
|
@ -1395,12 +1396,12 @@ impl ModulesManager {
|
|||
);
|
||||
}
|
||||
|
||||
fn _statuscleanup(&self, _: Option<ChType>) {
|
||||
fn _statuscleanup(&self, _: Option<Channel>) {
|
||||
// internal cleans up statusdb . For example :
|
||||
// - remove redudancies . If we see several Enabled("m"), only keep 1x
|
||||
// - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m")
|
||||
// the IDEAL is that this is ran before every read/update operation to ensure quality
|
||||
// Option<ChType> can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel
|
||||
// Option<Channel> can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel
|
||||
// Passing None to chnl may be a heavy operation, as this will review and look at the whole table
|
||||
}
|
||||
}
|
||||
|
@ -1467,10 +1468,10 @@ mod core_modulesmanager {
|
|||
*/
|
||||
|
||||
async fn complex_workflow(
|
||||
in_module: ModType ,
|
||||
in_module: BotModule ,
|
||||
in_modgroup : ModGroup ,
|
||||
in_chnl1 : ChType,
|
||||
in_chnl2 : ChType)
|
||||
in_chnl1 : Channel,
|
||||
in_chnl2 : Channel)
|
||||
{
|
||||
|
||||
|
||||
|
@ -1643,7 +1644,7 @@ mod core_modulesmanager {
|
|||
let in_module = BotModule("Experiments01".to_string());
|
||||
let in_modgroup = ModGroup::Custom;
|
||||
let (in_chnl1,in_chnl2) =
|
||||
(ChType::Channel("TestChannel01".to_string()),ChType::Channel("TestChannel02".to_string()));
|
||||
(Channel("TestChannel01".to_string()),Channel("TestChannel02".to_string()));
|
||||
|
||||
complex_workflow(in_module, in_modgroup, in_chnl1, in_chnl2).await;
|
||||
|
||||
|
@ -1659,7 +1660,7 @@ mod core_modulesmanager {
|
|||
let in_module = BotModule("CoreModule01".to_string());
|
||||
let in_modgroup = ModGroup::Core;
|
||||
let (in_chnl1,in_chnl2) =
|
||||
(ChType::Channel("TestChannel01".to_string()),ChType::Channel("TestChannel02".to_string()));
|
||||
(Channel("TestChannel01".to_string()),Channel("TestChannel02".to_string()));
|
||||
|
||||
complex_workflow(in_module, in_modgroup, in_chnl1, in_chnl2).await;
|
||||
|
||||
|
@ -1701,7 +1702,7 @@ mod core_modulesmanager {
|
|||
|
||||
async fn inner_enable_disable_complex(
|
||||
requestor:String,
|
||||
channel:ChType,
|
||||
channel:Channel,
|
||||
idmgr:IdentityManager,
|
||||
modsmgr:Arc<ModulesManager>)
|
||||
{
|
||||
|
@ -1724,7 +1725,7 @@ mod core_modulesmanager {
|
|||
|
||||
let requestor_badge = None; // If they are a Mod on the Given Channel already, that can be evaluated without the current badge
|
||||
|
||||
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
let (admin_level_access,_) = idlock.can_user_run(requestor.clone(), channel.clone(), requestor_badge.clone(),
|
||||
vec![
|
||||
|
@ -1773,7 +1774,7 @@ mod core_modulesmanager {
|
|||
|
||||
// [-] requestor_badge: Option<ChatBadge>,
|
||||
|
||||
// [x] trg_module: ModType,
|
||||
// [x] trg_module: BotModule,
|
||||
let trg_module = in_module;
|
||||
|
||||
// [x] trg_level: StatusLvl,
|
||||
|
@ -2020,7 +2021,7 @@ mod core_modulesmanager {
|
|||
|
||||
assert!(rslt.contains(&identity::UserRole::BotAdmin));
|
||||
|
||||
let channel = ChType::Channel("somechannel".to_string());
|
||||
let channel = Channel("somechannel".to_string());
|
||||
|
||||
|
||||
inner_enable_disable_complex(requestor, channel, idmgr, modsmgr).await;
|
||||
|
@ -2058,7 +2059,7 @@ mod core_modulesmanager {
|
|||
|
||||
let requestor = "mod_user".to_string();
|
||||
// let botadmin_badge = &None;
|
||||
let channel = ChType::Channel("somechannel".to_string());
|
||||
let channel = Channel("somechannel".to_string());
|
||||
|
||||
|
||||
idmgr.affirm_chatter_in_db(requestor.clone()).await;
|
||||
|
@ -2109,7 +2110,7 @@ mod core_modulesmanager {
|
|||
|
||||
|
||||
let requestor = "regular_user".to_string();
|
||||
let channel = ChType::Channel("somechannel".to_string());
|
||||
let channel = Channel("somechannel".to_string());
|
||||
|
||||
|
||||
idmgr.affirm_chatter_in_db(requestor.clone()).await;
|
||||
|
@ -2142,7 +2143,7 @@ mod core_modulesmanager {
|
|||
|
||||
let requestor = "regular_user".to_string();
|
||||
|
||||
let channel = ChType::Channel("somechannel".to_string());
|
||||
let channel = Channel("somechannel".to_string());
|
||||
|
||||
|
||||
idmgr.affirm_chatter_in_db(requestor.clone()).await;
|
||||
|
|
|
@ -15,21 +15,21 @@ use rand::Rng;
|
|||
use crate::core::ratelimiter;
|
||||
use crate::core::ratelimiter::RateLimiter;
|
||||
|
||||
use crate::core::botinstance::ChType;
|
||||
use crate::core::botinstance::Channel;
|
||||
use crate::core::botlog;
|
||||
pub use ChType::Channel;
|
||||
|
||||
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Chat {
|
||||
pub ratelimiters: Arc<Mutex<HashMap<ChType, RateLimiter>>>, // used to limit messages sent per channel
|
||||
pub ratelimiters: Arc<Mutex<HashMap<Channel, RateLimiter>>>, // used to limit messages sent per channel
|
||||
pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||
}
|
||||
|
||||
impl Chat {
|
||||
pub fn init(
|
||||
ratelimiters: HashMap<ChType, RateLimiter>,
|
||||
ratelimiters: HashMap<Channel, RateLimiter>,
|
||||
client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||
) -> Chat {
|
||||
Chat {
|
||||
|
@ -38,7 +38,7 @@ impl Chat {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn init_channel(&mut self, chnl: ChType) {
|
||||
pub async fn init_channel(&mut self, chnl: Channel) {
|
||||
let n = RateLimiter::new();
|
||||
self.ratelimiters.lock().await.insert(chnl, n);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use twitch_irc::message::PrivmsgMessage;
|
|||
use casual_logger::Log;
|
||||
|
||||
use crate::core::bot_actions::actions_util::{self, BotAR};
|
||||
use crate::core::botinstance::{ChType,ChangeResult};
|
||||
use crate::core::botinstance::{Channel,ChangeResult};
|
||||
use crate::core::botlog;
|
||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
||||
|
||||
|
@ -60,8 +60,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
exec_body: actions_util::asyncbox(cmd_promote),
|
||||
help: String::from("promote"),
|
||||
required_roles: vec![
|
||||
UserRole::Mod(ChType::Channel(String::new())),
|
||||
UserRole::SupMod(ChType::Channel(String::new())),
|
||||
UserRole::Mod(Channel(String::new())),
|
||||
UserRole::SupMod(Channel(String::new())),
|
||||
UserRole::Broadcaster,
|
||||
UserRole::BotAdmin,
|
||||
],
|
||||
|
@ -172,7 +172,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
sendername.clone(),
|
||||
&sender_badge,
|
||||
targetusr.to_string(),
|
||||
Some(ChType::Channel(targetchnl.clone())),
|
||||
Some(Channel(targetchnl.clone())),
|
||||
target_bot_admin_role,
|
||||
)
|
||||
.await
|
||||
|
@ -232,8 +232,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
exec_body: actions_util::asyncbox(cmd_demote),
|
||||
help: String::from("demote"),
|
||||
required_roles: vec![
|
||||
UserRole::Mod(ChType::Channel(String::new())),
|
||||
UserRole::SupMod(ChType::Channel(String::new())),
|
||||
UserRole::Mod(Channel(String::new())),
|
||||
UserRole::SupMod(Channel(String::new())),
|
||||
UserRole::Broadcaster,
|
||||
UserRole::BotAdmin,
|
||||
],
|
||||
|
@ -368,7 +368,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
sendername.clone(),
|
||||
&sender_badge,
|
||||
targetusr.to_string(),
|
||||
Some(ChType::Channel(targetchnl.clone())),
|
||||
Some(Channel(targetchnl.clone())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -424,8 +424,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
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::Mod(Channel(String::new())),
|
||||
UserRole::SupMod(Channel(String::new())),
|
||||
UserRole::Broadcaster,
|
||||
UserRole::BotAdmin,
|
||||
],
|
||||
|
@ -477,7 +477,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
idlock
|
||||
.getspecialuserroles(
|
||||
String::from(targetuser),
|
||||
Some(ChType::Channel(msg.channel_login.to_lowercase())),
|
||||
Some(Channel(msg.channel_login.to_lowercase())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -486,20 +486,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let callersproles = idlock
|
||||
.getspecialuserroles(
|
||||
msg.sender.name.to_lowercase(),
|
||||
Some(ChType::Channel(targetchnl.to_lowercase().to_string())),
|
||||
Some(Channel(targetchnl.to_lowercase().to_string())),
|
||||
)
|
||||
.await;
|
||||
|
||||
if callersproles.contains(&UserRole::Mod(ChType::Channel(
|
||||
if callersproles.contains(&UserRole::Mod(Channel(
|
||||
targetchnl.to_lowercase().to_string(),
|
||||
))) || callersproles.contains(&UserRole::SupMod(ChType::Channel(
|
||||
))) || callersproles.contains(&UserRole::SupMod(Channel(
|
||||
targetchnl.to_lowercase().to_string(),
|
||||
))) || callersproles.contains(&UserRole::Broadcaster)
|
||||
{
|
||||
idlock
|
||||
.getspecialuserroles(
|
||||
String::from(targetuser),
|
||||
Some(ChType::Channel(targetchnl.to_lowercase())),
|
||||
Some(Channel(targetchnl.to_lowercase())),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
|
@ -507,7 +507,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
idlock
|
||||
.getspecialuserroles(
|
||||
String::from(targetuser),
|
||||
Some(ChType::Channel(msg.channel_login.to_lowercase())),
|
||||
Some(Channel(msg.channel_login.to_lowercase())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -535,18 +535,18 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string();
|
||||
|
||||
if sproles.contains(&UserRole::Mod(ChType::Channel(
|
||||
if sproles.contains(&UserRole::Mod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::SupMod(ChType::Channel(
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::BotAdmin)
|
||||
{
|
||||
outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str();
|
||||
}
|
||||
outmsg
|
||||
} else if sproles.contains(&UserRole::Mod(ChType::Channel(
|
||||
} else if sproles.contains(&UserRole::Mod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::SupMod(ChType::Channel(
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::BotAdmin)
|
||||
{
|
||||
|
@ -578,8 +578,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum UserRole {
|
||||
Chatter,
|
||||
Mod(ChType), // String specifies Channel
|
||||
SupMod(ChType), // String specifies Channel
|
||||
Mod(Channel), // String specifies Channel
|
||||
SupMod(Channel), // String specifies Channel
|
||||
Broadcaster,
|
||||
BotAdmin,
|
||||
}
|
||||
|
@ -698,7 +698,8 @@ impl IdentityManager {
|
|||
|
||||
self.can_user_run(
|
||||
msg.sender.name.to_owned(),
|
||||
ChType::Channel(msg.channel_login.to_owned()),
|
||||
// Channel::construct(msg.channel_login.to_owned()),
|
||||
Channel(msg.channel_login.to_owned()),
|
||||
sender_badge,
|
||||
cmdreqroles,
|
||||
)
|
||||
|
@ -709,7 +710,7 @@ impl IdentityManager {
|
|||
pub async fn can_user_run(
|
||||
&mut self,
|
||||
usr: String,
|
||||
channelname: ChType,
|
||||
channelname: Channel,
|
||||
chat_badge: Option<ChatBadge>,
|
||||
cmdreqroles: Vec<UserRole>, // ) -> Result<Permissible,Box<dyn Error>> {
|
||||
) -> (Permissible, ChangeResult) {
|
||||
|
@ -798,9 +799,13 @@ impl IdentityManager {
|
|||
// [x] and cmdreqroles includes UserRole::Broadcaster , Ok(Permissible::Allow)
|
||||
// [x] and cmdreqroles includes UserRole::Mod("") OR UserRole::SupMod("") , Ok(Permissible::Allow)
|
||||
Some(ChatBadge::Broadcaster) => {
|
||||
// if cmdreqroles.contains(&UserRole::Broadcaster)
|
||||
// || cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new())))
|
||||
// || cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new())))
|
||||
// {
|
||||
if cmdreqroles.contains(&UserRole::Broadcaster)
|
||||
|| cmdreqroles.contains(&UserRole::Mod(ChType::Channel(String::new())))
|
||||
|| cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new())))
|
||||
|| cmdreqroles.contains(&UserRole::Mod(Channel(String::new())))
|
||||
|| cmdreqroles.contains(&UserRole::SupMod(Channel(String::new())))
|
||||
{
|
||||
// return Ok(Permissible::Allow)
|
||||
return (
|
||||
|
@ -869,7 +874,8 @@ impl IdentityManager {
|
|||
None,
|
||||
);
|
||||
|
||||
if cmdreqroles.contains(&UserRole::Mod(ChType::Channel(String::new()))) {
|
||||
// if cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) {
|
||||
if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) {
|
||||
botlog::trace(
|
||||
"Command requires Mod Role",
|
||||
Some("identity.rs > can_user_run()".to_string()),
|
||||
|
@ -905,7 +911,8 @@ impl IdentityManager {
|
|||
|
||||
// [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow)
|
||||
|
||||
if cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) {
|
||||
// if cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new()))) {
|
||||
if cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) {
|
||||
if let Some(a) = self
|
||||
.special_roles_users
|
||||
.read()
|
||||
|
@ -979,7 +986,7 @@ impl IdentityManager {
|
|||
authorizer: String,
|
||||
authorizer_badge: &Option<ChatBadge>,
|
||||
trgchatter: String,
|
||||
channel: Option<ChType>,
|
||||
channel: Option<Channel>,
|
||||
trg_role: Option<UserRole>,
|
||||
) -> ChangeResult {
|
||||
botlog::trace(
|
||||
|
@ -1163,7 +1170,7 @@ impl IdentityManager {
|
|||
authorizer: String,
|
||||
authorizer_badge: &Option<ChatBadge>,
|
||||
trgchatter: String,
|
||||
channel: Option<ChType>,
|
||||
channel: Option<Channel>,
|
||||
) -> ChangeResult {
|
||||
botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?}",
|
||||
authorizer,trgchatter,channel), Some("identity.rs > demote()".to_string()), None);
|
||||
|
@ -1260,7 +1267,7 @@ impl IdentityManager {
|
|||
pub async fn getspecialuserroles(
|
||||
&self,
|
||||
chattername: String,
|
||||
channel: Option<ChType>,
|
||||
channel: Option<Channel>,
|
||||
) -> Vec<UserRole> {
|
||||
/*
|
||||
Note : Ideally this be called for a given chatter name ?
|
||||
|
@ -1283,22 +1290,19 @@ impl IdentityManager {
|
|||
|
||||
// Checks if broadcaster
|
||||
let channel_out = match channel {
|
||||
Some(channel_tmp) => {
|
||||
match channel_tmp {
|
||||
ChType::Channel(channel_tmp) => {
|
||||
Some(chnl) => {
|
||||
// In this block, Some input channel is given
|
||||
// We're comparing the channel name with chattername to determine if they're a broadcaster
|
||||
if chattername == channel_tmp.to_lowercase() {
|
||||
if chattername == chnl.0
|
||||
{
|
||||
evalsproles.push(UserRole::Broadcaster);
|
||||
}
|
||||
|
||||
Some(ChType::Channel(channel_tmp))
|
||||
} // _ => ()
|
||||
}
|
||||
}
|
||||
Some(chnl)
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
||||
let rolesdb = Arc::clone(&self.special_roles_users);
|
||||
|
||||
let rolesdb_lock = rolesdb.read().await;
|
||||
|
@ -1379,8 +1383,8 @@ mod core_identity {
|
|||
fn user_role_identity() {
|
||||
Log::set_file_ext(Extension::Log);
|
||||
assert_eq!(
|
||||
UserRole::SupMod(ChType::Channel("strong".to_string())),
|
||||
UserRole::SupMod(ChType::Channel("Strong".to_lowercase()))
|
||||
UserRole::SupMod(Channel("strong".to_string())),
|
||||
UserRole::SupMod(Channel("Strong".to_lowercase()))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1395,7 +1399,8 @@ mod core_identity {
|
|||
|
||||
let (usr, channelname, chat_badge, cmdreqroles) = (
|
||||
bot,
|
||||
ChType::Channel("twitchchanneltest".to_string()),
|
||||
// Channel::construct("twitchchanneltest".to_string()),
|
||||
Channel("twitchchanneltest".to_string()),
|
||||
None,
|
||||
vec![]
|
||||
);
|
||||
|
@ -1420,7 +1425,8 @@ mod core_identity {
|
|||
let test_id_mgr = IdentityManager::init();
|
||||
|
||||
// [x] Mod Attempts to Promote User
|
||||
let channel = Some(ChType::Channel("twitchchanneltest".to_string()));
|
||||
// let channel = Some(Channel::construct("twitchchanneltest".to_string()));
|
||||
let channel = Some(Channel("twitchchanneltest".to_string()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let authorizer_badge = &Some(ChatBadge::Mod);
|
||||
let authorizer = "chatMod".to_string();
|
||||
|
@ -1450,7 +1456,8 @@ mod core_identity {
|
|||
let test_id_mgr = IdentityManager::init();
|
||||
|
||||
// [x] Broadcaster Promotes Chatter to SupMod
|
||||
let channel = Some(ChType::Channel("broadcasterer".to_string()));
|
||||
// let channel = Some(Channel::construct("broadcasterer".to_string()));
|
||||
let channel = Some(Channel("broadcasterer".to_string()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let authorizer_badge = &Some(ChatBadge::Broadcaster);
|
||||
let authorizer = "broadcasterer".to_string();
|
||||
|
@ -1475,7 +1482,7 @@ mod core_identity {
|
|||
.getspecialuserroles(trgchatter.clone(), channel.clone())
|
||||
.await;
|
||||
|
||||
assert!(rslt.contains(&UserRole::Mod(ChType::Channel("broadcasterer".to_string()))));
|
||||
assert!(rslt.contains(&UserRole::Mod(Channel("broadcasterer".to_string()))));
|
||||
|
||||
let rslt = test_id_mgr
|
||||
.promote(
|
||||
|
@ -1496,7 +1503,7 @@ mod core_identity {
|
|||
.getspecialuserroles(trgchatter.clone(), channel.clone())
|
||||
.await;
|
||||
|
||||
assert!(rslt.contains(&UserRole::SupMod(ChType::Channel(
|
||||
assert!(rslt.contains(&UserRole::SupMod(Channel(
|
||||
"broadcasterer".to_string()
|
||||
))));
|
||||
|
||||
|
@ -1530,7 +1537,7 @@ mod core_identity {
|
|||
let broadcaster = "broadcasterer".to_string();
|
||||
let broadcaster_badge = &Some(ChatBadge::Broadcaster);
|
||||
// let channel = Some(ChType::Channel(broadcaster.clone()));
|
||||
let channel = ChType::Channel(broadcaster.clone());
|
||||
let channel = Channel(broadcaster.clone());
|
||||
let supchatter = "superModerator".to_string();
|
||||
let trg_role = None;
|
||||
|
||||
|
@ -1575,7 +1582,7 @@ mod core_identity {
|
|||
// let broadcaster = "broadcasterer".to_string();
|
||||
let authorizer = supchatter;
|
||||
let authorizer_badge = &Some(ChatBadge::Broadcaster);
|
||||
let channel = Some(ChType::Channel(broadcaster.clone()));
|
||||
let channel = Some(Channel(broadcaster.clone()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let trg_role = None;
|
||||
|
||||
|
@ -1646,7 +1653,7 @@ mod core_identity {
|
|||
// let broadcaster = "broadcasterer".to_string();
|
||||
let authorizer = botadmin;
|
||||
let authorizer_badge = botadmin_badge;
|
||||
let channel = Some(ChType::Channel("somechannel".to_string()));
|
||||
let channel = Some(Channel("somechannel".to_string()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let trg_role = None;
|
||||
|
||||
|
@ -1721,7 +1728,7 @@ mod core_identity {
|
|||
|
||||
let supmod = "supmoder".to_string();
|
||||
|
||||
let channel = Some(ChType::Channel("somechannel".to_string()));
|
||||
let channel = Some(Channel("somechannel".to_string()));
|
||||
|
||||
test_id_mgr.affirm_chatter_in_db(supmod.clone()).await;
|
||||
test_id_mgr
|
||||
|
|
|
@ -16,8 +16,7 @@ use std::sync::Arc;
|
|||
use twitch_irc::message::PrivmsgMessage;
|
||||
|
||||
// use crate::core::botinstance::ChType::Channel;
|
||||
use crate::core::botinstance::ChType;
|
||||
use ChType::Channel;
|
||||
use crate::core::botinstance::Channel;
|
||||
use crate::core::botlog;
|
||||
|
||||
use crate::core::bot_actions::actions_util::{self, BotAR};
|
||||
|
@ -29,7 +28,7 @@ use tokio::time::{sleep, Duration};
|
|||
|
||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||
|
||||
const OF_CMD_CHANNEL:ChType = Channel(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
// 1. Define the BotAction
|
||||
let botc1 = BotCommand {
|
||||
|
|
Loading…
Reference in a new issue