fmt & clippy
This commit is contained in:
parent
e032cfb918
commit
d998e2f290
8 changed files with 228 additions and 161 deletions
|
@ -16,5 +16,5 @@ casual_logger = "0.6.5"
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "botLib"
|
name = "bot_lib"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
|
@ -11,9 +11,9 @@ use twitch_irc::SecureTCPTransport;
|
||||||
use twitch_irc::TwitchIRCClient;
|
use twitch_irc::TwitchIRCClient;
|
||||||
// use std::borrow::Borrow;
|
// use std::borrow::Borrow;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::borrow::BorrowMut;
|
// use std::borrow::BorrowMut;
|
||||||
use std::boxed;
|
// use std::boxed;
|
||||||
use std::cell::Ref;
|
// use std::cell::Ref;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -23,30 +23,29 @@ use rand::Rng;
|
||||||
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
|
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
// use crate::core::botmodules::BotAction;
|
||||||
|
|
||||||
use crate::core::botmodules::BotAction;
|
|
||||||
use crate::core::ratelimiter;
|
use crate::core::ratelimiter;
|
||||||
use crate::core::ratelimiter::RateLimiter;
|
use crate::core::ratelimiter::RateLimiter;
|
||||||
|
|
||||||
use crate::core::botmodules;
|
// use crate::core::botmodules;
|
||||||
use crate::core::botmodules::ModulesManager;
|
use crate::core::botmodules::ModulesManager;
|
||||||
use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
|
use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
// use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
// use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
// use futures::lock::Mutex;
|
// use futures::lock::Mutex;
|
||||||
|
|
||||||
use std::pin::Pin;
|
// use std::pin::Pin;
|
||||||
|
|
||||||
//use std::borrow::Borrow;
|
//use std::borrow::Borrow;
|
||||||
use core::borrow::Borrow;
|
// use core::borrow::Borrow;
|
||||||
|
|
||||||
// pub type BotAR = Arc<RwLock<BotInstance>>;
|
// pub type BotAR = Arc<RwLock<BotInstance>>;
|
||||||
use super::botmodules::bot_actions::actions_util::BotAR;
|
use super::botmodules::bot_actions::actions_util::BotAR;
|
||||||
|
|
||||||
use casual_logger::{Level, Log};
|
// use casual_logger::{Level, Log};
|
||||||
|
use casual_logger::Log;
|
||||||
|
|
||||||
pub mod botlog {
|
pub mod botlog {
|
||||||
|
|
||||||
|
@ -57,7 +56,8 @@ pub mod botlog {
|
||||||
- Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
|
- Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use casual_logger::{Level, Log};
|
// use casual_logger::{Level, Log};
|
||||||
|
use casual_logger::Log;
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
// trace, debug, info, notice, warn, error, fatal
|
// trace, debug, info, notice, warn, error, fatal
|
||||||
|
@ -72,11 +72,7 @@ pub mod botlog {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn trace(
|
pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
in_msg: &str,
|
|
||||||
in_module: Option<String>,
|
|
||||||
in_prvmsg: Option<&PrivmsgMessage>,
|
|
||||||
) -> () {
|
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
|
@ -97,11 +93,7 @@ pub mod botlog {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug(
|
pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
in_msg: &str,
|
|
||||||
in_module: Option<String>,
|
|
||||||
in_prvmsg: Option<&PrivmsgMessage>,
|
|
||||||
) -> () {
|
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
|
@ -122,7 +114,7 @@ pub mod botlog {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) -> () {
|
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
|
@ -143,11 +135,7 @@ pub mod botlog {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notice(
|
pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
in_msg: &str,
|
|
||||||
in_module: Option<String>,
|
|
||||||
in_prvmsg: Option<&PrivmsgMessage>,
|
|
||||||
) -> () {
|
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
|
@ -168,7 +156,7 @@ pub mod botlog {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) -> () {
|
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
|
@ -189,11 +177,7 @@ pub mod botlog {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error(
|
pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
|
||||||
in_msg: &str,
|
|
||||||
in_module: Option<String>,
|
|
||||||
in_prvmsg: Option<&PrivmsgMessage>,
|
|
||||||
) -> () {
|
|
||||||
let (chnl, chatter) = match in_prvmsg {
|
let (chnl, chatter) = match in_prvmsg {
|
||||||
Some(prvmsg) => {
|
Some(prvmsg) => {
|
||||||
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
|
||||||
|
@ -262,17 +246,18 @@ impl Chat {
|
||||||
) -> Chat {
|
) -> Chat {
|
||||||
Chat {
|
Chat {
|
||||||
ratelimiters: Arc::new(Mutex::new(ratelimiters)),
|
ratelimiters: Arc::new(Mutex::new(ratelimiters)),
|
||||||
client: client,
|
// client: client,
|
||||||
|
client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init_channel(&mut self, chnl: ChType) -> () {
|
pub async fn init_channel(&mut self, chnl: ChType) {
|
||||||
let n = RateLimiter::new();
|
let n = RateLimiter::new();
|
||||||
self.ratelimiters.lock().await.insert(chnl, n);
|
self.ratelimiters.lock().await.insert(chnl, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
|
// pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
|
||||||
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) -> () {
|
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) {
|
||||||
/*
|
/*
|
||||||
formats message before sending to TwitchIRC
|
formats message before sending to TwitchIRC
|
||||||
|
|
||||||
|
@ -308,7 +293,7 @@ impl Chat {
|
||||||
msg.channel_login, "rate limit counter increase"
|
msg.channel_login, "rate limit counter increase"
|
||||||
),
|
),
|
||||||
Some("Chat > say_in_reply_to".to_string()),
|
Some("Chat > say_in_reply_to".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
contextratelimiter.increment_counter();
|
contextratelimiter.increment_counter();
|
||||||
// println!("{:?}",self.ratelimiters);
|
// println!("{:?}",self.ratelimiters);
|
||||||
|
@ -316,29 +301,29 @@ impl Chat {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
&format!("{:?}", self.ratelimiters),
|
&format!("{:?}", self.ratelimiters),
|
||||||
Some("Chat > say_in_reply_to".to_string()),
|
Some("Chat > say_in_reply_to".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ratelimiter::LimiterResp::Skip => {
|
ratelimiter::LimiterResp::Skip => {
|
||||||
(); // do nothing otherwise
|
// (); // do nothing otherwise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log::flush();
|
Log::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn say(&self, _: String, _: String) -> () {
|
async fn _say(&self, _: String, _: String) {
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
// self.client.say(msg,outmsg).await.unwrap();
|
// self.client.say(msg,outmsg).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn me(&self, _: String, _: String) -> () {
|
async fn _me(&self, _: String, _: String) {
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
// self.client.me(msg,outmsg).await.unwrap();
|
// self.client.me(msg,outmsg).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn me_in_reply_to(&self, _: String, _: String) -> () {
|
async fn _me_in_reply_to(&self, _: String, _: String) {
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
// self.client.me(msg,outmsg).await.unwrap();
|
// self.client.me(msg,outmsg).await.unwrap();
|
||||||
|
@ -363,7 +348,7 @@ impl BotManagers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rIdentity(self) -> Arc<RwLock<IdentityManager>> {
|
pub fn r_identity(self) -> Arc<RwLock<IdentityManager>> {
|
||||||
self.identity
|
self.identity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -446,7 +431,8 @@ impl BotInstance {
|
||||||
// };
|
// };
|
||||||
|
|
||||||
BotInstance {
|
BotInstance {
|
||||||
prefix: prefix,
|
// prefix: prefix,
|
||||||
|
prefix,
|
||||||
bot_channel: Channel(login_name),
|
bot_channel: Channel(login_name),
|
||||||
incoming_messages: Arc::new(RwLock::new(incoming_messages)),
|
incoming_messages: Arc::new(RwLock::new(incoming_messages)),
|
||||||
botmodules: ModulesManager::init().await,
|
botmodules: ModulesManager::init().await,
|
||||||
|
@ -458,7 +444,7 @@ impl BotInstance {
|
||||||
// b
|
// b
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn runner(self) -> () {
|
pub async fn runner(self) {
|
||||||
let bot = Arc::new(RwLock::new(self));
|
let bot = Arc::new(RwLock::new(self));
|
||||||
|
|
||||||
let join_handle = tokio::spawn(async move {
|
let join_handle = tokio::spawn(async move {
|
||||||
|
@ -503,7 +489,8 @@ impl BotInstance {
|
||||||
// println!("Privmsg section");
|
// println!("Privmsg section");
|
||||||
// Log::debug(&format!("Privmsg section"));
|
// Log::debug(&format!("Privmsg section"));
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
&format!("Privmsg section"),
|
// &format!("Privmsg section"),
|
||||||
|
"Privmsg section",
|
||||||
Some("BotInstance > runner()".to_string()),
|
Some("BotInstance > runner()".to_string()),
|
||||||
Some(&msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
@ -551,8 +538,9 @@ impl BotInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_botmgrs(self) -> BotManagers {
|
pub async fn get_botmgrs(self) -> BotManagers {
|
||||||
let a = self.botmgrs;
|
// let a = self.botmgrs;
|
||||||
a
|
// a
|
||||||
|
self.botmgrs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_identity(&self) -> Arc<RwLock<IdentityManager>> {
|
pub fn get_identity(&self) -> Arc<RwLock<IdentityManager>> {
|
||||||
|
@ -560,19 +548,20 @@ impl BotInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_prefix(&self) -> char {
|
pub fn get_prefix(&self) -> char {
|
||||||
(*self).prefix
|
// (*self).prefix
|
||||||
|
self.prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// PRIVATE FUNCTIONS
|
// PRIVATE FUNCTIONS
|
||||||
|
|
||||||
pub async fn listener_main_prvmsg(bot: BotAR, msg: &PrivmsgMessage) -> () {
|
pub async fn listener_main_prvmsg(bot: BotAR, msg: &PrivmsgMessage) {
|
||||||
// println!(">> Inner listenermain_prvmsg()");
|
// println!(">> Inner listenermain_prvmsg()");
|
||||||
// Log::trace(">> Inner listenermain_prvmsg()");
|
// Log::trace(">> Inner listenermain_prvmsg()");
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
">> Inner listenermain_prvmsg()",
|
">> Inner listenermain_prvmsg()",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// let a = a;
|
// let a = a;
|
||||||
|
@ -589,7 +578,7 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
&format!("hacts size : {}", (*a).len()),
|
&format!("hacts size : {}", (*a).len()),
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
|
// println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
|
||||||
|
@ -597,16 +586,17 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
">> Inner listenermain_prvmsg() >> before for loop of bot actions",
|
">> Inner listenermain_prvmsg() >> before for loop of bot actions",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
for (_m, acts) in &*hacts.read().await {
|
// for (_m, acts) in &*hacts.read().await {
|
||||||
|
for acts in (*hacts.read().await).values() {
|
||||||
// println!(">> Inner listenermain_prvmsg() >> checking bot actions");
|
// println!(">> Inner listenermain_prvmsg() >> checking bot actions");
|
||||||
// Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions");
|
// Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions");
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
">> Inner listenermain_prvmsg() >> checking bot actions",
|
">> Inner listenermain_prvmsg() >> checking bot actions",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// let bot = bot;
|
// let bot = bot;
|
||||||
|
@ -617,10 +607,11 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
">> Inner listenermain_prvmsg() >> checking bot actions >> 2",
|
">> Inner listenermain_prvmsg() >> checking bot actions >> 2",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let _act = match a {
|
// let _act = match a {
|
||||||
|
match a {
|
||||||
crate::core::botmodules::BotAction::C(c) => {
|
crate::core::botmodules::BotAction::C(c) => {
|
||||||
/*
|
/*
|
||||||
BotCommand handling -
|
BotCommand handling -
|
||||||
|
@ -641,13 +632,13 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"Reviewing internal commands",
|
"Reviewing internal commands",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
|
// let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
|
||||||
let inpt = msg
|
let inpt = msg
|
||||||
.message_text
|
.message_text
|
||||||
.split(" ")
|
.split(' ')
|
||||||
.next()
|
.next()
|
||||||
.expect("ERROR during BotCommand");
|
.expect("ERROR during BotCommand");
|
||||||
|
|
||||||
|
@ -675,7 +666,8 @@ impl BotInstance {
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"Confirmed bot command",
|
"Confirmed bot command",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// println!("Going for botlock");
|
// println!("Going for botlock");
|
||||||
|
@ -683,7 +675,8 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"Going for botlock",
|
"Going for botlock",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
|
@ -692,7 +685,8 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"Going for identity",
|
"Going for identity",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let id = botlock.get_identity();
|
let id = botlock.get_identity();
|
||||||
|
@ -704,11 +698,14 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"Unpacking identity",
|
"Unpacking identity",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// let (a, b) =
|
||||||
|
// id.can_user_run_prvmsg(&msg, c.required_roles.clone()).await;
|
||||||
let (a, b) =
|
let (a, b) =
|
||||||
id.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await;
|
id.can_user_run_prvmsg(msg, c.required_roles.clone()).await;
|
||||||
// // [-] #todo : need ot add functionality around here to do an o7 when a mod has been promoted => Preferring to do this outside the mutex
|
// // [-] #todo : need ot add functionality around here to do an o7 when a mod has been promoted => Preferring to do this outside the mutex
|
||||||
// if let ChangeResult::Success(b) = b {
|
// if let ChangeResult::Success(b) = b {
|
||||||
// // let b = b.to_lowercase();
|
// // let b = b.to_lowercase();
|
||||||
|
@ -724,7 +721,8 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"Checking if permissible",
|
"Checking if permissible",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (eval, rolechange) = eval;
|
let (eval, rolechange) = eval;
|
||||||
|
@ -736,7 +734,8 @@ impl BotInstance {
|
||||||
botlog::notice(
|
botlog::notice(
|
||||||
"Assigning Mod UserRole to Mod",
|
"Assigning Mod UserRole to Mod",
|
||||||
Some("botinstance > listener_main_prvmsg()".to_string()),
|
Some("botinstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// println!("Read() lock Bot");
|
// println!("Read() lock Bot");
|
||||||
|
@ -744,13 +743,15 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"Read() lock Bot",
|
"Read() lock Bot",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let botlock = bot.read().await;
|
let botlock = bot.read().await;
|
||||||
let outstr =
|
let outstr =
|
||||||
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
|
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
|
||||||
(*botlock).botmgrs.chat.say_in_reply_to(msg, outstr).await;
|
// (*botlock).botmgrs.chat.say_in_reply_to(msg, outstr).await;
|
||||||
|
botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +762,8 @@ impl BotInstance {
|
||||||
botlog::debug(
|
botlog::debug(
|
||||||
"Executed as permissible",
|
"Executed as permissible",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
let a = Arc::clone(&bot);
|
let a = Arc::clone(&bot);
|
||||||
c.execute(a, msg.clone()).await;
|
c.execute(a, msg.clone()).await;
|
||||||
|
@ -770,7 +772,8 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"exit out of execution",
|
"exit out of execution",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Permissible::Block => {
|
Permissible::Block => {
|
||||||
|
@ -779,7 +782,8 @@ impl BotInstance {
|
||||||
botlog::info(
|
botlog::info(
|
||||||
"User Not allowed to run command",
|
"User Not allowed to run command",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
} // _ => (),
|
} // _ => (),
|
||||||
};
|
};
|
||||||
|
@ -803,7 +807,8 @@ impl BotInstance {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
"End of Separate Listener Main prvmsg",
|
"End of Separate Listener Main prvmsg",
|
||||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
// self
|
// self
|
||||||
|
|
|
@ -5,23 +5,23 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::core::identity;
|
use crate::core::identity;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
// use std::cell::RefCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use std::future::Future;
|
// use std::future::Future;
|
||||||
// use futures::lock::Mutex;
|
// use futures::lock::Mutex;
|
||||||
|
|
||||||
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
|
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
|
||||||
use tokio::sync::Mutex;
|
// use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::core::botinstance::{self, botlog, BotInstance};
|
use crate::core::botinstance::{self, botlog, BotInstance};
|
||||||
use std::rc::Rc;
|
// use std::rc::Rc;
|
||||||
|
|
||||||
// use tokio::sync::RwLock;
|
// use tokio::sync::RwLock;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use casual_logger::{Level, Log};
|
// use casual_logger::{Level, Log};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ use botinstance::ChType;
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
pub use ChType::Channel;
|
pub use ChType::Channel;
|
||||||
|
|
||||||
use self::bot_actions::actions_util;
|
// use self::bot_actions::actions_util;
|
||||||
use self::bot_actions::actions_util::BotAR;
|
use self::bot_actions::actions_util::BotAR;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum StatusLvl {
|
pub enum StatusLvl {
|
||||||
Instance,
|
Instance,
|
||||||
Ch(ChType),
|
_Ch(ChType),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -84,7 +84,7 @@ pub enum BotAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotAction {
|
impl BotAction {
|
||||||
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) -> () {
|
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||||
match self {
|
match self {
|
||||||
BotAction::L(a) => a.execute(m, n).await,
|
BotAction::L(a) => a.execute(m, n).await,
|
||||||
BotAction::C(a) => a.execute(m, n).await,
|
BotAction::C(a) => a.execute(m, n).await,
|
||||||
|
@ -111,8 +111,9 @@ pub struct BotCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotCommand {
|
impl BotCommand {
|
||||||
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) -> () {
|
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||||
((*self).exec_body)(m, n).await;
|
// ((*self).exec_body)(m, n).await;
|
||||||
|
(*self.exec_body)(m, n).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,10 +139,11 @@ pub mod bot_actions {
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
use std::rc::Rc;
|
// use std::rc::Rc;
|
||||||
|
|
||||||
use crate::core::botinstance::{BotInstance, BotManagers, Chat};
|
// use crate::core::botinstance::{BotInstance, BotManagers, Chat};
|
||||||
use std::cell::RefCell;
|
use crate::core::botinstance::BotInstance;
|
||||||
|
// use std::cell::RefCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
// use futures::lock::Mutex;
|
// use futures::lock::Mutex;
|
||||||
|
@ -172,8 +174,9 @@ pub struct Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Listener {
|
impl Listener {
|
||||||
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) -> () {
|
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||||
((*self).exec_body)(m, n).await;
|
// ((*self).exec_body)(m, n).await;
|
||||||
|
(self.exec_body)(m, n).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +210,7 @@ impl BotActionTrait for Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Routine {}
|
pub struct Routine {}
|
||||||
|
|
||||||
// #[derive(Clone)]
|
// #[derive(Clone)]
|
||||||
|
|
||||||
|
@ -235,7 +238,7 @@ impl ModulesManager {
|
||||||
let m = HashMap::new();
|
let m = HashMap::new();
|
||||||
let act = HashMap::new();
|
let act = HashMap::new();
|
||||||
|
|
||||||
let mut mgr = ModulesManager {
|
let mgr = ModulesManager {
|
||||||
statusdb: Arc::new(RwLock::new(m)),
|
statusdb: Arc::new(RwLock::new(m)),
|
||||||
botactions: Arc::new(RwLock::new(act)),
|
botactions: Arc::new(RwLock::new(act)),
|
||||||
};
|
};
|
||||||
|
@ -392,13 +395,21 @@ impl ModulesManager {
|
||||||
// // () // return because there was a conflict?
|
// // () // return because there was a conflict?
|
||||||
// panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , probmod );
|
// panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , probmod );
|
||||||
// }
|
// }
|
||||||
match find_conflict_module(&self, &in_action).await {
|
// match find_conflict_module(&self, &in_action).await {
|
||||||
// Some(c) => panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , c ),
|
// match find_conflict_module(self, &in_action).await {
|
||||||
Some(c) => panic!(
|
// // Some(c) => panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , c ),
|
||||||
|
// Some(c) => panic!(
|
||||||
|
// "ERROR: Could not add module; there was a conflict with existing module {:?}",
|
||||||
|
// c
|
||||||
|
// ),
|
||||||
|
// None => (),
|
||||||
|
// }
|
||||||
|
|
||||||
|
if let Some(c) = find_conflict_module(self, &in_action).await {
|
||||||
|
panic!(
|
||||||
"ERROR: Could not add module; there was a conflict with existing module {:?}",
|
"ERROR: Could not add module; there was a conflict with existing module {:?}",
|
||||||
c
|
c
|
||||||
),
|
)
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dbt = self.statusdb.write().await;
|
let mut dbt = self.statusdb.write().await;
|
||||||
|
@ -432,13 +443,12 @@ impl ModulesManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn statuscleanup(&self, _: Option<ChType>) -> () {
|
fn _statuscleanup(&self, _: Option<ChType>) {
|
||||||
// internal cleans up statusdb . For example :
|
// internal cleans up statusdb . For example :
|
||||||
// - remove redudancies . If we see several Enabled("m"), only keep 1x
|
// - remove redudancies . If we see several Enabled("m"), only keep 1x
|
||||||
// - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m")
|
// - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m")
|
||||||
// the IDEAL is that this is ran before every read/update operation to ensure quality
|
// the IDEAL is that this is ran before every read/update operation to ensure quality
|
||||||
// Option<ChType> can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel
|
// Option<ChType> can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel
|
||||||
// Passing None to chnl may be a heavy operation, as this will review and look at the whole table
|
// Passing None to chnl may be a heavy operation, as this will review and look at the whole table
|
||||||
()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
use std::borrow::Borrow;
|
// use std::borrow::Borrow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::error::Error;
|
// use std::error::Error;
|
||||||
|
|
||||||
use crate::core::botmodules::bot_actions::actions_util;
|
use crate::core::botmodules::bot_actions::actions_util;
|
||||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
|
// use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
|
||||||
|
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
||||||
|
|
||||||
use crate::core::botinstance::{self, botlog, BotInstance, ChType};
|
// use crate::core::botinstance::{self, botlog, BotInstance, ChType};
|
||||||
use futures::lock::Mutex;
|
use crate::core::botinstance::{self, ChType};
|
||||||
use twitch_irc::message::{Badge, PrivmsgMessage};
|
// use futures::lock::Mutex;
|
||||||
|
// use twitch_irc::message::{Badge, PrivmsgMessage};
|
||||||
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
// use crate::core::botmodules::ChType;
|
// use crate::core::botmodules::ChType;
|
||||||
|
|
||||||
use crate::core::botinstance::ArcBox;
|
// use crate::core::botinstance::ArcBox;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
// use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
// use std::rc::Rc;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use casual_logger::{Level, Log};
|
use casual_logger::Log;
|
||||||
|
|
||||||
use super::botmodules::bot_actions::actions_util::BotAR;
|
use super::botmodules::bot_actions::actions_util::BotAR;
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
|
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) -> () {
|
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||||
// println!("Called cmd promote");
|
// println!("Called cmd promote");
|
||||||
botinstance::botlog::trace(
|
botinstance::botlog::trace(
|
||||||
|
@ -99,7 +102,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
let sendername = msg.clone().sender.name;
|
let sendername = msg.clone().sender.name;
|
||||||
|
|
||||||
let mut argv = msg.message_text.split(" ");
|
let mut argv = msg.message_text.split(' ');
|
||||||
|
|
||||||
argv.next(); // Skip the command name
|
argv.next(); // Skip the command name
|
||||||
|
|
||||||
|
@ -142,7 +145,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
let rslt = match targetusr {
|
let rslt = match targetusr {
|
||||||
Some(targetusr) => {
|
Some(targetusr) => {
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
&format!("running promote()"),
|
// &format!("running promote()"),
|
||||||
|
"running promote()",
|
||||||
Some("identity.rs > cmd_promote()".to_string()),
|
Some("identity.rs > cmd_promote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -167,7 +171,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
&format!("No Targer User argument"),
|
// &format!("No Targer User argument"),
|
||||||
|
"No Targer User argument",
|
||||||
Some("identity.rs > cmd_demote()".to_string()),
|
Some("identity.rs > cmd_demote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -482,7 +487,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
botinstance::botlog::trace(
|
botinstance::botlog::trace(
|
||||||
&format!("End of cmd_promote()"),
|
// &format!("End of cmd_promote()"),
|
||||||
|
"End of cmd_promote()",
|
||||||
Some("identity.rs > cmd_prommote()".to_string()),
|
Some("identity.rs > cmd_prommote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -519,7 +525,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
|
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_msg:PrivmsgMessage) {
|
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_msg:PrivmsgMessage) {
|
||||||
async fn cmd_demote(mut bot: BotAR, msg: PrivmsgMessage) {
|
async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
// println!("Called cmd demote");
|
// println!("Called cmd demote");
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
"Called cmd demote",
|
"Called cmd demote",
|
||||||
|
@ -566,8 +572,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
// let arg2 = argv.next();
|
// let arg2 = argv.next();
|
||||||
|
|
||||||
let (arg1, arg2) = {
|
let (arg1, _arg2) = {
|
||||||
let mut argv = msg.message_text.split(" ");
|
let mut argv = msg.message_text.split(' ');
|
||||||
|
|
||||||
argv.next(); // Skip the command name
|
argv.next(); // Skip the command name
|
||||||
|
|
||||||
|
@ -664,7 +670,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
let rslt = match targetusr {
|
let rslt = match targetusr {
|
||||||
Some(targetusr) => {
|
Some(targetusr) => {
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
&format!("running demote()"),
|
// &format!("running demote()"),
|
||||||
|
"running demote()",
|
||||||
Some("identity.rs > cmd_demote()".to_string()),
|
Some("identity.rs > cmd_demote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -682,7 +689,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
&format!("No Targer User argument"),
|
// &format!("No Targer User argument"),
|
||||||
|
"No Targer User argument",
|
||||||
Some("identity.rs > cmd_demote()".to_string()),
|
Some("identity.rs > cmd_demote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -824,7 +832,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||||
|
|
||||||
// println!("{}",msg.message_text);
|
// println!("{}",msg.message_text);
|
||||||
let mut argv = msg.message_text.split(" ");
|
let mut argv = msg.message_text.split(' ');
|
||||||
|
|
||||||
// for v in argv {
|
// for v in argv {
|
||||||
// println!("args : {v}");
|
// println!("args : {v}");
|
||||||
|
@ -971,7 +979,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
targetchnl.to_lowercase().to_string(),
|
targetchnl.to_lowercase().to_string(),
|
||||||
))) || callersproles.contains(&UserRole::SupMod(ChType::Channel(
|
))) || callersproles.contains(&UserRole::SupMod(ChType::Channel(
|
||||||
targetchnl.to_lowercase().to_string(),
|
targetchnl.to_lowercase().to_string(),
|
||||||
))) || callersproles.contains(&&UserRole::Broadcaster)
|
))) || callersproles.contains(&UserRole::Broadcaster)
|
||||||
{
|
{
|
||||||
idlock
|
idlock
|
||||||
.getspecialuserroles(
|
.getspecialuserroles(
|
||||||
|
@ -1004,7 +1012,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// # I believe at this stage I still have botlock active
|
// # I believe at this stage I still have botlock active
|
||||||
|
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
&format!("Evaluating special roles"),
|
// &format!("Evaluating special roles"),
|
||||||
|
"Evaluating special roles",
|
||||||
Some("identity.rs > init > getroles()".to_string()),
|
Some("identity.rs > init > getroles()".to_string()),
|
||||||
Some(&msg),
|
Some(&msg),
|
||||||
);
|
);
|
||||||
|
@ -1019,7 +1028,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|| (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase())
|
|| (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase())
|
||||||
{
|
{
|
||||||
// First evaluates if they're broadcaster
|
// First evaluates if they're broadcaster
|
||||||
let mut outmsg = format!("FeelsWowMan they're the broadcaster. ");
|
// let mut outmsg = format!("FeelsWowMan they're the broadcaster. ");
|
||||||
|
let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string();
|
||||||
if sproles.contains(&UserRole::Mod(ChType::Channel(
|
if sproles.contains(&UserRole::Mod(ChType::Channel(
|
||||||
msg.channel_login.to_lowercase(),
|
msg.channel_login.to_lowercase(),
|
||||||
))) || sproles.contains(&UserRole::SupMod(ChType::Channel(
|
))) || sproles.contains(&UserRole::SupMod(ChType::Channel(
|
||||||
|
@ -1037,7 +1047,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
{
|
{
|
||||||
format!("Target chatter's user roles are : {:?}", sproles)
|
format!("Target chatter's user roles are : {:?}", sproles)
|
||||||
} else {
|
} else {
|
||||||
format!("Target chatter has no special roles LULE ")
|
// format!("Target chatter has no special roles LULE ")
|
||||||
|
"Target chatter has no special roles LULE ".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
// if sproles.contains(&UserRole::Mod(msg.channel_login.to_lowercase())) {
|
// if sproles.contains(&UserRole::Mod(msg.channel_login.to_lowercase())) {
|
||||||
|
@ -1119,12 +1130,15 @@ pub enum Permissible {
|
||||||
Block,
|
Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserRolesDB = HashMap<String, Arc<RwLock<Vec<UserRole>>>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct IdentityManager {
|
pub struct IdentityManager {
|
||||||
// special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
|
// special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
|
||||||
// special_roles_users : Arc<Mutex<HashMap<String,Vec<UserRole>>>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
|
// special_roles_users : Arc<Mutex<HashMap<String,Vec<UserRole>>>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
|
||||||
// special_roles_users : Arc<RwLock<HashMap<String,Vec<UserRole>>>>,
|
// special_roles_users : Arc<RwLock<HashMap<String,Vec<UserRole>>>>,
|
||||||
special_roles_users: Arc<RwLock<HashMap<String, Arc<RwLock<Vec<UserRole>>>>>>,
|
// special_roles_users: Arc<RwLock<HashMap<String, Arc<RwLock<Vec<UserRole>>>>>>,
|
||||||
|
special_roles_users: Arc<RwLock<UserRolesDB>>,
|
||||||
// parent_mgr : Box<crate::core::botinstance::BotManagers>,
|
// parent_mgr : Box<crate::core::botinstance::BotManagers>,
|
||||||
//parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
|
//parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
|
||||||
}
|
}
|
||||||
|
@ -1217,7 +1231,7 @@ impl IdentityManager {
|
||||||
// pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>>
|
// pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>>
|
||||||
// pub fn can_user_run_PRVMSG(&self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
|
// pub fn can_user_run_PRVMSG(&self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
|
||||||
// pub async fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
|
// pub async fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
|
||||||
pub async fn can_user_run_PRVMSG(
|
pub async fn can_user_run_prvmsg(
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: &PrivmsgMessage,
|
msg: &PrivmsgMessage,
|
||||||
cmdreqroles: Vec<UserRole>,
|
cmdreqroles: Vec<UserRole>,
|
||||||
|
@ -1229,7 +1243,8 @@ impl IdentityManager {
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
"Checking within PRVMSG",
|
"Checking within PRVMSG",
|
||||||
Some("identity.rs > can_user_run_PRVMSG()".to_string()),
|
Some("identity.rs > can_user_run_PRVMSG()".to_string()),
|
||||||
Some(&msg),
|
// Some(&msg),
|
||||||
|
Some(msg),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sender_badge: Option<ChatBadge> = None;
|
let mut sender_badge: Option<ChatBadge> = None;
|
||||||
|
@ -1362,7 +1377,8 @@ impl IdentityManager {
|
||||||
|
|
||||||
let usr = usr.to_lowercase();
|
let usr = usr.to_lowercase();
|
||||||
|
|
||||||
if cmdreqroles.len() == 0 {
|
// if cmdreqroles.len() == 0 {
|
||||||
|
if cmdreqroles.is_empty() {
|
||||||
// return Ok(Permissible::Allow)
|
// return Ok(Permissible::Allow)
|
||||||
return (
|
return (
|
||||||
Permissible::Allow,
|
Permissible::Allow,
|
||||||
|
@ -1413,7 +1429,8 @@ impl IdentityManager {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let roleslock = Arc::clone(&(*self).special_roles_users);
|
// let roleslock = Arc::clone(&(*self).special_roles_users);
|
||||||
|
let roleslock = Arc::clone(&self.special_roles_users);
|
||||||
|
|
||||||
// println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem
|
// println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem
|
||||||
botinstance::botlog::trace(
|
botinstance::botlog::trace(
|
||||||
|
@ -1433,7 +1450,7 @@ impl IdentityManager {
|
||||||
// }
|
// }
|
||||||
self.affirm_chatter_in_db(usr.clone()).await;
|
self.affirm_chatter_in_db(usr.clone()).await;
|
||||||
|
|
||||||
let mut roleslock = roleslock.write().await;
|
let roleslock = roleslock.write().await;
|
||||||
match (*roleslock).get(&usr.to_lowercase()) {
|
match (*roleslock).get(&usr.to_lowercase()) {
|
||||||
Some(usrroles)
|
Some(usrroles)
|
||||||
if usrroles
|
if usrroles
|
||||||
|
@ -1470,7 +1487,7 @@ impl IdentityManager {
|
||||||
// Some("identity.rs > can_user_run()".to_string()), None);
|
// Some("identity.rs > can_user_run()".to_string()), None);
|
||||||
|
|
||||||
let mut roleslock = roleslock;
|
let mut roleslock = roleslock;
|
||||||
let mut a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
|
let a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
|
||||||
let mut alock = a.write().await;
|
let mut alock = a.write().await;
|
||||||
|
|
||||||
alock.push(UserRole::Mod(channelname.clone()));
|
alock.push(UserRole::Mod(channelname.clone()));
|
||||||
|
@ -1513,7 +1530,12 @@ impl IdentityManager {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(a) = (&*self)
|
// if let Some(a) = (&*self)
|
||||||
|
// .special_roles_users
|
||||||
|
// .read()
|
||||||
|
// .await
|
||||||
|
// .get(&usr.to_lowercase())
|
||||||
|
if let Some(a) = self
|
||||||
.special_roles_users
|
.special_roles_users
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
|
@ -1546,7 +1568,12 @@ impl IdentityManager {
|
||||||
// [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow)
|
// [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(ChType::Channel(String::new()))) {
|
if cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) {
|
||||||
if let Some(a) = (&*self)
|
// if let Some(a) = (&*self)
|
||||||
|
// .special_roles_users
|
||||||
|
// .read()
|
||||||
|
// .await
|
||||||
|
// .get(&usr.to_lowercase())
|
||||||
|
if let Some(a) = self
|
||||||
.special_roles_users
|
.special_roles_users
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
|
@ -1579,8 +1606,12 @@ impl IdentityManager {
|
||||||
botinstance::botlog::trace(
|
botinstance::botlog::trace(
|
||||||
&format!(
|
&format!(
|
||||||
"special roles get : {:?}",
|
"special roles get : {:?}",
|
||||||
(&*self)
|
// (&*self)
|
||||||
.special_roles_users
|
// .special_roles_users
|
||||||
|
// .read()
|
||||||
|
// .await
|
||||||
|
// .get(&usr.to_lowercase())
|
||||||
|
self.special_roles_users
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
.get(&usr.to_lowercase())
|
.get(&usr.to_lowercase())
|
||||||
|
@ -1589,7 +1620,8 @@ impl IdentityManager {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(a) = (&*self)
|
// if let Some(a) = (&*self)
|
||||||
|
if let Some(a) = (self)
|
||||||
.special_roles_users
|
.special_roles_users
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
|
@ -1701,7 +1733,7 @@ impl IdentityManager {
|
||||||
|
|
||||||
(authusrroles, trgusrroles)
|
(authusrroles, trgusrroles)
|
||||||
} else {
|
} else {
|
||||||
let mut authusrroles = self
|
let authusrroles = self
|
||||||
.getspecialuserroles(authorizer.to_lowercase().clone(), None)
|
.getspecialuserroles(authorizer.to_lowercase().clone(), None)
|
||||||
.await;
|
.await;
|
||||||
let trgusrroles = self
|
let trgusrroles = self
|
||||||
|
@ -1810,10 +1842,9 @@ impl IdentityManager {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
return ChangeResult::Success(String::from("Promotion Successful"));
|
return ChangeResult::Success(String::from("Promotion Successful"));
|
||||||
}
|
} else {
|
||||||
// Other else conditions would be mostly spcecial responses like ChangeResult::NoChange or ChangeResult::Fail
|
// Other else conditions would be mostly spcecial responses like ChangeResult::NoChange or ChangeResult::Fail
|
||||||
// related to authusrroles
|
// related to authusrroles
|
||||||
else {
|
|
||||||
return ChangeResult::Failed(String::from("You're not permitted to do that"));
|
return ChangeResult::Failed(String::from("You're not permitted to do that"));
|
||||||
}
|
}
|
||||||
} else if !trgusrroles.contains(&UserRole::Broadcaster)
|
} else if !trgusrroles.contains(&UserRole::Broadcaster)
|
||||||
|
@ -1893,8 +1924,13 @@ impl IdentityManager {
|
||||||
|
|
||||||
// At the moment, without any new roles, this should not be reached
|
// At the moment, without any new roles, this should not be reached
|
||||||
|
|
||||||
|
// botinstance::botlog::warn(
|
||||||
|
// &format!("Code Warning : add handing for other trgusrroles"),
|
||||||
|
// Some("identity.rs > promote()".to_string()),
|
||||||
|
// None,
|
||||||
|
// );
|
||||||
botinstance::botlog::warn(
|
botinstance::botlog::warn(
|
||||||
&format!("Code Warning : add handing for other trgusrroles"),
|
"Code Warning : add handing for other trgusrroles",
|
||||||
Some("identity.rs > promote()".to_string()),
|
Some("identity.rs > promote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -2224,8 +2260,13 @@ impl IdentityManager {
|
||||||
// },
|
// },
|
||||||
// _ => (),
|
// _ => (),
|
||||||
// }
|
// }
|
||||||
|
// botinstance::botlog::warn(
|
||||||
|
// &format!("Runtime reached undeveloped code"),
|
||||||
|
// Some("identity.rs > promote()".to_string()),
|
||||||
|
// None,
|
||||||
|
// );
|
||||||
botinstance::botlog::warn(
|
botinstance::botlog::warn(
|
||||||
&format!("Runtime reached undeveloped code"),
|
"Runtime reached undeveloped code",
|
||||||
Some("identity.rs > promote()".to_string()),
|
Some("identity.rs > promote()".to_string()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -2360,7 +2401,9 @@ impl IdentityManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
botinstance::botlog::warn(&format!("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling"),
|
// botinstance::botlog::warn(&format!("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling"),
|
||||||
|
// Some("identity.rs > demote()".to_string()), None);
|
||||||
|
botinstance::botlog::warn("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling",
|
||||||
Some("identity.rs > demote()".to_string()), None);
|
Some("identity.rs > demote()".to_string()), None);
|
||||||
Log::flush();
|
Log::flush();
|
||||||
ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully"))
|
ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully"))
|
||||||
|
@ -2477,7 +2520,8 @@ impl IdentityManager {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
return evalsproles;
|
// return evalsproles;
|
||||||
|
evalsproles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,12 @@ pub enum LimiterResp {
|
||||||
Skip, // as outside of rate limits
|
Skip, // as outside of rate limits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for RateLimiter {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RateLimiter {
|
impl RateLimiter {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -38,7 +44,7 @@ impl RateLimiter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn increment_counter(&mut self) -> () {
|
pub fn increment_counter(&mut self) {
|
||||||
self.msgcounter += 1;
|
self.msgcounter += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -2,12 +2,12 @@
|
||||||
// pub mod modules;
|
// pub mod modules;
|
||||||
//use myLib;
|
//use myLib;
|
||||||
//pub mod lib;
|
//pub mod lib;
|
||||||
use std::process::Output;
|
// use std::process::Output;
|
||||||
|
|
||||||
// use crate::core::botinstance::ArcBox;
|
// use crate::core::botinstance::ArcBox;
|
||||||
use botLib::core::botinstance::ArcBox;
|
// use bot_lib::core::botinstance::ArcBox;
|
||||||
|
|
||||||
use botLib::core::botinstance::{self, BotInstance};
|
use bot_lib::core::botinstance::{self, BotInstance};
|
||||||
// use core::botinstance::{self,BotInstance};
|
// use core::botinstance::{self,BotInstance};
|
||||||
|
|
||||||
use casual_logger::Extension;
|
use casual_logger::Extension;
|
||||||
|
@ -33,10 +33,11 @@ pub async fn main() {
|
||||||
let a = a.read().await;
|
let a = a.read().await;
|
||||||
// let a = *a;
|
// let a = *a;
|
||||||
|
|
||||||
for (_, acts) in &*a {
|
// for (_, acts) in &*a {
|
||||||
|
for acts in (*a).values() {
|
||||||
for act in acts {
|
for act in acts {
|
||||||
match act {
|
match act {
|
||||||
botLib::core::botmodules::BotAction::C(b) => {
|
bot_lib::core::botmodules::BotAction::C(b) => {
|
||||||
// println!("bot actiions: {}",b.command)
|
// println!("bot actiions: {}",b.command)
|
||||||
// Log::info(&format!("bot actions: {}",b.command));
|
// Log::info(&format!("bot actions: {}",b.command));
|
||||||
botinstance::botlog::info(
|
botinstance::botlog::info(
|
||||||
|
@ -45,7 +46,7 @@ pub async fn main() {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
botLib::core::botmodules::BotAction::L(l) => {
|
bot_lib::core::botmodules::BotAction::L(l) => {
|
||||||
// println!("bot actiions: {}",l.name)
|
// println!("bot actiions: {}",l.name)
|
||||||
// Log::info(&format!("bot actions: {}",l.name));
|
// Log::info(&format!("bot actions: {}",l.name));
|
||||||
botinstance::botlog::info(
|
botinstance::botlog::info(
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub use crate::core::botmodules::ModulesManager;
|
||||||
|
|
||||||
// use crate::core::botinstance;
|
// use crate::core::botinstance;
|
||||||
pub use crate::core::botinstance::BotInstance;
|
pub use crate::core::botinstance::BotInstance;
|
||||||
use futures::lock::Mutex;
|
// use futures::lock::Mutex;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
// [ ] Load submodules
|
// [ ] Load submodules
|
||||||
|
|
|
@ -11,22 +11,23 @@
|
||||||
// mod crate::modules;
|
// mod crate::modules;
|
||||||
//use crate::modules;
|
//use crate::modules;
|
||||||
|
|
||||||
use std::future::Future;
|
// use std::future::Future;
|
||||||
|
|
||||||
use crate::core::botmodules::bot_actions::actions_util::{self, BotAR};
|
use crate::core::botmodules::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::botinstance::{self, BotInstance, ChType};
|
// use crate::core::botinstance::{self, BotInstance, ChType};
|
||||||
use futures::lock::Mutex;
|
use crate::core::botinstance;
|
||||||
|
// use futures::lock::Mutex;
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
use crate::core::identity;
|
use crate::core::identity;
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use std::rc::Rc;
|
// use std::rc::Rc;
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::Arc;
|
||||||
|
|
||||||
// pub fn init(mgr:&mut ModulesManager)
|
// pub fn init(mgr:&mut ModulesManager)
|
||||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
|
@ -63,7 +64,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn good_girl(mut bot: BotAR, msg: PrivmsgMessage) {
|
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
// println!("In GoodGirl() Listener");
|
// println!("In GoodGirl() Listener");
|
||||||
// Change below from debug to trace if required later
|
// Change below from debug to trace if required later
|
||||||
botinstance::botlog::debug(
|
botinstance::botlog::debug(
|
||||||
|
|
Loading…
Reference in a new issue