fix: harden Twitch bot socket handling and triggers (FR-470..474)#22
Merged
Merged
Conversation
- FR-474: connect over TLS (port 6697, ssl.create_default_context + wrap_socket) so the OAuth token sent via PASS is encrypted, not plaintext on 6667. - FR-470: set socket.settimeout(SOCKET_TIMEOUT) after connect so the existing `except socket.timeout` branch is live and a stalled connection can't hang the process indefinitely. - FR-471: buffer received bytes and split on the CRLF terminator, processing one complete IRC line at a time (mirrors the Wikimedia bot). A single recv() can hold several messages or a partial one; the old code treated the whole blob as one message. - FR-472: remove the "PING :tmi.twitch.tv" -> "lol" trigger. It was unreachable behind the PING early-return and would spam chat on every server ping if reached. - FR-473: add TwitchBot._word_in() whole-word helper and apply it to the five triggers named in the ticket (love, cake, portal, shiny, duck) so they no longer fire on substrings (glove, cupcake, portable, ...). Remaining substring triggers tracked in follow-up #49439. Verified: ruff check + format clean; existing pytest suite 22/22 pass; standalone checks of _word_in whole-word matching and the CRLF framing (concatenated, split-midline, partial-only).
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
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.
Batch fix for five verified
twitch.pybugs filed under the ClaudeCode project (Redmine #48945–#48949). All are in the Twitch bot's socket/IRC handling; each was checked against source before fixing.Fixes
#48949) — connect over TLS (port6697,ssl.create_default_context()+wrap_socket(..., server_hostname=SERVER)). The OAuth token, sent via the IRCPASScommand, was previously transmitted in plaintext over port 6667.#48945) — callsocket.settimeout(SOCKET_TIMEOUT)after connect, so the pre-existingexcept socket.timeout: continuebranch is actually reachable and a stalled/dead connection can't hang the process forever.#48946) — frame messages properly: accumulate received bytes in a buffer and split on the IRC\r\nterminator, processing one complete line at a time and keeping any trailing partial for the nextrecv(). Mirrors the async Wikimedia bot. Previously the wholerecv()blob was.strip()ed and treated as a single message, so concatenated or split messages were mishandled (this also silently fixes the mention regexes, which anchor on$).#48947) — remove the"PING :tmi.twitch.tv"→"lol"trigger. It was dead code behind the PING early-return, and would have spammed chat on every server ping if reached.#48948) — addTwitchBot._word_in()(regex\bword\b) and apply it to the five triggers the ticket names —love,cake,portal,shiny,duck— so they match whole words, not substrings (glove,cupcake,portable,abduction,shininess). The remaining bare-substring triggers are the same class but a couple involve a matching-strictness judgment (e.g.yayvsyayyy); tracked as follow-up #49439 for the owner to decide.Verification
ruff check+ruff format --check: cleanpytestsuite: 22/22 pass (covers the Wikimedia bot; unaffected)_word_inwhole-word matching (matches real words, rejectsglove/cupcake/portable/abduction/shininess), and CRLF framing across concatenated, split-mid-line, and partial-only chunks.Note:
BotConfig.SERVERremainsirc.twitch.tv(unchanged/out of scope) — only the port and transport changed.