2024.01.27 - init add back generics

This commit is contained in:
ModulatingForce 2024-01-27 21:40:08 -05:00
commit b9ea781ed8
5 changed files with 109 additions and 70 deletions

View file

@ -145,9 +145,10 @@ impl Chat {
pub struct BotInstance
// where
// F: std::future::Future + ?Sized,
pub struct BotInstance<F>
where
// F: std::future::Future + ?Sized,
F: std::future::Future
{
prefix : char,
bot_channel : ChType,
@ -156,7 +157,7 @@ pub struct BotInstance
// pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
pub chat : Chat,
// botmodules : HashMap<ModType,Vec<EnType>>,
pub botmodules : ModulesManager,
pub botmodules : ModulesManager<F>,
twitch_oauth : String,
pub bot_channels : Vec<ChType>,
/*bot_commands : Vec[BotCommand],
@ -168,16 +169,16 @@ pub struct BotInstance
impl BotInstance
// where
// F: std::future::Future + 'static,
// //F: 'static,
impl<F> BotInstance<F>
where
F: std::future::Future + 'static,
//F: 'static,
{
pub fn init() -> BotInstance
// where
// F: std::future::Future + 'static,
pub fn init() -> BotInstance<F>
where
F: std::future::Future + 'static,
{
dotenv().ok();
@ -297,51 +298,51 @@ impl BotInstance
pub async fn run(mut self) -> () {
// pub async fn run(mut self) -> () {
let join_handle = tokio::spawn(async move {
// let join_handle = tokio::spawn(async move {
while let Some(message) = self.incoming_messages.recv().await {
// Below can be used to debug if I want to capture all messages
// println!("Received message: {:?}", message);
// while let Some(message) = self.incoming_messages.recv().await {
// // Below can be used to debug if I want to capture all messages
// // println!("Received message: {:?}", message);
match message {
ServerMessage::Notice(msg) => {
if let Some(chnl) = msg.channel_login {
println!("NOTICE : (#{}) {}", chnl, msg.message_text);
}
}
ServerMessage::Privmsg(msg) => {
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// match message {
// ServerMessage::Notice(msg) => {
// if let Some(chnl) = msg.channel_login {
// println!("NOTICE : (#{}) {}", chnl, msg.message_text);
// }
// }
// ServerMessage::Privmsg(msg) => {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
println!("Privmsg section");
// println!("Privmsg section");
// b.listener_main_prvmsg(&msg);
self.listener_main_prvmsg(&msg).await;
// - BotCommand listener should likely need to be called within the above
// // b.listener_main_prvmsg(&msg);
// self.listener_main_prvmsg(&msg).await;
// // - BotCommand listener should likely need to be called within the above
},
ServerMessage::Whisper(msg) => {
println!("(w) {}: {}", msg.sender.name, msg.message_text);
},
ServerMessage::Join(msg) => {
println!("JOINED: {}", msg.channel_login);
},
ServerMessage::Part(msg) => {
println!("PARTED: {}", msg.channel_login);
},
_ => {}
}
}
});
// },
// ServerMessage::Whisper(msg) => {
// println!("(w) {}: {}", msg.sender.name, msg.message_text);
// },
// ServerMessage::Join(msg) => {
// println!("JOINED: {}", msg.channel_login);
// },
// ServerMessage::Part(msg) => {
// println!("PARTED: {}", msg.channel_login);
// },
// _ => {}
// }
// }
// });
join_handle.await.unwrap();
}
// join_handle.await.unwrap();
// }
// -----------------