Retrieve Reply information from ExecBodyParams #52

Merged
modulatingforce merged 11 commits from retrieve-reply-details into main 2024-04-03 19:51:04 -04:00

Initial Description

Stemming from #48 (comment)

Custom Developers should be able to retrieve reply details from a message, rather than custom build out the logic

The logic already exists here , observed in an experimental module

https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/custom/experimental/experiment002.rs#L72-L75

    let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") {
            Some(reply)
        } else { None }
    ;

Better would be something where the Custom Developer doesn't have to build out the above logic - they can just call a function related to command

Probably would have these methods defined at ExecBodyParams object

Plan of Action :

  • Implementation of ExecBodyParams method get_parent_reply(&self) -> Option<ReplyParent>
  • Smol enh to Chat so it can take in impl ReplyToMessage
  • User Tests > WIP
  • Unit test?
  • Clippy / fmt / comments cleanup
# Initial Description Stemming from https://git.flake.sh/modulatingforce/forcebot_rs/pulls/48#issuecomment-921 Custom Developers should be able to retrieve reply details from a message, rather than custom build out the logic The logic already exists here , observed in an experimental module https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/custom/experimental/experiment002.rs#L72-L75 ```rust let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") { Some(reply) } else { None } ; ``` Better would be something where the Custom Developer doesn't have to build out the above logic - they can just call a function related to command Probably would have these methods defined at `ExecBodyParams` object # Plan of Action : - [x] Implementation of `ExecBodyParams` method `get_parent_reply(&self) -> Option<ReplyParent>` - [x] Smol enh to `Chat` so it can take in `impl ReplyToMessage` - [x] User Tests > WIP - [x] Unit test? - [x] Clippy / fmt / comments cleanup
modulatingforce added this to the Prototype 1.0 milestone 2024-03-29 11:01:45 -04:00
modulatingforce added this to the Forcebot Prototype 1.0 Push project 2024-03-29 11:01:45 -04:00
modulatingforce added a new dependency 2024-03-29 11:09:00 -04:00
mzntori added 1 commit 2024-03-29 20:42:29 -04:00
add reply parent functionality
Some checks failed
ci/woodpecker/pr/cargo-checks Pipeline failed
f2893791b9
Collaborator

Does this work how you wanted it?

Does this work how you wanted it?
mzntori added 1 commit 2024-03-29 20:47:44 -04:00
oops forgot to add the use statement
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
a048003e93
modulatingforce reviewed 2024-03-30 17:07:05 -04:00
modulatingforce left a comment
Author
Owner

@mzntori yuppo! fking beautiful . Thanks for the work!

@HaruYuumei - can you review this and see if this would work for you for your PR #48 ? I've decided to push this into main branch first as this would benefit active branches

Also, feel free to use this branch to add in some tests Haru - like if you want to create a module that tests this or look at existing test ones, and just add to them

Example Use Case in a custom fn could be something like this pseudocode

fn good_girl(params : ExecBodyParams) {

   match Some(parent_reply) = params.get_parent_reply() {
      println!("{}",parent_reply.sender.name)
   }
}
@mzntori yuppo! fking beautiful . Thanks for the work! @HaruYuumei - **can you review this and see if this would work for you for your PR https://git.flake.sh/modulatingforce/forcebot_rs/pulls/48 ?** I've decided to push this into `main` branch first as this would benefit active branches Also, feel free to use this branch to add in some tests Haru - like if you want to create a module that tests this or look at existing test ones, and just add to them Example Use Case in a custom `fn` could be _something_ like this _pseudocode_ ```rust fn good_girl(params : ExecBodyParams) { match Some(parent_reply) = params.get_parent_reply() { println!("{}",parent_reply.sender.name) } }
@ -60,0 +61,4 @@
///
/// If that message replied to message return that information in form of `Some<ReplyParent>`.
/// Otherwise, return `None`.
pub fn get_parent_reply(&self) -> Option<ReplyParent> {
Author
Owner

ExecBodyParams
New Method - pub fn get_parent_reply(&self) -> Option<ReplyParent>

`ExecBodyParams` New Method - `pub fn get_parent_reply(&self) -> Option<ReplyParent>`
@ -63,0 +116,4 @@
pub message_text: String,
pub channel_login: String,
pub channel_id: String,
}
Author
Owner

ExecBodyParams
New Struct - pub struct ReplyParent

