-
Notifications
You must be signed in to change notification settings - Fork 14
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
Early support for current Twitch badges #12
base: issue-11
Are you sure you want to change the base?
Conversation
This patch handles new twitch badges from their newer API called Badge V1 Fix EmojiJob comparison to include channel_id Better errors out of new badge parsing
1. Put FFZ badges in a list 2. Upon attempting to insert twitch badges, consume FFZ badges instead 3. Assign FFZ badges to SpriteCharacterKeys 4. Assign other badges (Twitch badges) to SpriteCharacterKeys Assumes FFZ badges are to be displayed before Twitch badges and that the FFZ moderator replacement badge is of a lower priority than the FFZ bot badge. Note that the moderator badge is now "moderator" not "mod" in most cases.
|
||
if (emoji == null) | ||
LazyLoadEmoji emoji = null; | ||
if (type.canRegEx()) |
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.
The slashes in new badge name caused me problems because they'd get identified as regex's and then things got weird. So I realized that the need for regex's could be sourced from the EmojiType because only twitch emoji really use regex. This I think simplified the BTTV handling
@@ -224,24 +222,70 @@ private void parseTwitchBadges(TypedEmojiMap badgeMap, String jsonData) throws I | |||
{ | |||
JsonElement jsonElement = new JsonParser().parse(jsonData); | |||
|
|||
Boolean isNewStyle = jsonElement.getAsJsonObject().has("badge_sets"); |
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.
Not sure if the changes to this function are handling all possible error states.
package com.glitchcog.fontificator.emoji.loader.twitch; | ||
|
||
|
||
public class TwitchBadgesNew { |
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.
This is a rather silly name for this class, but it could always be renamed, or eventually just replace the other one.
@@ -740,6 +759,7 @@ public void deepCopy(ConfigEmoji copy) | |||
this.ffzEnabled = copy.ffzEnabled; | |||
this.twitchLoaded = copy.twitchLoaded; | |||
this.twitchBadgesLoadedChannel = copy.twitchBadgesLoadedChannel; | |||
this.twitchBadgesLoadedChannel = copy.twitchBadgesLoadedGlobal; |
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.
Cut and paste bug; you mean: this.twitchBadgesLoadedGlobal = copy.twitchBadgesLoadedGlobal;
@@ -414,42 +414,25 @@ private boolean isConfigChanged(ConfigMessage messageConfig, ConfigEmoji emojiCo | |||
|
|||
// Bank to pull FrankerFaceZ badges from | |||
TypedEmojiMap ffzBadgeBank = emojiManager.getEmojiByType(EmojiType.FRANKERFACEZ_BADGE); | |||
Map<String, LazyLoadEmoji> ffzBadgeMap = new LinkedHashMap<String, LazyLoadEmoji>(); |
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.
Does this need to be a LinkedHashMap? I don't think you depend on a consistent order for FFZ badges.
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.
I originally used a LinkedHashMap to collect all the badges to be displayed, both Twitch and FFZ, because I could control the order they were added.
It doesn't look like this ffzBadgeMap variable needs to be ordered, since it only will contain at most the FFZ mod override and the FFZ donor badges, but in principle I think it should be, since whatever is in this map will get drawn in some order as badges. In theory, FFZ might add five more badges tomorrow, and then we'd have to change it back.
Here's the first phase of changes for new badge support.
I'm very very open to criticism and corrections on this. I'll admit java is not a language I've touched much in recent years. I'm quite flexible. My end goal with all of this was to get it so that I'd see current subscriber emotes in the widget and the rest flowed from that.
What is critically missing from this is a way to retrieve channel/user IDs.
There's multiple ways.: IRC broadcasts the room ID to you once you join. There's an
HTTP REST API from Twitch to look up a user ID from a username.
How that is handled in relationship to the ability to preload emotes/badges and/or to interject this loading into the connection process was a problem I did not solve.
Perhaps that can be solved by glitchcog in another patch on this issue-11 branch. Without that, I don't think it should merge into master. I probably broke classic badges with this patchset.
Additionally, since I'm mostly improving this for a twitch broadcaster named "pjdicesare", I got
some feedback from them. One thing that came up is that once support for all these badges are
added, it could become quite too much and all the extra badges would take away from screen space
in the widget. With up to 4 twitch badges now possible at once, that might turn out to be too much at once. But having an up to date subscriber emote seemed useful, which again is why I started working on this in the first place.
Info about new badges and a bit about the implementation:
New Twitch badges are based on being part of the IRC v3 message tags
Examples:
badges=subscriber/1,moderator/1
badges=subscriber/6,bits/1000
badges=prime/1
https://dev.twitch.tv/docs/v5/guides/irc/
Section "PRIVMSG (Twitch Tags)" documents the badges tag.
The twitch badges are described by a different json format from what used to be and are available here:
https://badges.twitch.tv/v1/badges/channels/_ID_/display
The global badges are here: https://badges.twitch.tv/v1/badges/global/display
In order to handle this, plus the interaction with FFZ's badge overrides, I had to change several things.
You'll note that I've tried to identify badges by their "primary identifier", which isn't a name I'm married to, either.
A primary identifier for "subscriber/6" is "subscriber". A primary identifier for "moderator/1" is "moderator". Coincidentally, this makes it
possible to figure out which FFZ badge overrides the "moderator" identifier.
EDIT: Say this to get github to link the issue: Issue #11