From fcf4f3f7cfe6c94eefdb3883bb3e06e52d9895a6 Mon Sep 17 00:00:00 2001 From: mzntori Date: Fri, 29 Mar 2024 21:06:48 +0100 Subject: [PATCH] add debug implementations that helped (kinda) --- src/core/bot_actions.rs | 2 +- src/core/botinstance.rs | 3 ++- src/core/botmodules.rs | 34 +++++++++++++++++++++++++++++++++- src/core/chat.rs | 2 +- src/core/identity.rs | 2 +- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 130be94..c7ec0c5 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -12,7 +12,7 @@ pub type BotAR = Arc>; pub type ActAR = Arc>; pub type RoutineAR = Arc>; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 86ac8bb..2c06cea 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -40,7 +40,7 @@ pub struct Channel(pub String); use super::bot_actions::ExecBodyParams; use super::botmodules::StatusType; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct BotManagers { pub identity: Arc>, pub chat: Chat, @@ -70,6 +70,7 @@ impl ArcBox { } } +#[derive(Debug)] pub struct BotInstance { pub prefix: char, pub bot_channel: Channel, diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 0dba823..32e669f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -28,6 +28,7 @@ use core::panic; use std::borrow::Borrow; use std::borrow::BorrowMut; use std::collections::HashMap; +use std::fmt::{Debug, Formatter}; use std::ops::DerefMut; use std::sync::Arc; @@ -470,6 +471,7 @@ pub enum StatusType { Disabled(StatusLvl), } +#[derive(Debug)] pub enum BotAction { C(BotCommand), L(Listener), @@ -532,6 +534,12 @@ impl BotActionTrait for BotCommand { } } +impl Debug for BotCommand { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?} {:?} {:?} {:?} {:?}", self.module, self.command, self.alias, self.help, self.required_roles) + } +} + pub struct Listener { pub module: BotModule, pub name: String, @@ -579,6 +587,12 @@ impl BotActionTrait for Listener { } } +impl Debug for Listener { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?} {:?} {:?}", self.module, self.name, self.help) + } +} + // #[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash)] pub enum RoutineAttr { @@ -617,6 +631,7 @@ pub enum RoutineAttr { */ // For some key statuses and in particular Stopping to Gracefully stop +#[derive(Debug)] pub enum RoutineSignal { Stopping, // Gracefully Stopping Stopped, // When cancelling or aborting, this also is represented by Stopped @@ -624,7 +639,6 @@ pub enum RoutineSignal { NotStarted, } -// #[derive(Debug)] pub struct Routine { pub name : String , pub module : BotModule , // from() can determine this if passed parents_params @@ -641,6 +655,23 @@ pub struct Routine { pub self_act_ar : Option , } +// implement Debug manually witouth `exec_body` since you cant debug `ExecBody`. +impl Debug for Routine { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.name)?; + write!(f, "{:?}", self.module)?; + write!(f, "{:?}", self.channel)?; + write!(f, "{:?}", self.parent_params)?; + write!(f, "{:?}", self.join_handle)?; + write!(f, "{:?}", self.start_time)?; + write!(f, "{:?}", self.complete_iterations)?; + write!(f, "{:?}", self.remaining_iterations)?; + write!(f, "{:?}", self.routine_attr)?; + write!(f, "{:?}", self.internal_signal)?; + write!(f, "{:?}", self.self_routine_ar)?; + write!(f, "{:?}", self.self_act_ar) + } +} impl Routine { @@ -1477,6 +1508,7 @@ impl Routine { type StatusdbEntry = (ModGroup, Vec); type ModuleActions = Vec>>; +#[derive(Debug)] pub struct ModulesManager { statusdb: Arc>>, pub botactions: Arc>>, diff --git a/src/core/chat.rs b/src/core/chat.rs index a83bd8c..275ef3b 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -27,7 +27,7 @@ use super::identity; use async_recursion::async_recursion; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Chat { pub ratelimiters: Arc>>, // used to limit messages sent per channel pub client: TwitchIRCClient, StaticLoginCredentials>, diff --git a/src/core/identity.rs b/src/core/identity.rs index e1500eb..7a9e579 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -698,7 +698,7 @@ pub enum Permissible { type UserRolesDB = HashMap>>>; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct IdentityManager { special_roles_users: Arc>, }