`ExecBodyParams` New Struct - `pub struct ReplyParent`
HaruYuumei was assigned by modulatingforce 2024-03-30 17:08:27 -04:00
modulatingforce self-assigned this 2024-03-30 17:08:27 -04:00
mzntori was assigned by modulatingforce 2024-03-30 17:08:28 -04:00
modulatingforce added the
Status
Need More Info
label 2024-03-31 09:12:04 -04:00
modulatingforce added the
Ownership
Collab
label 2024-03-31 09:45:33 -04:00
Author
Owner

Just to Update :

So far, what tori put in place works.

However, there is an additional desired enhancement so that the bot replies to the original message rather than the message of the BotCommand

At the moment, when the bot replies some initial tests from Haru, it replies to the BotCommand Message rather than the what the BotCommand was in reply to

This can definitely be done with twitch-irc and the code from this PR , but better may be to just go ahead and enhance Chat.say_in_reply_to() so it can be passed anything that implements ReplyToMessage similar to underlying Client.say_in_reply_to()

https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to

Likely starting in this call onwards

https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/core/chat.rs#L393

Not extremely difficult to do but I need to double check that this doesn't impact anything business logic related in the downstream


Plan of Action

  • Will be enhancing Chat.say_in_reply_to() to handle impl ReplyToMessage > @modulatingforce - WIP
  • Afterwards, Haru to test
Just to Update : So far, what tori put in place works. However, there is an additional desired enhancement so that the bot replies to the original message rather than the message of the `BotCommand` At the moment, when the bot replies some initial tests from Haru, it replies to the `BotCommand` Message rather than the what the `BotCommand` was in reply to This can definitely be done with `twitch-irc` and the code from this PR , but better may be to just go ahead and enhance `Chat.say_in_reply_to()` so it can be passed anything that implements `ReplyToMessage` similar to underlying `Client.say_in_reply_to()` https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to Likely starting in this call onwards https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/core/chat.rs#L393 Not extremely difficult to do but I need to double check that this doesn't impact anything business logic related in the downstream --- **Plan of Action** - [x] Will be enhancing `Chat.say_in_reply_to()` to handle `impl ReplyToMessage` > @modulatingforce - WIP - [x] Afterwards, Haru to test
modulatingforce added 4 commits 2024-04-03 13:48:30 -04:00
modulatingforce reviewed 2024-04-03 14:01:05 -04:00
modulatingforce left a comment
Author
Owner

Hi @HaruYuumei Feel free to test with the changes I've added. You can pass a tuple : (Destination Channel , Message ID to Reply to) in say_in_reply_to()

Something like

