Feature/eventsub definition generator - #137
Merged
Merged
Conversation
Adds TwitchEventsubDefinitionParser/Generator, mirroring the approach already used for the Eventsub payload classes: fetches and regex-parses the eventsub-subscription-types docs page (there's no swagger/openapi source for it, unlike eventsub-reference), cross-referencing condition fields against the already-parsed eventsub swagger schemas via TwitchAPIParser instead of re-parsing the reference page. Wired into generate_all_apis.tscn as a third "Generate Definitions" column, reusing the existing Eventsub SwaggerParser node to avoid a duplicate fetch. Regenerated twitch_eventsub_definition.gd against live Twitch docs, which picks up the same 5 new subscription types found on the C# side (AutomodMessageHoldV2, AutomodMessageUpdateV2, ChannelBitsUse, ChannelChannelPointsAutomaticRewardRedemptionAddV2, ChannelCustomPowerUpRedemptionAdd) plus a couple of condition/version corrections. Verified the data matches the C# TwitcherSharp generator's output exactly. Also switches response_script resolution from a compile-time class_name reference to a runtime load() by script name: with a bare identifier, a definition for a script that doesn't exist yet in generated_eventsub would fail the whole file to parse, taking every other definition down with it - a real risk given generated_eventsub isn't reliably kept in sync with Twitch. load() degrades to a null response_script for that one entry with a logged error instead.
For each entry in OVERRIDES (e.g. channel.hype_train.begin -> hype_train_begin), also emit a second "*Legacy" Type + static var pointing at the pre-override, mechanically-derived script name (e.g. CHANNEL_HYPE_TRAIN_BEGIN_LEGACY -> channel_hype_train_begin). Anyone already depending on that name keeps working; it's marked deprecated (## @deprecated: ...) and shouldn't be used going forward. response_script for a legacy alias whose file genuinely doesn't exist (most of them, since the override exists precisely because the mechanical name was wrong) degrades to null with a logged load error rather than breaking the whole file - verified end to end.
…e override" This reverts commit 90b8c50.
kanimaru
requested changes
Aug 23, 2026
…review feedback Instead of a separate "Generate Definitions" button, TwitchEventsubGenerator.generate_api() now also regenerates twitch_eventsub_definition.gd right after the payload classes - one click on "Generate Eventsub" does both, reusing the same parsed swagger schemas. Removes the now-unneeded generate_definitions.gd/.tscn. Also applies kani's review feedback on PR #137: explicit type annotations on the `for info in definitions` loops. Left _screaming_snake() as-is rather than switching to to_snake_case().to_upper() as suggested - that splits a trailing version digit off its letter ("ChannelModerateV2" -> "CHANNEL_MODERATE_V_2"), which would break every V2 entry.
generate_api() ran the Definitions step after prepare_component(), which mutates every parsed component's _classname (prefixing it with "TwitchES") to build the payload class names. By the time the Definitions parser searched for e.g. "HypeTrainBeginCondition" it had already become "TwitchESHypeTrainBeginCondition", so every condition lookup silently failed and every definition ended up with an empty conditions array. Move the Definitions step to the start of generate_api(), before component names get mutated. Verified: 0 lookup warnings and non-empty conditions across all 83 definitions (was 71/83 failing).
The "double enable" cleanup dropped res://addons/twitcher/plugin.cfg instead of a duplicate. The merge from main had correctly produced the two-entry list that master carries (gut + twitcher) - the branch base simply predated gut being added, so it was a real merge result, not a duplicate. Without it the addon under development is disabled in its own project. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The generated definitions now list every condition field the docs mention, including optional and mutually exclusive ones - channel.raid takes either from_broadcaster_user_id or to_broadcaster_user_id, never both, and conduit.shard.disabled has an optional conduit_id. get_conditions() copied every listed key unconditionally, so the unused one went out as an empty string and Twitch rejected the subscription. Skip empty values, and read through Dictionary.get() so a config built via create() with a partial condition dictionary no longer crashes here - which is exactly the case create() already logs "You miss probably following condition" about. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Derive the enum version suffix from the digit the header regex already captures, so a future "channel.moderate v3" becomes CHANNEL_MODERATE_V3 instead of a second CHANNEL_MODERATE_V2. - Warn loudly when a definition references a generated_eventsub script that doesn't exist. Definitions are emitted before the payload classes and refer to them by global class name, so a subscription type with no swagger schema would otherwise turn into a project-wide parse error. Runs after the components are written, since an existence check before that would reject types that are about to be generated. - Emit the same "CLASS GOT AUTOGENERATED" banner the other generators use, and add it to the checked-in file so it stays identical to generator output. - Add the missing uid= to both new ext_resource lines in generate_all_apis.tscn. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
kanimaru
approved these changes
Sep 4, 2026
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.
Just like TwitcherSharp, I added a code generator that will now generate the Static definitions for us, so we no longer need to manually check and update them constantly.