enh chat.say_in_reply
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
ModulatingForce 2024-04-03 13:47:59 -04:00
parent 57725ee840
commit 345cf97922

View file

@ -4,7 +4,7 @@ use std::sync::Arc;
use tokio::sync::Mutex;
use twitch_irc::login::StaticLoginCredentials;
use twitch_irc::message::PrivmsgMessage;
use twitch_irc::message::{PrivmsgMessage, ReplyToMessage};
use twitch_irc::transport::tcp::{TCPTransport, TLS};
use twitch_irc::TwitchIRCClient;
@ -34,9 +34,14 @@ pub struct Chat {
}
#[derive(Clone,Debug)]
pub enum BotMsgType<'a> {
SayInReplyTo(&'a PrivmsgMessage,String),
// #[derive(Clone,Debug)] // <-- [ ] 04.03 - was having issues using this
#[derive(Clone)]
// pub enum BotMsgType<'a> {
pub enum BotMsgType {
// SayInReplyTo(&'a PrivmsgMessage,String),
// SayInReplyTo(Arc<Box<dyn ReplyToMessage>>,String),
// SayInReplyTo(&'a dyn ReplyToMessage,String), // [ ] 04.03 - Having issues defining it this way?
SayInReplyTo((String,String),String), // ( Destination Channel , Message ID to reply to ) , OutMessage // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to
Say(String,String),
Notif(String), // For Bot Sent Notifications
}
@ -59,7 +64,8 @@ impl Chat {
}
#[async_recursion]
pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) {
// pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) {
pub async fn send_botmsg(&self, msginput: BotMsgType, params : ExecBodyParams) {
@ -72,17 +78,21 @@ impl Chat {
*/
botlog::trace(
/* // [ ] 04.03 - Was having issues withh this
botlog::trace(
format!("send_bot_msg params : {:?}",msginput).as_str(),
Some("chat.rs > send_botmsg ".to_string()),
Some(&params.msg),
);
Log::flush();
*/
let (channel_login,mut outmsg) = match msginput.clone() {
BotMsgType::SayInReplyTo(msg, outmsg) => {
(msg.channel_login.clone(),outmsg)
// (msg.channel_login.clone(),outmsg)
// (msg.clone().channel_login().to_string(),outmsg)
(msg.0, // Desintation Channel
outmsg)
},
BotMsgType::Say(a,b ) => {
(a.clone(),b.clone())
@ -340,7 +350,12 @@ impl Chat {
match msginput.clone() {
BotMsgType::SayInReplyTo(msg, _) => {
self.client.say_in_reply_to(msg, outmsg).await.unwrap();
dbg!(msg.clone().channel_login(),msg.message_id(),outmsg.clone());
self.client.say_in_reply_to(&(
msg.clone().channel_login().to_string(),
msg.message_id().to_string()),
outmsg).await.unwrap();
},
BotMsgType::Say(a, _) => {
self.client.say(a, outmsg).await.unwrap();
@ -357,11 +372,12 @@ impl Chat {
channel_login.clone(), "rate limit counter increase", contextratelimiter
);
if let BotMsgType::SayInReplyTo(msg,_ ) = msginput {
if let BotMsgType::SayInReplyTo(_,_ ) = msginput {
botlog::trace(
logstr.as_str(),
Some("Chat > send_botmsg".to_string()),
Some(msg),
// Some(msg),
None,
);
} else {
botlog::trace(
@ -390,7 +406,9 @@ impl Chat {
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
// #[async_recursion]
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
pub async fn say_in_reply_to(&self, msg: &impl ReplyToMessage, outmsg: String , params : ExecBodyParams) {
// let params_clone = params.clone();
@ -443,7 +461,10 @@ impl Chat {
// Log::flush();
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await;
self.send_botmsg(BotMsgType::SayInReplyTo(
(msg.channel_login().to_string(),
msg.message_id().to_string()),
outmsg) , params).await;
}