problem scenario with some test modules

This commit is contained in:
ModulatingForce 2023-12-28 06:02:55 -05:00
commit 4184527d19
5 changed files with 296 additions and 160 deletions

View file

@ -145,7 +145,10 @@ impl Chat {
pub struct BotInstance {
pub struct BotInstance<F>
where
F: std::future::Future + ?Sized,
{
prefix : char,
bot_channel : ChType,
//pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
@ -153,7 +156,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],
@ -163,10 +166,18 @@ pub struct BotInstance {
// identity : identitymodule,
}
impl BotInstance {
pub fn init() -> BotInstance {
impl<F> BotInstance<F>
where
F: std::future::Future + 'static,
{
pub fn init() -> BotInstance<F>
where
F: std::future::Future + 'static,
{
dotenv().ok();
let login_name = env::var("login_name").unwrap().to_owned();
@ -237,6 +248,53 @@ impl BotInstance {
b
}
pub async fn runner(mut self) -> () {
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);
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");
// 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);
},
_ => {}
}
}
});
join_handle.await.unwrap();
}
pub async fn run(mut self) -> () {
@ -341,3 +399,21 @@ impl BotInstance {
// ======================================
// ======================================
// ======================================
// ======================================
// UNIT TEST MODULES
#[cfg(test)]
mod tests {
fn always() {
assert_eq!(1,1);
}
}