(cont) cleanup
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

(cont)

(cont)

(cont)
This commit is contained in:
ModulatingForce 2024-03-02 12:21:18 -05:00
parent b2220dc224
commit e86b051ff3
6 changed files with 124 additions and 1298 deletions

View file

@ -4,13 +4,13 @@ pub mod actions_util {
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::{Mutex, RwLock}; use tokio::sync::{Mutex, RwLock};
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
use crate::core::botinstance::BotInstance; use crate::core::botinstance::BotInstance;
pub type BotAM = Arc<Mutex<BotInstance>>; pub type BotAM = Arc<Mutex<BotInstance>>;
pub type BotAR = Arc<RwLock<BotInstance>>; pub type BotAR = Arc<RwLock<BotInstance>>;

View file

@ -16,7 +16,7 @@ use casual_logger::Log;
use crate::core::ratelimiter::RateLimiter; use crate::core::ratelimiter::RateLimiter;
use crate::core::botmodules::bot_actions::actions_util::BotAR; use crate::core::bot_actions::actions_util::BotAR;
use crate::core::botmodules::ModulesManager; use crate::core::botmodules::ModulesManager;
use crate::core::identity::{ChangeResult, IdentityManager, Permissible}; use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
@ -142,7 +142,7 @@ impl BotInstance {
ServerMessage::Privmsg(msg) => { ServerMessage::Privmsg(msg) => {
botlog::debug( botlog::debug(
format!( format!(
"[Twitch Chat] > {} @ #{}: {}", "[Twitch Chat > {}] > {}: {}",
msg.channel_login, msg.sender.name, msg.message_text msg.channel_login, msg.sender.name, msg.message_text
) )
.as_str(), .as_str(),

View file

@ -36,7 +36,7 @@ use crate::core::botinstance::{BotInstance, ChType};
use crate::core::botlog; use crate::core::botlog;
use crate::core::identity; use crate::core::identity;
pub use crate::core::bot_actions; use crate::core::bot_actions;
pub use ChType::Channel; pub use ChType::Channel;
pub use ModType::BotModule; pub use ModType::BotModule;
@ -168,23 +168,20 @@ botactions
impl ModulesManager { impl ModulesManager {
pub async fn init() -> Arc<ModulesManager> { pub async fn init() -> Arc<ModulesManager> {
let mgr = ModulesManager { let mgr = ModulesManager {
statusdb: Arc::new(RwLock::new(HashMap::new())), statusdb: Arc::new(RwLock::new(HashMap::new())),
botactions: Arc::new(RwLock::new(HashMap::new())), botactions: Arc::new(RwLock::new(HashMap::new())),
}; };
// :: [x] initialize core modules // :: [x] initialize core modules
botlog::debug( botlog::trace(
"ModulesManager > init() > Adding modules", "ModulesManager > init() > Adding modules",
Some("ModulesManager > init()".to_string()), Some("ModulesManager > init()".to_string()),
None, None,
); );
let mgrarc = Arc::new(mgr); let mgrarc = Arc::new(mgr);
// 1. load core modules // 1. load core modules
crate::core::identity::init(Arc::clone(&mgrarc)).await; crate::core::identity::init(Arc::clone(&mgrarc)).await;
@ -223,7 +220,6 @@ impl ModulesManager {
} }
pub async fn add_botaction(&self, in_module: ModType, in_action: BotAction) { pub async fn add_botaction(&self, in_module: ModType, in_action: BotAction) {
botlog::trace( botlog::trace(
"Add botaction called", "Add botaction called",
Some("ModulesManager > init()".to_string()), Some("ModulesManager > init()".to_string()),
@ -247,11 +243,9 @@ impl ModulesManager {
// 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<ModType> {
if let BotAction::C(incmd) = act { if let BotAction::C(incmd) = act {
let actdb = mgr.botactions.read().await; let actdb = mgr.botactions.read().await;
for (module, moduleactions) in &(*actdb) { for (module, moduleactions) in &(*actdb) {
for modact in moduleactions.iter() { for modact in moduleactions.iter() {
if let BotAction::C(dbcmd) = &modact { if let BotAction::C(dbcmd) = &modact {
@ -262,13 +256,12 @@ impl ModulesManager {
if incmd.command.to_lowercase() == dbcmd.command.to_lowercase() { if incmd.command.to_lowercase() == dbcmd.command.to_lowercase() {
// Returning State - with the identified module // Returning State - with the identified module
return Some(module.clone()); // works return Some(module.clone()); // works
} }
for a in &dbcmd.alias { for a in &dbcmd.alias {
if incmd.command.to_lowercase() == a.to_lowercase() { if incmd.command.to_lowercase() == a.to_lowercase() {
// Returning State - with the identified module // Returning State - with the identified module
return Some(module.clone()); // works return Some(module.clone()); // works
} }
} }
@ -278,14 +271,14 @@ impl ModulesManager {
for inalias in &incmd.alias { for inalias in &incmd.alias {
if inalias.to_lowercase() == dbcmd.command.to_lowercase() { if inalias.to_lowercase() == dbcmd.command.to_lowercase() {
// Returning State - with the identified module // Returning State - with the identified module
return Some(module.clone()); // works return Some(module.clone()); // works
} }
for a in &dbcmd.alias { for a in &dbcmd.alias {
if inalias.to_lowercase() == a.to_lowercase() { if inalias.to_lowercase() == a.to_lowercase() {
// Returning State - with the identified module // Returning State - with the identified module
return Some(module.clone()); // works return Some(module.clone()); // works
} }
} }
@ -307,21 +300,21 @@ impl ModulesManager {
} }
let mut dbt = self.statusdb.write().await; let mut dbt = self.statusdb.write().await;
let statusvector = dbt let statusvector = dbt.entry(in_module.clone()).or_insert(Vec::new());
.entry(in_module.clone())
.or_insert(Vec::new());
statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); // Pushes the Module as Enabled at Instance Level statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); // Pushes the Module as Enabled at Instance Level
let mut a = self.botactions.write().await; let mut a = self.botactions.write().await;
let modactions = a let modactions = a.entry(in_module.clone()).or_insert(Vec::new());
.entry(in_module.clone())
.or_insert(Vec::new());
modactions.push(in_action); modactions.push(in_action);
botlog::trace( botlog::trace(
format!("Modules Manager> add_botaction called - botactions size : {}", modactions.len()).as_str(), format!(
"Modules Manager> add_botaction called - botactions size : {}",
modactions.len()
)
.as_str(),
Some("ModulesManager > init()".to_string()), Some("ModulesManager > init()".to_string()),
None, None,
); );

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,7 @@ use twitch_irc::message::PrivmsgMessage;
use crate::core::botlog; use crate::core::botlog;
use crate::core::botmodules::bot_actions::actions_util::{self, BotAR}; use crate::core::bot_actions::actions_util::{self, BotAR};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::identity; use crate::core::identity;

View file

@ -20,7 +20,7 @@ pub async fn main() {
let bot = BotInstance::init().await; let bot = BotInstance::init().await;
{ {
botlog::debug("Reading bot actions", Some("main()".to_string()), None); botlog::trace("Reading bot actions", Some("main()".to_string()), None);
let actsdb = Arc::clone(&bot.botmodules.botactions); let actsdb = Arc::clone(&bot.botmodules.botactions);
let actsdb_lock = actsdb.read().await; let actsdb_lock = actsdb.read().await;
@ -29,10 +29,10 @@ pub async fn main() {
for act in acts { for act in acts {
let outstr = match act { let outstr = match act {
botmodules::BotAction::C(b) => { botmodules::BotAction::C(b) => {
format!("bot actions: {}", b.command) format!("bot actions > Command : {}", b.command)
} }
botmodules::BotAction::L(l) => { botmodules::BotAction::L(l) => {
format!("bot actions: {}", l.name) format!("bot actions > Listener : {}", l.name)
} }
_ => "Not a valid match??".to_string(), _ => "Not a valid match??".to_string(),
}; };