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