Custom this BotCommand #48

Merged
modulatingforce merged 12 commits from say-this-guy into master 2024-04-09 15:49:58 -04:00

this would issue a fun notification back in the reply

For example :

  • "Got it! looking into their biometrics now HACKERMAN"
  • "SUS I see"
  • "Hmm"
  • "Reposting that to twitter rn"

In the future, maybe it could be enhanced to do other things or have additional enhanced logic

At Custom Module Level, use the Chat module functions mentioned here to say in reply to chat

#43 (comment)


Functional Use Case - Twitch Chatter

  1. As a Twitch Chatter, if I have any required roles of a given BotCommand, I can run that BotCommand
  2. I reply to a message in Chat with <botprefix>this . For example <botprefix>this fking guy ICANT
  3. The bot Responds to my message or the original message with a Fun Response

Code Difficulty

Low Difficulty and Relatively Small Code Change

However, delegating has it's advantages :

  1. Others will use this as a hands on Rust Learning Experience
  2. Hands on with Bot Code

Plan of Action :

  • Create a new Custom Module
    • Create a BotCommand called this
    • Create an Execution Body for the BotCommand . Logic should include checking if what was responded to was a reply
    • Use Chat module to Send messages to users or elsehwere #43
      • In this case, we're likely dealing with say_in_reply_to() so responds to the user
  • Unit Tests? Only if there's any advanced logic done so not required
`this` would issue a fun notification back in the reply For example : - "Got it! looking into their biometrics now HACKERMAN" - "SUS I see" - "Hmm" - "Reposting that to twitter rn" In the future, maybe it could be enhanced to do other things or have additional enhanced logic At Custom Module Level, use the `Chat` module functions mentioned here to say in reply to chat https://git.flake.sh/modulatingforce/forcebot_rs/pulls/43#issuecomment-730 --- # Functional Use Case - Twitch Chatter 1. As a Twitch Chatter, if I have any required roles of a given `BotCommand`, I can run that `BotCommand` 2. I reply to a message in Chat with `<botprefix>this` . For example `<botprefix>this fking guy ICANT` 3. The bot Responds to my message or the original message with a Fun Response --- # Code Difficulty Low Difficulty and Relatively Small Code Change However, delegating has it's advantages : 1. Others will use this as a hands on Rust Learning Experience 2. Hands on with Bot Code --- # Plan of Action : - [x] Create a new Custom Module - [x] Create a `BotCommand` called `this` - [x] Create an Execution Body for the `BotCommand` . Logic should include checking if what was responded to was a reply - [x] Use `Chat` module to Send messages to users or elsehwere https://git.flake.sh/modulatingforce/forcebot_rs/pulls/43 - In this case, we're likely dealing with `say_in_reply_to()` so responds to the user - [x] Unit Tests? Only if there's any advanced logic done so not required
modulatingforce added the
Kind/Enhancement
Bot_Code
Custom
labels 2024-03-27 17:47:12 -04:00
modulatingforce added the
Complexity
Basic
label 2024-03-27 18:21:24 -04:00
modulatingforce added the
Priority
Low
label 2024-03-27 18:24:26 -04:00
modulatingforce added this to the Rust Learning project 2024-03-27 18:24:41 -04:00
modulatingforce modified the project from Rust Learning to Forcebot Prototype 1.0 Push 2024-03-27 18:27:02 -04:00
modulatingforce added the
Phase 1.0
Requirements > Review & Planning
label 2024-03-27 19:58:39 -04:00
Author
Owner

Just in case if helpful

  1. When creating an fn execution body, ensure it's defined similar to the following , with just one argument : an ExecBodyParams
async fn foo(params : ExecBodyParams) 

Working Custom Module Example
https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/custom/experimental/experiment001.rs#L100

  1. Within the body itself, if you want to access parts of the members, simply call the argument. Example below is accessing msg from params
if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()

Working Custom Module Example
https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/custom/experimental/experiment001.rs#L106-L107

  1. The data that can be pulled from params are defined in the ExecBodyParams type
#[derive(Clone)]
pub struct ExecBodyParams {
    pub bot : BotAR,
    pub msg : PrivmsgMessage,
    pub parent_act : ActAR , 
}

Source Definition
https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/core/bot_actions.rs#L15-L19

