From ff6046bb1f7f0ae11c072fe389ff5b5a3d5dc37b Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:04:57 -0400 Subject: [PATCH] botcommands recognized in replies --- src/core/botinstance.rs | 95 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 5 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index a668dac..8d76956 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -171,6 +171,7 @@ impl BotInstance { ); } ServerMessage::Privmsg(msg) => { + botlog::debug( format!( "[Twitch Chat > {}] > {}: {}", @@ -181,6 +182,17 @@ impl BotInstance { Some(&msg), ); + + botlog::trace( + format!( + "[TRACE][Twitch Chat > {}] > {}: {:?}", + msg.channel_login, msg.sender.name, msg + ) + .as_str(), + Some("BotInstance > runner()".to_string()), + Some(&msg), + ); + BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await; } ServerMessage::Whisper(msg) => { @@ -243,6 +255,59 @@ impl BotInstance { Some(msg), ); + + // /* + // [ ] Here, msg is taken, and message_text is split so we can pull the first argument + // */ + + // let inpt = msg + // .message_text + // .split(' ') + // .next() + // .expect("ERROR during BotCommand"); + + /* + [ ] What we should do instead is : + 1. Check if the message is related to a Reply (so we know how many arguments we should skip) + 2. If a reply, skip the first argument + */ + + let mut msgiter= msg + .message_text + .split(' '); + + let arg1 = msgiter.next(); + let arg2 = msgiter.next(); + + let reply = if let Some(replyidout) = msg.source.tags.0.get("reply-thread-parent-msg-id") { + if let Some(replyid) = replyidout { + // println!("Detected Reply : {}",replyid); + Some(replyid) + } else { None } + } else { None } + ; + + // let inpt = match reply { + // None => arg1, // Regular message, use the first arg as the command + // Some(_) => arg2, // A reply message, use the 2nd arg as the command + // }; + + + let inpt = match reply { + None => { // Regular message, use the first arg as the command + match arg1 { + None => return, // return if no argument found + Some(a) => a, + } + }, + Some(_) => { + match arg2 { // A reply message, use the 2nd arg as the command + None => return, // return if no argument found + Some(a) => a, + } + }, + }; + for acts in (*actsdblock).values() { for a in acts { match a { @@ -263,11 +328,31 @@ impl BotInstance { Some(msg), ); - let inpt = msg - .message_text - .split(' ') - .next() - .expect("ERROR during BotCommand"); + + // /* + // [ ] Here, msg is taken, and message_text is split so we can pull the first argument + // */ + + // let inpt = msg + // .message_text + // .split(' ') + // .next() + // .expect("ERROR during BotCommand"); + + // /* + // [ ] What we should do instead is : + // 1. Check if the message is related to a Reply (so we know how many arguments we should skip) + // 2. If a reply, skip the first argument + // */ + + // if let Some(rslt) = msg.source.tags.0.get("reply-thread-parent-msg-id") { + // if let Some(rslt) = rslt { + // println!("Detected Reply : {}",rslt); + // } + // } + + + // [x] Check if a bot command based on ... // [x] prefix + command