bot_actions module
This commit is contained in:
parent
2d1349e255
commit
0a74406bb3
3 changed files with 32 additions and 39 deletions
|
@ -1,3 +1,4 @@
|
|||
pub mod bot_actions;
|
||||
pub mod botinstance;
|
||||
pub mod botlog;
|
||||
pub mod botmodules;
|
||||
|
|
27
src/core/bot_actions.rs
Normal file
27
src/core/bot_actions.rs
Normal file
|
@ -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<Mutex<BotInstance>>;
|
||||
pub type BotAR = Arc<RwLock<BotInstance>>;
|
||||
|
||||
pub type ExecBody = Box<
|
||||
dyn Fn(BotAR, PrivmsgMessage) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
|
||||
>;
|
||||
|
||||
pub fn asyncbox<T>(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody
|
||||
where
|
||||
T: Future<Output = ()> + Send + 'static,
|
||||
{
|
||||
Box::new(move |a, b| Box::pin(f(a, b)))
|
||||
}
|
||||
}
|
|
@ -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<Mutex<BotInstance>>;
|
||||
pub type BotAR = Arc<RwLock<BotInstance>>;
|
||||
|
||||
pub type ExecBody = Box<
|
||||
dyn Fn(BotAR, PrivmsgMessage) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
|
||||
>;
|
||||
|
||||
pub fn asyncbox<T>(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody
|
||||
where
|
||||
T: Future<Output = ()> + Send + 'static,
|
||||
{
|
||||
Box::new(move |a, b| Box::pin(f(a, b)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Listener {
|
||||
pub module: ModType,
|
||||
pub name: String,
|
||||
|
|
Loading…
Reference in a new issue