Just in case if helpful 1. When creating an fn execution body, ensure it's defined similar to the following , with just one argument : an ExecBodyParams ``` async fn foo(params : ExecBodyParams) ``` Working Custom Module Example https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/custom/experimental/experiment001.rs#L100 2. Within the body itself, if you want to access parts of the members, simply call the argument. Example below is accessing msg from params ``` if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase() ``` Working Custom Module Example https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/custom/experimental/experiment001.rs#L106-L107 3. The data that can be pulled from params are defined in the ExecBodyParams type ```rust #[derive(Clone)] pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, pub parent_act : ActAR , } ``` Source Definition https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/main/src/core/bot_actions.rs#L15-L19
HaruYuumei added 1 commit 2024-03-28 14:39:20 -04:00
new module test
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
95a9962721
trying to add a new module
Author
Owner

I believe I got it to work on a local . Without pushing, see if these recommendations help. This will also help future documentation

LULE I could push what I have, but let's see if you could get it to work also . You pretty much had what you needed, just in the wrong places to load

Code Recommendation

  1. In custom.rs , add the following
mod thisguy
// ...
thisguy::init(mgr).await;

a. NOTE - if you have borrowing issues, you can clone() the Arc for one of the values earlier like so

experimental::init(mgr.clone()).await;
thisguy::init(mgr).await;
  1. Move the thisguy.rs file into the custom folder

  2. Remove the other stuff that was added before

  • modules.rs & modules folder

Additional Information

1. Core Implementation on Loading Modules

Note : This is not critical to know when creating custom modules are loaded

In Core , when the ModulesManager is first constructed, it calls the Fixed paths for custom.rs & core.rs (below)

https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/say-this-guy/src/core/botmodules.rs#L612-L617

So when defining new modules ensure they are references in either of those points - more than likely custom.rs

For example, below is loading the experimental module

https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/say-this-guy/src/custom.rs#L15

https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/say-this-guy/src/custom.rs#L24

2. Modules loaded are logged

Logs show just after the above process what has been loaded into the bot from commands from main. You'll see log entries similar to the following

["Now=2024-03-28T15:45:32-0400&Pid=20224&Thr=ThreadId(1)&Seq=31"]
Trace = 'Reading bot actions'
Channel = 'None'
Chatter = 'None'
Code_Module = 'Some("main()")'



["Now=2024-03-28T15:44:44-0400&Pid=18904&Thr=ThreadId(1)&Seq=32"]
Info = 'bot actions > Command : enable'
Channel = 'None'
Chatter = 'None'
Code_Module = 'Some("main()")'
I believe I got it to work on a local . Without pushing, see if these recommendations help. This will also help future documentation LULE I could push what I have, but let's see if you could get it to work also . You pretty much had what you needed, just in the wrong places to load # Code Recommendation 1. In `custom.rs` , add the following ``` mod thisguy // ... thisguy::init(mgr).await; ``` a. NOTE - if you have borrowing issues, you can clone() the Arc for one of the values earlier like so ``` experimental::init(mgr.clone()).await; thisguy::init(mgr).await; ``` 2. Move the `thisguy.rs` file into the custom folder 3. Remove the other stuff that was added before - modules.rs & modules folder --- # Additional Information ## 1. Core Implementation on Loading Modules _Note :_ This is not critical to know when creating custom modules are loaded ### In Core , when the ModulesManager is first constructed, it calls the Fixed paths for custom.rs & core.rs (below) https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/say-this-guy/src/core/botmodules.rs#L612-L617 ### So when defining new modules ensure they are references in either of those points - more than likely custom.rs For example, below is loading the experimental module https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/say-this-guy/src/custom.rs#L15 https://git.flake.sh/modulatingforce/forcebot_rs/src/branch/say-this-guy/src/custom.rs#L24 ## 2. Modules loaded are logged Logs show just after the above process what has been loaded into the bot from commands from main. You'll see log entries similar to the following ``` ["Now=2024-03-28T15:45:32-0400&Pid=20224&Thr=ThreadId(1)&Seq=31"] Trace = 'Reading bot actions' Channel = 'None' Chatter = 'None' Code_Module = 'Some("main()")' ["Now=2024-03-28T15:44:44-0400&Pid=18904&Thr=ThreadId(1)&Seq=32"] Info = 'bot actions > Command : enable' Channel = 'None' Chatter = 'None' Code_Module = 'Some("main()")' ```
HaruYuumei added 1 commit 2024-03-28 17:50:39 -04:00
custom module update
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
f8de595290
modulatingforce added 1 commit 2024-03-28 17:55:02 -04:00
Merge branch 'main' into say-this-guy
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
3ec51d66e5
HaruYuumei added 2 commits 2024-03-28 18:35:52 -04:00
HaruYuumei was assigned by modulatingforce 2024-03-28 19:20:53 -04:00
Author
Owner

This may be helpful :

  • In Main , I experimented with the following in a custom button sayout that checks for messages that are considered replies .

Below sample is taking the reply body

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 }
    ;