chat.say_in_reply_to(("testchannel","5555",params);

Feel free to test and create a test listener or button that tests it out


Hi @mzntori can you check my notes? It's not super important but just curious if you could create a simpler version or not

Thanks!

Hi @HaruYuumei Feel free to test with the changes I've added. You can pass a tuple : (Destination Channel , Message ID to Reply to) in `say_in_reply_to()` Something like ```rust chat.say_in_reply_to(("testchannel","5555",params); ``` Feel free to test and create a test listener or button that tests it out --- Hi @mzntori can you check my notes? It's not super important but just curious if you could create a simpler version or not Thanks!
src/core/chat.rs Outdated
@ -40,0 +41,4 @@
// 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
Author
Owner

@mzntori can you check this? I want to store in this BotMsgType::SayInReplyTo a ReplyToMessage (or a impl ReplyToMessage like the function in https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to

But I keep either getting stuff about it not bounded correctly or it starts getting a bit dank ( I need to define Arc/Boxes, and I'm not sure if that'll be intuitive for custom developers, if that's required to be built by a custom developer )

My Compromise is pass the tuple version (String,String) in the downstream - but if twitch-irc changes impl ReplyToMessage , we would need to change these areas . (though this is likely not an issue if this doesn't happen often)

What do you think?

@mzntori can you check this? I want to store in this `BotMsgType::SayInReplyTo` a `ReplyToMessage` (or a `impl ReplyToMessage` like the function in https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to But I keep either getting stuff about it not bounded correctly or it starts getting a bit dank ( I need to define Arc/Boxes, and I'm not sure if that'll be intuitive for custom developers, if that's required to be built by a custom developer ) My Compromise is pass the tuple version `(String,String)` in the downstream - but if `twitch-irc` changes `impl ReplyToMessage` , we would need to change these areas . (though this is likely not an issue if this doesn't happen often) What do you think?
src/core/chat.rs Outdated
@ -393,1 +409,3 @@
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) {
Author
Owner

Chat.say_in_reply_to() now take msg as &impl ReplyToMessage

Similar to the underlying in the following : https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to

As the above documentation explains, for ReplyToMessage we can pass the following

  • a &PrivmsgMessage
  • a tuple (&str, &str) or (String, String), where the first member is the login name of the channel the message was sent to, and the second member is the ID of the message to reply to.
`Chat.say_in_reply_to()` now take msg as `&impl ReplyToMessage` Similar to the underlying in the following : https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to As the above documentation explains, for `ReplyToMessage` we can pass the following - a `&PrivmsgMessage` - a tuple `(&str, &str)` or `(String, String)`, where the first member is the login name of the channel the message was sent to, and the second member is the ID of the message to reply to.
HaruYuumei added 1 commit 2024-04-03 14:26:22 -04:00
reply-to-parent working
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
7199703766
Collaborator

Everything should be working as intended now, by being able to use the tuple in say_reply_to() I could pass the parent message id and the channel id in wich the message was sent to locate the parent message and reply directly to it 😄

Everything should be working as intended now, by being able to use the tuple in say_reply_to() I could pass the parent message id and the channel id in wich the message was sent to locate the parent message and reply directly to it 😄
Collaborator

SayInReplyTo((S, S), S) is very unintuitive, either remove the tuple or make it something like SayInReplyTo{channel: S, message_id: S, message: S}.
As for the method params for say_in_reply_to i dont think you need to pass something complicated like a ReplyToMessage but just channel login and message id seperately. I think that would work fine for the API and users can find their own way to do that.

`SayInReplyTo((S, S), S)` is very unintuitive, either remove the tuple or make it something like `SayInReplyTo{channel: S, message_id: S, message: S}`. As for the method params for `say_in_reply_to` i dont think you need to pass something complicated like a ReplyToMessage but just channel login and message id seperately. I think that would work fine for the API and users can find their own way to do that.
modulatingforce added 1 commit 2024-04-03 18:33:26 -04:00
adj sayinreply to use channel & msgid
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
6867cc7af8
modulatingforce reviewed 2024-04-03 18:36:56 -04:00
modulatingforce left a comment
Author
Owner

@HaruYuumei how does this look? This is an example of how it looks without the tuple

@HaruYuumei how does this look? This is an example of how it looks without the tuple
@ -199,3 +261,4 @@
params.clone().msg.message_id().to_string(),
String::from("16:13 notohh: baby girl"),
params.clone()
).await;
Author
Owner

New Usage of say_in_reply()

    .say_in_reply_to(
        Channel(params.clone().msg.channel_login().to_string()),
        params.clone().msg.message_id().to_string(), 
        String::from("16:13 notohh: baby girl"),
        params.clone()
    ).await;
New Usage of `say_in_reply()` ```rust .say_in_reply_to( Channel(params.clone().msg.channel_login().to_string()), params.clone().msg.message_id().to_string(), String::from("16:13 notohh: baby girl"), params.clone() ).await; ```
Author
Owner
  • Another requested Enhancement . Have 2x fn in chat

  • sayinreply <-- this doesn't require a msgid . It will respond to the msgid passed in params automatically

  • sayinreplyto <-- we pass a msgid to reply to

- [x] Another requested Enhancement . Have 2x fn in chat - sayinreply <-- this doesn't require a msgid . It will respond to the msgid passed in params automatically - sayinreplyto <-- we pass a msgid to reply to
modulatingforce added 3 commits 2024-04-03 19:45:28 -04:00
clippy cleanup
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
fde96ac895
Author
Owner

Looking good - approving the merge

Looking good - approving the merge
modulatingforce changed title from WIP: Retrieve Reply information from `ExecBodyParams` to Retrieve Reply information from `ExecBodyParams` 2024-04-03 19:50:23 -04:00
modulatingforce merged commit e67c8582c1 into main 2024-04-03 19:51:04 -04:00
modulatingforce added the
Phase 5.0
Resolution > Completed
label 2024-04-03 20:43:51 -04:00
Sign in to join this conversation.
No reviewers
No milestone
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#48 Custom `this` BotCommand
modulatingforce/forcebot_rs
Reference: modulatingforce/forcebot_rs#52
No description provided.