pub struct changes

look into error at identity:1333
This commit is contained in:
haruyuumei 2024-03-23 14:33:45 -03:00 committed by ModulatingForce
parent 960cd5724c
commit bed61c2830
6 changed files with 61 additions and 48 deletions

View file

@ -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"

View file

@ -43,8 +43,14 @@ pub enum ChangeResult {
// pub use ChType::Channel;
//
//simplifying from enum to struct
pub struct Channel(pub String);
pub struct Channel(String);
impl Channel
{
pub fn construct(channel_string:String) -> Channel
{
Channel(channel_string)
}
}
use super::botmodules::StatusType;
#[derive(Clone)]

View file

@ -415,8 +415,15 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// BotModule(String),
// }
pub struct BotModule(pub String);
pub struct BotModule(String);
//botmodule simplified from enum to tuple struct
impl BotModule{
pub fn construct(module_name:String) -> BotModule
{
BotModule(module_name)
}
}
impl PartialEq for BotModule {
fn eq(&self, other: &Self) -> bool {

View file

@ -58,7 +58,7 @@ impl Chat {
let contextratelimiter = rllock
// .get_mut()
.get_mut(&Channel(String::from(&msg.channel_login)))
.get_mut(&Channel::construct(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

View file

@ -54,14 +54,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
);
let tempb = BotCommand {
module: BotModule(String::from("identity")),
module: BotModule::construct(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(String::new())),
UserRole::SupMod(Channel(String::new())),
UserRole::Mod(Channel::construct(String::new())),
UserRole::SupMod(Channel::construct(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(targetchnl.clone())),
Some(Channel::construct(targetchnl.clone())),
target_bot_admin_role,
)
.await
@ -226,14 +226,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
}
let tempb = BotCommand {
module: BotModule(String::from("identity")),
module: BotModule::construct(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(String::new())),
UserRole::SupMod(Channel(String::new())),
UserRole::Mod(Channel::construct(String::new())),
UserRole::SupMod(Channel::construct(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(targetchnl.clone())),
Some(Channel::construct(targetchnl.clone())),
)
.await
}
@ -418,14 +418,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
}
let tempcomm = BotCommand {
module: BotModule(String::from("identity")),
module: BotModule::construct(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(String::new())),
UserRole::SupMod(Channel(String::new())),
UserRole::Mod(Channel::construct(String::new())),
UserRole::SupMod(Channel::construct(String::new())),
UserRole::Broadcaster,
UserRole::BotAdmin,
],
@ -477,7 +477,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
idlock
.getspecialuserroles(
String::from(targetuser),
Some(Channel(msg.channel_login.to_lowercase())),
Some(Channel::construct(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(targetchnl.to_lowercase().to_string())),
Some(Channel::construct(targetchnl.to_lowercase().to_string())),
)
.await;
if callersproles.contains(&UserRole::Mod(Channel(
if callersproles.contains(&UserRole::Mod(Channel::construct(
targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::SupMod(Channel(
))) || callersproles.contains(&UserRole::SupMod(Channel::construct(
targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::Broadcaster)
{
idlock
.getspecialuserroles(
String::from(targetuser),
Some(Channel(targetchnl.to_lowercase())),
Some(Channel::construct(targetchnl.to_lowercase())),
)
.await
} else {
@ -507,7 +507,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
idlock
.getspecialuserroles(
String::from(targetuser),
Some(Channel(msg.channel_login.to_lowercase())),
Some(Channel::construct(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(
if sproles.contains(&UserRole::Mod(Channel::construct(
msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel(
))) || sproles.contains(&UserRole::SupMod(Channel::construct(
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(
} else if sproles.contains(&UserRole::Mod(Channel::construct(
msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel(
))) || sproles.contains(&UserRole::SupMod(Channel::construct(
msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::BotAdmin)
{
@ -698,7 +698,7 @@ impl IdentityManager {
self.can_user_run(
msg.sender.name.to_owned(),
Channel(msg.channel_login.to_owned()),
Channel::construct(msg.channel_login.to_owned()),
sender_badge,
cmdreqroles,
)
@ -799,8 +799,8 @@ impl IdentityManager {
// [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(String::new())))
|| cmdreqroles.contains(&UserRole::SupMod(Channel(String::new())))
|| cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new())))
|| cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new())))
{
// return Ok(Permissible::Allow)
return (
@ -869,7 +869,7 @@ impl IdentityManager {
None,
);
if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) {
if cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) {
botlog::trace(
"Command requires Mod Role",
Some("identity.rs > can_user_run()".to_string()),
@ -905,7 +905,7 @@ 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(String::new()))) {
if cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new()))) {
if let Some(a) = self
.special_roles_users
.read()
@ -1292,7 +1292,7 @@ impl IdentityManager {
evalsproles.push(UserRole::Broadcaster);
}
Some(Channel(channel_tmp))
Some(Channel::construct(channel_tmp))
} // _ => ()
}
}
@ -1379,8 +1379,8 @@ mod core_identity {
fn user_role_identity() {
Log::set_file_ext(Extension::Log);
assert_eq!(
UserRole::SupMod(Channel("strong".to_string())),
UserRole::SupMod(Channel("Strong".to_lowercase()))
UserRole::SupMod(Channel::construct("strong".to_string())),
UserRole::SupMod(Channel::construct("Strong".to_lowercase()))
);
}
@ -1395,7 +1395,7 @@ mod core_identity {
let (usr, channelname, chat_badge, cmdreqroles) = (
bot,
Channel("twitchchanneltest".to_string()),
Channel::construct("twitchchanneltest".to_string()),
None,
vec![]
);
@ -1420,7 +1420,7 @@ mod core_identity {
let test_id_mgr = IdentityManager::init();
// [x] Mod Attempts to Promote User
let channel = Some(Channel("twitchchanneltest".to_string()));
let channel = Some(Channel::construct("twitchchanneltest".to_string()));
let trgchatter = "regularChatter".to_string();
let authorizer_badge = &Some(ChatBadge::Mod);
let authorizer = "chatMod".to_string();
@ -1450,7 +1450,7 @@ mod core_identity {
let test_id_mgr = IdentityManager::init();
// [x] Broadcaster Promotes Chatter to SupMod
let channel = Some(Channel("broadcasterer".to_string()));
let channel = Some(Channel::construct("broadcasterer".to_string()));
let trgchatter = "regularChatter".to_string();
let authorizer_badge = &Some(ChatBadge::Broadcaster);
let authorizer = "broadcasterer".to_string();
@ -1475,7 +1475,7 @@ mod core_identity {
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
assert!(rslt.contains(&UserRole::Mod(Channel("broadcasterer".to_string()))));
assert!(rslt.contains(&UserRole::Mod(Channel::construct("broadcasterer".to_string()))));
let rslt = test_id_mgr
.promote(
@ -1496,7 +1496,7 @@ mod core_identity {
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
assert!(rslt.contains(&UserRole::SupMod(Channel(
assert!(rslt.contains(&UserRole::SupMod(Channel::construct(
"broadcasterer".to_string()
))));
@ -1530,7 +1530,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(broadcaster.clone());
let channel = Channel::construct(broadcaster.clone());
let supchatter = "superModerator".to_string();
let trg_role = None;
@ -1575,7 +1575,7 @@ mod core_identity {
// let broadcaster = "broadcasterer".to_string();
let authorizer = supchatter;
let authorizer_badge = &Some(ChatBadge::Broadcaster);
let channel = Some(Channel(broadcaster.clone()));
let channel = Some(Channel::construct(broadcaster.clone()));
let trgchatter = "regularChatter".to_string();
let trg_role = None;
@ -1646,7 +1646,7 @@ mod core_identity {
// let broadcaster = "broadcasterer".to_string();
let authorizer = botadmin;
let authorizer_badge = botadmin_badge;
let channel = Some(Channel("somechannel".to_string()));
let channel = Some(Channel::construct("somechannel".to_string()));
let trgchatter = "regularChatter".to_string();
let trg_role = None;
@ -1721,7 +1721,7 @@ mod core_identity {
let supmod = "supmoder".to_string();
let channel = Some(Channel("somechannel".to_string()));
let channel = Some(Channel::construct("somechannel".to_string()));
test_id_mgr.affirm_chatter_in_db(supmod.clone()).await;
test_id_mgr

View file

@ -28,11 +28,11 @@ use tokio::time::{sleep, Duration};
pub async fn init(mgr: Arc<ModulesManager>) {
const OF_CMD_CHANNEL:Channel = Channel(String::new());
const OF_CMD_CHANNEL:Channel = Channel::construct(String::new());
// 1. Define the BotAction
let botc1 = BotCommand {
module: BotModule(String::from("experiments001")),
module: BotModule::construct(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(String::from("experiments001")),
module: BotModule::construct(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(String::from("experiments001")),
module: BotModule::construct(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(String::from("experiments001")),
module: BotModule::construct(String::from("experiments001")),
command: String::from("rtest"), // command call name
alias: vec![], // String of alternative names
exec_body: actions_util::asyncbox(routinelike),