From 0a74406bb36ef5a66138c7a409c637af24b35505 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:41:24 -0500 Subject: [PATCH] bot_actions module --- src/core.rs | 1 + src/core/bot_actions.rs | 27 ++++++++++++++++++++++++++ src/core/botmodules.rs | 43 ++++------------------------------------- 3 files changed, 32 insertions(+), 39 deletions(-) create mode 100644 src/core/bot_actions.rs diff --git a/src/core.rs b/src/core.rs index 5e6c370..8917c5d 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,3 +1,4 @@ +pub mod bot_actions; pub mod botinstance; pub mod botlog; pub mod botmodules; diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs new file mode 100644 index 0000000..9e56e07 --- /dev/null +++ b/src/core/bot_actions.rs @@ -0,0 +1,27 @@ +pub mod actions_util { + + use std::boxed::Box; + use std::future::Future; + use std::pin::Pin; + use std::sync::Arc; + + use tokio::sync::{Mutex, RwLock}; + + use twitch_irc::message::PrivmsgMessage; + + use crate::core::botinstance::BotInstance; + + pub type BotAM = Arc>; + pub type BotAR = Arc>; + + pub type ExecBody = Box< + dyn Fn(BotAR, PrivmsgMessage) -> Pin + Send>> + Send + Sync, + >; + + pub fn asyncbox(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody + where + T: Future + Send + 'static, + { + Box::new(move |a, b| Box::pin(f(a, b))) + } +} diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index b7b27fd..b03d122 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -19,11 +19,10 @@ Example */ - use core::panic; -use std::error::Error; use std::collections::HashMap; +use std::error::Error; use std::sync::Arc; use twitch_irc::message::PrivmsgMessage; @@ -32,11 +31,12 @@ use tokio::sync::RwLock; use async_trait::async_trait; -use crate::core::botinstance::{BotInstance,ChType}; +use self::bot_actions::actions_util::BotAR; +use crate::core::botinstance::{BotInstance, ChType}; use crate::core::botlog; use crate::core::identity; -use self::bot_actions::actions_util::BotAR; +pub use crate::core::bot_actions; pub use ChType::Channel; pub use ModType::BotModule; @@ -107,41 +107,6 @@ impl BotActionTrait for BotCommand { } } -pub mod bot_actions { - - pub mod actions_util { - - use std::boxed::Box; - use std::future::Future; - use std::pin::Pin; - - // use std::rc::Rc; - - // use crate::core::botinstance::{BotInstance, BotManagers, Chat}; - use crate::core::botinstance::BotInstance; - // use std::cell::RefCell; - use std::sync::Arc; - use twitch_irc::message::PrivmsgMessage; - // use futures::lock::Mutex; - // Important to use tokios Mutex here since std Mutex doesn't work with async functions - use tokio::sync::{Mutex, RwLock}; - - pub type BotAM = Arc>; - pub type BotAR = Arc>; - - pub type ExecBody = Box< - dyn Fn(BotAR, PrivmsgMessage) -> Pin + Send>> + Send + Sync, - >; - - pub fn asyncbox(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody - where - T: Future + Send + 'static, - { - Box::new(move |a, b| Box::pin(f(a, b))) - } - } -} - pub struct Listener { pub module: ModType, pub name: String,