This may be helpful : - In Main , I experimented with the following in a custom button `sayout` that checks for messages that are considered replies . Below sample is taking the reply body 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 } ; ```
modulatingforce added a new dependency 2024-03-29 11:09:00 -04:00
modulatingforce added the
Status
Blocked
label 2024-03-29 11:09:41 -04:00
Author
Owner
  • PR for ExecParams reply feature will be introduced first - #52
- [x] PR for ExecParams reply feature will be introduced first - https://git.flake.sh/modulatingforce/forcebot_rs/pulls/52
modulatingforce self-assigned this 2024-03-30 16:59:46 -04:00
modulatingforce added the
Ownership
Collab with Leads
label 2024-03-31 09:52:59 -04:00
HaruYuumei added 2 commits 2024-04-02 19:11:51 -04:00
Thisguy working partially
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
d972eb7726
not fully implemented reply to the reply
HaruYuumei added 2 commits 2024-04-03 09:26:31 -04:00
Rewriten the code
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
b43d6f8159
working with command instead listener
Author
Owner

Hi @HaruYuumei

As discussed, #52 has been merged into master

To update the branch on this PR, please

  • Update Branch By Merge

** You can do this directly on this forge

Just FYI, doing this (from this Feature Branch, Update Branch by Merge), it will take the changes from Main/Master and add them onto this Feature Branch without changing either branch's commit history

The above is generally the most common way unless you're looking to reorganize / cleanup commit history . It generally also does not have issues

As a comparison, if you Update Branch by Rebase, you're changing the history of the feature branch by having all main/master branch be applied first before feature branch commits

For more information : https://www.atlassian.com/git/tutorials/merging-vs-rebasing


Generally, when Updating your feature set, I would say :

  1. Use the Update Branch by Merge Option

  2. If there are issues merging (e.g., merge conflict), we can address this afterwards, possibly by :

a. attempting the same merge locally (with Feature checked out, merge master into feature), and resolving the merge conflicts

OR

b. attempting to Update Branch by Rebase (try the forge first ; but if the forge also finds conflicts, try to do the rebase locally, and resolve the conflicts)


When there's a merge conflict, the source files will be in a state where you can pick which changes are in conflict by deleting the unwanted change between the two > and then stage & commit that resolving merge conflict as a normal commit

More information :

https://www.simplilearn.com/tutorials/git-tutorial/merge-conflicts-in-git

Hope that helps!

Hi @HaruYuumei As discussed, https://git.flake.sh/modulatingforce/forcebot_rs/pulls/52 has been merged into master **To update the branch on this PR, please** - Update Branch By Merge ** You can do this directly on this forge Just FYI, doing this (from this Feature Branch, Update Branch by Merge), it will take the changes from Main/Master and add them onto this Feature Branch without changing either branch's commit history The above is generally the most common way unless you're looking to reorganize / cleanup commit history . It generally also does not have issues As a comparison, if you Update Branch by Rebase, you're changing the history of the feature branch by having all main/master branch be applied first before feature branch commits For more information : https://www.atlassian.com/git/tutorials/merging-vs-rebasing --- Generally, when Updating your feature set, I would say : 1. Use the Update Branch by Merge Option 2. If there are issues merging (e.g., merge conflict), we can address this afterwards, possibly by : a. attempting the same merge locally (with Feature checked out, merge master into feature), and resolving the merge conflicts OR b. attempting to Update Branch by Rebase (try the forge first ; but if the forge also finds conflicts, try to do the rebase locally, and resolve the conflicts) --- When there's a merge conflict, the source files will be in a state where you can pick which changes are in conflict by deleting the unwanted change between the two > and then stage & commit that resolving merge conflict as a normal commit More information : https://www.simplilearn.com/tutorials/git-tutorial/merge-conflicts-in-git Hope that helps!
modulatingforce removed the
Status
Blocked
label 2024-04-03 20:40:52 -04:00
Author
Owner

Haru going to try the above at some point today

If there are issues, we'll troubleshoot those issues on this branch and use whatever we learn for merges needed for textmods

Haru going to try the above at some point today If there are issues, we'll troubleshoot those issues on this branch and use whatever we learn for merges needed for textmods
HaruYuumei added 1 commit 2024-04-09 14:45:30 -04:00
Merge branch 'master' into say-this-guy
Some checks failed
ci/woodpecker/pr/cargo-checks Pipeline failed
93768de4dc
modulatingforce reviewed 2024-04-09 15:02:35 -04:00
modulatingforce left a comment
Author
Owner

Hi @HaruYuumei

Could you try this locally? Pull this branch down - you should also get a compile error when cargo build . Afterwards, try the suggestion to make sure it builds

Afterwards, push up

Hi @HaruYuumei Could you try this locally? Pull this branch down - you should also get a compile error when `cargo build` . Afterwards, try the suggestion to make sure it builds Afterwards, push up
@ -0,0 +34,4 @@
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, a, params.clone())
Author
Owner

We're getting an error here in ci/cd

error[E0061]: this method takes 4 arguments but 3 arguments were supplied
   --> src\custom\thisguy.rs:37:10
    |
37  |         .say_in_reply_to(&params.msg, a, params.clone())
    |          ^^^^^^^^^^^^^^^ -----------     -------------- an argument of type `std::string::String` is missing
    |                          |
    |                          expected `Channel`, found `&PrivmsgMessage`
    |
note: method defined here
   --> src\core\chat.rs:415:18
    |
415 |     pub async fn say_in_reply_to(
    |                  ^^^^^^^^^^^^^^^
416 |         &self,
417 |         destination_channel : Channel ,
    |         -----------------------------
418 |         reply_message_id : String ,
    |         -------------------------
419 |         outmsg: String ,
    |         --------------
420 |         params : ExecBodyParams)
    |         -----------------------
help: provide the argument
    |
37  |         .say_in_reply_to(/* core::botinstance::Channel */, a, /* std::string::String */, params.clone())
    |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Recommend this be adjusted to

.say_in_reply_to(&params.msg.channel_login(), &params.msg.message_id(),a, params.clone())
We're getting an error here in ci/cd ``` error[E0061]: this method takes 4 arguments but 3 arguments were supplied --> src\custom\thisguy.rs:37:10 | 37 | .say_in_reply_to(&params.msg, a, params.clone()) | ^^^^^^^^^^^^^^^ ----------- -------------- an argument of type `std::string::String` is missing | | | expected `Channel`, found `&PrivmsgMessage` | note: method defined here --> src\core\chat.rs:415:18 | 415 | pub async fn say_in_reply_to( | ^^^^^^^^^^^^^^^ 416 | &self, 417 | destination_channel : Channel , | ----------------------------- 418 | reply_message_id : String , | ------------------------- 419 | outmsg: String , | -------------- 420 | params : ExecBodyParams) | ----------------------- help: provide the argument | 37 | .say_in_reply_to(/* core::botinstance::Channel */, a, /* std::string::String */, params.clone()) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` --- Recommend this be adjusted to ```rust .say_in_reply_to(&params.msg.channel_login(), &params.msg.message_id(),a, params.clone()) ```
modulatingforce marked this conversation as resolved
HaruYuumei added 1 commit 2024-04-09 15:22:30 -04:00
changed reply message on thisguy
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
55aeaa7fc1
modulatingforce reviewed 2024-04-09 15:40:06 -04:00
modulatingforce left a comment
Author
Owner

@HaruYuumei could you review and address the warnings first? Thank you!

@HaruYuumei could you review and address the warnings first? Thank you!
@ -0,0 +57,4 @@
Broadcaster
],
}
.add_to_modmgr(Arc::clone(&mgr))
Author
Owner

@HaruYuumei CI/CD is throwing a warning for this line

To improve our coding, CI/CD is set to a relatively strict level - the following:

cargo clippy --all-targets --all-features

Could you run that locally? Read through the errors that are returned - these lints usually have links to sites that help explain what might be best and why

Take your time on this though if required!

@HaruYuumei CI/CD is throwing a warning for this line To improve our coding, CI/CD is set to a relatively strict level - the following: ``` cargo clippy --all-targets --all-features ``` Could you run that locally? Read through the errors that are returned - these lints usually have links to sites that help explain what might be best and why Take your time on this though if required!
modulatingforce marked this conversation as resolved
HaruYuumei added 1 commit 2024-04-09 15:45:17 -04:00
warning changed
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
e41f7b0524
Collaborator

looks like it was a reference that was not actually needed should be alright now 😄

looks like it was a reference that was not actually needed should be alright now 😄
Author
Owner

CI/CD looks good

Approving

CI/CD looks good Approving
modulatingforce changed title from WIP: Custom this BotCommand to Custom this BotCommand 2024-04-09 15:48:51 -04:00
modulatingforce added
Phase 5.0
Resolution > Completed
and removed
Phase 2.0
Design > Research & Analysis
labels 2024-04-09 15:49:38 -04:00
modulatingforce merged commit e1021c269d into master 2024-04-09 15:49:58 -04:00
modulatingforce deleted branch say-this-guy 2024-04-09 15:49:58 -04:00
Sign in to join this conversation.
No reviewers
No milestone
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Depends on
Reference: modulatingforce/forcebot_rs#48
No description provided.