-
Notifications
You must be signed in to change notification settings - Fork 32
Twitch chat interactivity! #30
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
Open
dansanderson
wants to merge
18
commits into
thisisparker:main
Choose a base branch
from
dansanderson:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tion of a !clue command
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a major new feature set for Cursewords: Twitch chat interactivity! Cursewords can connect to a Twitch channel's chat room and react to messages posted by viewers. Features include:
!clue
command, like so:!clue 22d
This introduces a new configuration system for storing Twitch credentials and settings. It can use a configuration file in the TOML format, located in either the current working directory or in
$HOME/.config/
. Settings can be set or overridden on the command line as well. This system is flexible enough to use for future features.See README.md for usage instructions.
Technical notes
This version uses twitchapps.com/tmi/ "OAuth tokens" for authentication. OIDC implicit code flow might be more user friendly (I think that's the one where you can open a browser and just sign in with the bot account?) but this works well enough if you're willing to copy-paste the token into config. I include instructions in the README.
The Twitch client runs in its own thread to avoid impeding the solving UI. It accesses Grid without explicit thread safety support, so I don't know if that'll be an issue. I considered a
queue.Queue
but so far this seems to work as is.websockets
usesasyncio
coroutines. The coroutine event loop runs in the Twitch child thread. On exit, the main thread joins the Twitch thread so it can clean up. The Twitch thread also keeps track of who made correct guesses to print in an on-screen thank you message when quitting.I could have used TwitchIO, an
asyncio
-based library with much of the chat bot functionality intwitch.py
. I decided to try it with raw websockets because I thought I'd be able to figure out "whisper" support that TwitchIO v1 doesn't yet have. I concluded that whisper support requires "verified" bot status and decided to punt for now.I wanted whisper support so that clue requests could be private and not spam the chat. With clues going to the public chat, I added a cooldown mechanism so a given user can only ask for a clue every so many seconds (configurable). I'm sure CursewordsLive attendees will be well behaved and this is probably overkill.
Outgoing messages use a delayed queue of one message per second to avoid tripping Twitch's rate limit for (unverified?) bots.
I left in some logging support that was useful for troubleshooting Twitch behaviors without cluttering the display. As submitted, it's disabled by default via config, and only logs IRC "NOTICE" messages. It could be used for other things.
I tried to keep intrusions on the main branch minimal:
websockets
andpytest
are the only new dependencies, and pytest is just for development.cursewords.py
still contains Grid and the main loop. It's probably time to spilt things out into more files and helper functions, but I didn't want to introduce refactoring alongside new features.autopep8
.