Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate clap command from lioranboard #4

Merged
merged 3 commits into from
Jan 5, 2021
Merged

Conversation

matanp
Copy link
Owner

@matanp matanp commented Jan 3, 2021

OBS Websocket protocol:
https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md

changes in obs_helper:
-added async function getScene, to factor it out, and not have code repeated. Looks through the OBS scene list and returns the scene data from the scene matching the scene_name parameter
-added showNewHeartEyes which has the new functionality. (see code comment for more info)
-added global variable current_scene and listen to OBS scene change event to keep updated
-deleted unused getScenes function
-minor style changes

Images to show the OBS setup. All 10 heart sources point to the same mp4 file. The point of having multiple is so the command can be used more than once every 4.5 seconds (length of the video). Can now handle 10 requests every 4.5 seconds, and more can be added in obs w/o changing the code.

image
image

changes in bot_main:
-if 'clap' is a part of a user message, call showNewHeartEyes from obs_helper

@matanp matanp requested a review from unfamiliarish2 January 3, 2021 00:28
@matanp
Copy link
Owner Author

matanp commented Jan 3, 2021

added a line to obs connect function to set global current_scene on connect, so we don't need to wait for first scene change to access the variable

@matanp
Copy link
Owner Author

matanp commented Jan 3, 2021

also a comment that searching for any message with clap somewhere in it is a design choice. noting because it differs from how it behaved in lioranboard where only the precise message !clap would work.

Copy link
Collaborator

@unfamiliarish2 unfamiliarish2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too lazy to dig into the obs code too much yet, but there you go

bot_brain.js Outdated
Comment on lines 64 to 66
if (user_command.search("clap") != -1) {
OBS.showNewHeartEyes();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this has the behavior of maybe hitting a bunch of commands if you did something like:
!discordclapformatanbot

if you wanna be real fancy in the future, you could:

  1. define a hashmap/dict that hashes the command string to the associated function that takes in the appropriate args
  2. parse the command into its string form (maybe space separated command plus args)
  3. after parsing the command, reduce a lot of the if-command-then checks to one try-catch that calls/returns the output from the hashmap

let me know if this is confusing and you want an example
mostly this doesn't matter too much, but would have the benefit of probably tightening up your code a bit, and defining all the commands in just one place (rather than woven a bit through your code)

note also that your user_command.search() functionality is different for lines 76-78

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For matanbot, discord and background, I want my bot to say something back to twitch, by returning out of message_main. For clap command, I just want it to do a thing in OBS silently. So !discordclapformatanbot would register clap and discord, not matanbot.

I like that idea a lot! The thing that has stopped me thus far from going down a route like that is I want slightly different behavior from different commands, and I don't have my head around implementing different things within the hashmap.

The current different behaviors being:

  1. search for a word within the whole message
  2. command that must be at the beginning
  3. search for a command, but don't return anything and continue looking for other valid commands

@matanp matanp merged commit b569c99 into main Jan 5, 2021
@matanp matanp deleted the clap_command_migration branch January 25, 2021 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants