botlog module
This commit is contained in:
parent
a2747b1ad5
commit
90b9b66e6d
9 changed files with 404 additions and 238 deletions
src/core
|
@ -1,15 +1,14 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
use std::env;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
use tokio::sync::{RwLock,Mutex};
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
|
||||
use twitch_irc::login::StaticLoginCredentials;
|
||||
use twitch_irc::message::{PrivmsgMessage,ServerMessage};
|
||||
use twitch_irc::transport::tcp::{TCPTransport,TLS};
|
||||
use twitch_irc::{ClientConfig,SecureTCPTransport,TwitchIRCClient};
|
||||
use twitch_irc::message::{PrivmsgMessage, ServerMessage};
|
||||
use twitch_irc::transport::tcp::{TCPTransport, TLS};
|
||||
use twitch_irc::{ClientConfig, SecureTCPTransport, TwitchIRCClient};
|
||||
|
||||
use dotenv::dotenv;
|
||||
|
||||
|
@ -20,189 +19,188 @@ use rand::Rng;
|
|||
use crate::core::ratelimiter;
|
||||
use crate::core::ratelimiter::RateLimiter;
|
||||
|
||||
use crate::core::botmodules::ModulesManager;
|
||||
use crate::core::botmodules::bot_actions::actions_util::BotAR;
|
||||
use crate::core::botmodules::ModulesManager;
|
||||
use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
|
||||
|
||||
use crate::core::botlog;
|
||||
|
||||
pub mod botlog {
|
||||
// pub mod botlog {
|
||||
|
||||
/*
|
||||
Module intends to add some layers to logging with the module user only requiring to pass :
|
||||
- String Log message
|
||||
- Option<String> - Code_Module
|
||||
- Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
|
||||
*/
|
||||
// /*
|
||||
// Module intends to add some layers to logging with the module user only requiring to pass :
|
||||
// - String Log message
|
||||
// - Option<String> - Code_Module
|
||||
// - Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
|
||||
// */
|
||||
// // use casual_logger::{Level, Log};
|
||||
// use casual_logger::Log;
|
||||
// use twitch_irc::message::PrivmsgMessage;
|
||||
|
||||
// use casual_logger::{Level, Log};
|
||||
use casual_logger::Log;
|
||||
use twitch_irc::message::PrivmsgMessage;
|
||||
// // trace, debug, info, notice, warn, error, fatal
|
||||
|
||||
// trace, debug, info, notice, warn, error, fatal
|
||||
// /*
|
||||
|
||||
/*
|
||||
// in main : Log::debug("Checking bot actions", Some("main()".to_string()), None);
|
||||
|
||||
in main : Log::debug("Checking bot actions", Some("main()".to_string()), None);
|
||||
// in log :
|
||||
// [blalba@timestmp]
|
||||
// debug = "Checking bot actions",
|
||||
|
||||
in log :
|
||||
[blalba@timestmp]
|
||||
debug = "Checking bot actions",
|
||||
// */
|
||||
// pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
*/
|
||||
// Log::trace_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
// }
|
||||
|
||||
pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
// pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
Log::trace_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
}
|
||||
// Log::debug_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
// }
|
||||
|
||||
pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
// pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
Log::debug_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
}
|
||||
// Log::info_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
// }
|
||||
|
||||
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
// pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
Log::info_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
}
|
||||
// Log::notice_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
// }
|
||||
|
||||
pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
// pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
Log::notice_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
}
|
||||
// Log::warn_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
// }
|
||||
|
||||
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
// pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
Log::warn_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
}
|
||||
// Log::error_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
// }
|
||||
|
||||
pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
// pub fn fatal<'a>(
|
||||
// in_msg: &'a str,
|
||||
// in_module: Option<String>,
|
||||
// in_prvmsg: Option<&PrivmsgMessage>,
|
||||
// ) -> &'a str {
|
||||
// let (chnl, chatter) = match in_prvmsg {
|
||||
// Some(prvmsg) => {
|
||||
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
// (
|
||||
// Some(prvmsg.channel_login.clone()),
|
||||
// Some(prvmsg.sender.name.clone()),
|
||||
// ) // <-- Clone fine atm while we're just working with Strings
|
||||
// }
|
||||
// None => (None, None),
|
||||
// };
|
||||
|
||||
Log::error_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
}
|
||||
// Log::fatal_t(
|
||||
// in_msg,
|
||||
// casual_logger::Table::default() //
|
||||
// .str("Channel", &format!("{:?}", chnl))
|
||||
// .str("Chatter", &format!("{:?}", chatter))
|
||||
// .str("Code_Module", &format!("{:?}", in_module)),
|
||||
// );
|
||||
|
||||
pub fn fatal<'a>(
|
||||
in_msg: &'a str,
|
||||
in_module: Option<String>,
|
||||
in_prvmsg: Option<&PrivmsgMessage>,
|
||||
) -> &'a str {
|
||||
let (chnl, chatter) = match in_prvmsg {
|
||||
Some(prvmsg) => {
|
||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||
(
|
||||
Some(prvmsg.channel_login.clone()),
|
||||
Some(prvmsg.sender.name.clone()),
|
||||
) // <-- Clone fine atm while we're just working with Strings
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
|
||||
Log::fatal_t(
|
||||
in_msg,
|
||||
casual_logger::Table::default() //
|
||||
.str("Channel", &format!("{:?}", chnl))
|
||||
.str("Chatter", &format!("{:?}", chatter))
|
||||
.str("Code_Module", &format!("{:?}", in_module)),
|
||||
);
|
||||
|
||||
in_msg
|
||||
}
|
||||
}
|
||||
// in_msg
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub enum ChType {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue