Simplify enum objects #39
4 changed files with 61 additions and 51 deletions
|
@ -415,14 +415,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// BotModule(String),
|
||||
// }
|
||||
|
||||
pub struct BotModule(String);
|
||||
//botmodule simplified from enum to tuple struct
|
||||
impl BotModule{
|
||||
pub fn construct(module_name:String) -> BotModule
|
||||
{
|
||||
BotModule(module_name)
|
||||
}
|
||||
}
|
||||
pub struct BotModule(pub String);
|
||||
// //botmodule simplified from enum to tuple struct
|
||||
// impl BotModule{
|
||||
// pub fn construct(module_name:String) -> BotModule
|
||||
// {
|
||||
// BotModule(module_name)
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
impl PartialEq for BotModule {
|
||||
|
|
|
@ -58,7 +58,7 @@ impl Chat {
|
|||
|
||||
let contextratelimiter = rllock
|
||||
// .get_mut()
|
||||
.get_mut(&Channel::construct(String::from(&msg.channel_login)))
|
||||
.get_mut(&Channel(String::from(&msg.channel_login)))
|
||||
.expect("ERROR: Issue with Rate limiters");
|
||||
|
||||
// Continue to check the limiter and sleep if required if the minimum is not reached
|
||||
|
|
|
@ -54,14 +54,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
);
|
||||
|
||||
let tempb = BotCommand {
|
||||
module: BotModule::construct(String::from("identity")),
|
||||
module: BotModule(String::from("identity")),
|
||||
command: String::from("promote"), // command call name
|
||||
alias: vec![], // String of alternative names
|
||||
exec_body: actions_util::asyncbox(cmd_promote),
|
||||
help: String::from("promote"),
|
||||
required_roles: vec![
|
||||
UserRole::Mod(Channel::construct(String::new())),
|
||||
UserRole::SupMod(Channel::construct(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(Channel::construct(targetchnl.clone())),
|
||||
Some(Channel(targetchnl.clone())),
|
||||
target_bot_admin_role,
|
||||
)
|
||||
.await
|
||||
|
@ -226,14 +226,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
}
|
||||
|
||||
let tempb = BotCommand {
|
||||
module: BotModule::construct(String::from("identity")),
|
||||
module: BotModule(String::from("identity")),
|
||||
command: String::from("demote"), // command call name
|
||||
alias: vec![], // String of alternative names
|
||||
exec_body: actions_util::asyncbox(cmd_demote),
|
||||
help: String::from("demote"),
|
||||
required_roles: vec![
|
||||
UserRole::Mod(Channel::construct(String::new())),
|
||||
UserRole::SupMod(Channel::construct(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(Channel::construct(targetchnl.clone())),
|
||||
Some(Channel(targetchnl.clone())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -418,14 +418,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
}
|
||||
|
||||
let tempcomm = BotCommand {
|
||||
module: BotModule::construct(String::from("identity")),
|
||||
module: BotModule(String::from("identity")),
|
||||
command: String::from("getroles"), // command call name
|
||||
alias: vec![], // String of alternative names
|
||||
exec_body: actions_util::asyncbox(getroles),
|
||||
help: String::from("getroles"),
|
||||
required_roles: vec![
|
||||
UserRole::Mod(Channel::construct(String::new())),
|
||||
UserRole::SupMod(Channel::construct(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(Channel::construct(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(Channel::construct(targetchnl.to_lowercase().to_string())),
|
||||
Some(Channel(targetchnl.to_lowercase().to_string())),
|
||||
)
|
||||
.await;
|
||||
|
||||
if callersproles.contains(&UserRole::Mod(Channel::construct(
|
||||
if callersproles.contains(&UserRole::Mod(Channel(
|
||||
targetchnl.to_lowercase().to_string(),
|
||||
))) || callersproles.contains(&UserRole::SupMod(Channel::construct(
|
||||
))) || callersproles.contains(&UserRole::SupMod(Channel(
|
||||
targetchnl.to_lowercase().to_string(),
|
||||
))) || callersproles.contains(&UserRole::Broadcaster)
|
||||
{
|
||||
idlock
|
||||
.getspecialuserroles(
|
||||
String::from(targetuser),
|
||||
Some(Channel::construct(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(Channel::construct(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(Channel::construct(
|
||||
if sproles.contains(&UserRole::Mod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel::construct(
|
||||
))) || 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(Channel::construct(
|
||||
} else if sproles.contains(&UserRole::Mod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel::construct(
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::BotAdmin)
|
||||
{
|
||||
|
@ -698,7 +698,8 @@ impl IdentityManager {
|
|||
|
||||
self.can_user_run(
|
||||
msg.sender.name.to_owned(),
|
||||
Channel::construct(msg.channel_login.to_owned()),
|
||||
// Channel::construct(msg.channel_login.to_owned()),
|
||||
Channel(msg.channel_login.to_owned()),
|
||||
sender_badge,
|
||||
cmdreqroles,
|
||||
)
|
||||
|
@ -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(Channel::construct(String::new())))
|
||||
|| cmdreqroles.contains(&UserRole::SupMod(Channel::construct(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(Channel::construct(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(Channel::construct(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()
|
||||
|
@ -1376,8 +1383,8 @@ mod core_identity {
|
|||
fn user_role_identity() {
|
||||
Log::set_file_ext(Extension::Log);
|
||||
assert_eq!(
|
||||
UserRole::SupMod(Channel::construct("strong".to_string())),
|
||||
UserRole::SupMod(Channel::construct("Strong".to_lowercase()))
|
||||
UserRole::SupMod(Channel("strong".to_string())),
|
||||
UserRole::SupMod(Channel("Strong".to_lowercase()))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1392,7 +1399,8 @@ mod core_identity {
|
|||
|
||||
let (usr, channelname, chat_badge, cmdreqroles) = (
|
||||
bot,
|
||||
Channel::construct("twitchchanneltest".to_string()),
|
||||
// Channel::construct("twitchchanneltest".to_string()),
|
||||
Channel("twitchchanneltest".to_string()),
|
||||
None,
|
||||
vec![]
|
||||
);
|
||||
|
@ -1417,7 +1425,8 @@ mod core_identity {
|
|||
let test_id_mgr = IdentityManager::init();
|
||||
|
||||
// [x] Mod Attempts to Promote User
|
||||
let channel = Some(Channel::construct("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();
|
||||
|
@ -1447,7 +1456,8 @@ mod core_identity {
|
|||
let test_id_mgr = IdentityManager::init();
|
||||
|
||||
// [x] Broadcaster Promotes Chatter to SupMod
|
||||
let channel = Some(Channel::construct("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();
|
||||
|
@ -1472,7 +1482,7 @@ mod core_identity {
|
|||
.getspecialuserroles(trgchatter.clone(), channel.clone())
|
||||
.await;
|
||||
|
||||
assert!(rslt.contains(&UserRole::Mod(Channel::construct("broadcasterer".to_string()))));
|
||||
assert!(rslt.contains(&UserRole::Mod(Channel("broadcasterer".to_string()))));
|
||||
|
||||
let rslt = test_id_mgr
|
||||
.promote(
|
||||
|
@ -1493,7 +1503,7 @@ mod core_identity {
|
|||
.getspecialuserroles(trgchatter.clone(), channel.clone())
|
||||
.await;
|
||||
|
||||
assert!(rslt.contains(&UserRole::SupMod(Channel::construct(
|
||||
assert!(rslt.contains(&UserRole::SupMod(Channel(
|
||||
"broadcasterer".to_string()
|
||||
))));
|
||||
|
||||
|
@ -1527,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 = Channel::construct(broadcaster.clone());
|
||||
let channel = Channel(broadcaster.clone());
|
||||
let supchatter = "superModerator".to_string();
|
||||
let trg_role = None;
|
||||
|
||||
|
@ -1572,7 +1582,7 @@ mod core_identity {
|
|||
// let broadcaster = "broadcasterer".to_string();
|
||||
let authorizer = supchatter;
|
||||
let authorizer_badge = &Some(ChatBadge::Broadcaster);
|
||||
let channel = Some(Channel::construct(broadcaster.clone()));
|
||||
let channel = Some(Channel(broadcaster.clone()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let trg_role = None;
|
||||
|
||||
|
@ -1643,7 +1653,7 @@ mod core_identity {
|
|||
// let broadcaster = "broadcasterer".to_string();
|
||||
let authorizer = botadmin;
|
||||
let authorizer_badge = botadmin_badge;
|
||||
let channel = Some(Channel::construct("somechannel".to_string()));
|
||||
let channel = Some(Channel("somechannel".to_string()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let trg_role = None;
|
||||
|
||||
|
@ -1718,7 +1728,7 @@ mod core_identity {
|
|||
|
||||
let supmod = "supmoder".to_string();
|
||||
|
||||
let channel = Some(Channel::construct("somechannel".to_string()));
|
||||
let channel = Some(Channel("somechannel".to_string()));
|
||||
|
||||
test_id_mgr.affirm_chatter_in_db(supmod.clone()).await;
|
||||
test_id_mgr
|
||||
|
|
|
@ -28,11 +28,11 @@ use tokio::time::{sleep, Duration};
|
|||
|
||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||
|
||||
const OF_CMD_CHANNEL:Channel = Channel::construct(String::new());
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
// 1. Define the BotAction
|
||||
let botc1 = BotCommand {
|
||||
module: BotModule::construct(String::from("experiments001")),
|
||||
module: BotModule(String::from("experiments001")),
|
||||
command: String::from("test1"), // command call name
|
||||
alias: vec![
|
||||
String::from("tester1"),
|
||||
|
@ -50,7 +50,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
// 1. Define the BotAction
|
||||
let list1 = Listener {
|
||||
module: BotModule::construct(String::from("experiments001")),
|
||||
module: BotModule(String::from("experiments001")),
|
||||
name: String::from("GoodGirl Listener"),
|
||||
exec_body: actions_util::asyncbox(good_girl),
|
||||
help: String::from(""),
|
||||
|
@ -73,7 +73,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
// 1. Define the BotAction
|
||||
let botc1 = BotCommand {
|
||||
module: BotModule::construct(String::from("experiments001")),
|
||||
module: BotModule(String::from("experiments001")),
|
||||
command: String::from("babygirl"), // command call name
|
||||
alias: vec![], // String of alternative names
|
||||
exec_body: actions_util::asyncbox(babygirl),
|
||||
|
@ -92,7 +92,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
// 1. Define the BotAction
|
||||
let botc1 = BotCommand {
|
||||
module: BotModule::construct(String::from("experiments001")),
|
||||
module: BotModule(String::from("experiments001")),
|
||||
command: String::from("rtest"), // command call name
|
||||
alias: vec![], // String of alternative names
|
||||
exec_body: actions_util::asyncbox(routinelike),
|
||||
|
|
Loading…
Reference in a new issue