clippy adj
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
ModulatingForce 2024-03-22 20:18:02 -04:00
parent 4b0d51a674
commit 06e182df55

View file

@ -44,6 +44,8 @@ use crate::core::bot_actions;
pub use ChType::Channel; pub use ChType::Channel;
pub use ModType::BotModule; pub use ModType::BotModule;
use std::hash::{Hash, Hasher};
use super::identity::ChatBadge; use super::identity::ChatBadge;
// use super::identity::ChangeResult; // use super::identity::ChangeResult;
@ -162,7 +164,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 }; let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 };
// if no trg_module was passed // if no trg_module was passed
if let None = trg_module { // if let None = trg_module {
if trg_module.is_none() {
let botlock = bot.read().await; let botlock = bot.read().await;
@ -190,8 +193,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let currchnl = msg.channel_login.to_lowercase(); let currchnl = msg.channel_login.to_lowercase();
let trg_level = let trg_level =
if arg1 == Some("-i") { StatusLvl::Instance } if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
else if arg1 == Some("-f") { StatusLvl::Instance } // else if arg1 == Some("-f") { StatusLvl::Instance }
else { StatusLvl::Ch(ChType::Channel(currchnl)) } else { StatusLvl::Ch(ChType::Channel(currchnl)) }
; ;
@ -338,7 +341,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 }; let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 };
// if no trg_module was passed // if no trg_module was passed
if let None = trg_module { // if let None = trg_module {
if trg_module.is_none() {
let botlock = bot.read().await; let botlock = bot.read().await;
@ -367,8 +371,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let currchnl = msg.channel_login.to_lowercase(); let currchnl = msg.channel_login.to_lowercase();
let trg_level = let trg_level =
if arg1 == Some("-i") { StatusLvl::Instance } if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
else if arg1 == Some("-f") { StatusLvl::Instance } // else if arg1 == Some("-f") { StatusLvl::Instance }
else { StatusLvl::Ch(ChType::Channel(currchnl)) } else { StatusLvl::Ch(ChType::Channel(currchnl)) }
; ;
@ -416,7 +420,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// #[derive(Debug, PartialEq, Eq, Hash, Clone)] // #[derive(Debug, PartialEq, Eq, Hash, Clone)]
#[derive(Debug, Hash, Clone)] // #[derive(Debug, Hash, Clone)]
#[derive(Debug, Clone)]
pub enum ModType { pub enum ModType {
BotModule(String), BotModule(String),
} }
@ -430,6 +435,15 @@ impl PartialEq for ModType {
} }
impl Eq for ModType {} impl Eq for ModType {}
impl Hash for ModType{
fn hash<H: Hasher>(&self, state: &mut H) {
// self.id.hash(state);
// self.phone.hash(state);
let BotModule(name) = self.clone();
name.to_lowercase().hash(state);
}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum ModGroup { pub enum ModGroup {
@ -561,10 +575,13 @@ impl BotActionTrait for Listener {
#[derive(Debug)] #[derive(Debug)]
pub struct Routine {} pub struct Routine {}
type StatusdbEntry = (ModGroup, Vec<StatusType>);
pub struct ModulesManager { pub struct ModulesManager {
// statusdb: Arc<RwLock<HashMap<ModType, Vec<ModStatusType>>>>, // statusdb: Arc<RwLock<HashMap<ModType, Vec<ModStatusType>>>>,
// statusdb: Arc<RwLock<HashMap<(ModType,ModGroup), Vec<StatusType>>>>, // statusdb: Arc<RwLock<HashMap<(ModType,ModGroup), Vec<StatusType>>>>,
statusdb: Arc<RwLock<HashMap<ModType, (ModGroup, Vec<StatusType>)>>>, // statusdb: Arc<RwLock<HashMap<ModType, (ModGroup, Vec<StatusType>)>>>,
statusdb: Arc<RwLock<HashMap<ModType, StatusdbEntry>>>,
pub botactions: Arc<RwLock<HashMap<ModType, Vec<BotAction>>>>, pub botactions: Arc<RwLock<HashMap<ModType, Vec<BotAction>>>>,
} }
@ -783,7 +800,8 @@ impl ModulesManager {
let modlist = self.moduleslist().await; let modlist = self.moduleslist().await;
let rslt = modlist.get(&trg_module); let rslt = modlist.get(&trg_module);
if let None = rslt { // if let None = rslt {
if rslt.is_none() {
return ChangeResult::Failed("Module doesn't exist".to_string()); return ChangeResult::Failed("Module doesn't exist".to_string());
} }
@ -1034,7 +1052,7 @@ impl ModulesManager {
let modlist = self.moduleslist().await; let modlist = self.moduleslist().await;
let rslt = modlist.get(&trg_module); let rslt = modlist.get(&trg_module);
if let None = rslt { if rslt.is_none() {
return ChangeResult::Failed("Module doesn't exist".to_string()); return ChangeResult::Failed("Module doesn't exist".to_string());
} }
@ -1245,9 +1263,12 @@ impl ModulesManager {
if (*x == StatusType::Enabled(StatusLvl::Instance)) if (*x == StatusType::Enabled(StatusLvl::Instance))
|| (*x == StatusType::Disabled(StatusLvl::Instance)) { || (*x == StatusType::Disabled(StatusLvl::Instance)) {
true true
} else if let StatusType::Enabled(StatusLvl::Ch(_)) = (*x).clone() { // } else if let StatusType::Enabled(StatusLvl::Ch(_)) = (*x).clone() {
true // true
} else {false} // } else {false}
} else {
matches!((*x).clone(), StatusType::Enabled(StatusLvl::Ch(_)))
}
) )
{ {
statusvector.remove(index); statusvector.remove(index);
@ -1903,10 +1924,10 @@ mod core_modulesmanager {
modsmgr.affirm_in_statusdb(in_module.clone(), in_modgroup.clone()).await; modsmgr.affirm_in_statusdb(in_module.clone(), in_modgroup.clone()).await;
let in_module = match current_test_scenario { // let in_module = match current_test_scenario {
// TestScenarios::ModuleDoesNotExist => BotModule("NonExisting_Module".to_string()), // // TestScenarios::ModuleDoesNotExist => BotModule("NonExisting_Module".to_string()),
_ => in_module, // _ => in_module,
}; // };
/* /*