-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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 |
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. |
There was a problem hiding this 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
if (user_command.search("clap") != -1) { | ||
OBS.showNewHeartEyes(); | ||
} |
There was a problem hiding this comment.
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:
- define a hashmap/dict that hashes the command string to the associated function that takes in the appropriate args
- parse the command into its string form (maybe space separated command plus args)
- 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
There was a problem hiding this comment.
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:
- search for a word within the whole message
- command that must be at the beginning
- search for a command, but don't return anything and continue looking for other valid commands
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.
changes in bot_main:
-if 'clap' is a part of a user message, call showNewHeartEyes from obs_helper