use of com.glitchcog.fontificator.emoji.LazyLoadEmoji in project ChatGameFontificator by GlitchCog.
the class EmojiParser method parseFrankerFaceZModBadge.
/**
* Parse the FrankerFaceZ room data for the optional moderator badge
*
* @param manager
* @param jsonData
* @throws IOException
*/
public void parseFrankerFaceZModBadge(EmojiManager manager, String jsonData) throws IOException {
Gson gson = new Gson();
Type roomType = new TypeToken<Room>() {
}.getType();
JsonObject jsonObject = new JsonParser().parse(jsonData).getAsJsonObject();
Room room = gson.fromJson(jsonObject.get("room"), roomType);
final boolean customFfzModBadgeExists = room != null && room.getModerator_badge() != null;
if (customFfzModBadgeExists) {
LazyLoadEmoji modLle = new LazyLoadEmoji(UserType.MOD.getKey(), UserType.MOD.getKey(), "https:" + room.getModerator_badge(), ConfigEmoji.MOD_BADGE_COLOR, EmojiType.FRANKERFACEZ_BADGE);
manager.getEmojiByType(EmojiType.FRANKERFACEZ_BADGE).put(UserType.MOD.getKey(), modLle);
logBox.log("Loaded the custom FrankerFaceZ moderator badge");
}
}
use of com.glitchcog.fontificator.emoji.LazyLoadEmoji in project ChatGameFontificator by GlitchCog.
the class EmojiParser method parseTwitchEmoteJsonV2.
/**
* Parse emotes loaded using Twitch's emote API version 2
*
* Twitch V2 API retired on February 14, 2017
*
* @param manager
* @param jsonData
* @param jsonMapData
* @throws IOException
*/
@Deprecated
private void parseTwitchEmoteJsonV2(EmojiManager manager, String jsonData, String jsonMapData) throws IOException {
TypedEmojiMap emoji = manager.getEmojiByType(EmojiType.TWITCH_V2);
JsonElement emoteElement = new JsonParser().parse(jsonData).getAsJsonObject().get("emoticons");
Gson gson = new Gson();
Type emoteType = new TypeToken<TwitchEmoteV2[]>() {
}.getType();
TwitchEmoteV2[] jsonEmoteObjects = gson.fromJson(emoteElement, emoteType);
for (TwitchEmoteV2 e : jsonEmoteObjects) {
// For Twitch emotes V2, there are no multi-image emotes, I think, based on the JSON structure
LazyLoadEmoji lle = new LazyLoadEmoji(e.getRegex(), e.getUrl(), e.getWidth(), e.getHeight(), EmojiType.TWITCH_V2);
lle.setSubscriber(e.isSubscriber_only());
lle.setState(e.getState());
emoji.put(e.getRegex(), lle);
}
logBox.log(jsonEmoteObjects.length + " Twitch emote" + (jsonEmoteObjects.length == 1 ? "" : "s") + " loaded");
}
use of com.glitchcog.fontificator.emoji.LazyLoadEmoji in project ChatGameFontificator by GlitchCog.
the class EmojiParser method parseBetterTtvEmoteJson.
/**
* Parse emotes loaded using the BetterTTV emote API
*
* @param emoji
* @param jsonData
* @param isGlobal
* Whether the BetterTTV emotes to be loaded are the BetterTTV global emotes
* @throws IOException
*/
private void parseBetterTtvEmoteJson(TypedEmojiMap emoji, String jsonData, boolean isGlobal) throws IOException {
JsonParser jp = new JsonParser();
JsonObject root = jp.parse(jsonData).getAsJsonObject();
if (root.get("emotes").isJsonNull()) {
logBox.log("Unable to load Better TTV global emotes");
return;
}
Gson gson = new Gson();
Type emoteType = new TypeToken<BttvEmote[]>() {
}.getType();
final String urlTemplate = "https:" + root.get("urlTemplate").getAsString().replace("{{image}}", "2x");
BttvEmote[] bttvEmotes = gson.fromJson(root.get("emotes").getAsJsonArray(), emoteType);
int bttvCount = 0;
for (BttvEmote be : bttvEmotes) {
LazyLoadEmoji lle = new LazyLoadEmoji(be.getCode(), urlTemplate.replace("{{id}}", be.getId()), isGlobal ? EmojiType.BETTER_TTV_GLOBAL : EmojiType.BETTER_TTV_CHANNEL);
lle.setAnimatedGif(AnimatedGifUtil.GIF_EXTENSION.equals(be.getImageType()));
emoji.put(be.getCode(), lle);
bttvCount++;
}
logBox.log(bttvCount + " Better TTV emote" + (bttvCount == 1 ? "" : "s") + " found");
}
use of com.glitchcog.fontificator.emoji.LazyLoadEmoji in project ChatGameFontificator by GlitchCog.
the class EmojiParser method parseFrankerFaceZEmoteJson.
/**
* Parse emotes loaded using the FrankerFaceZ emote API
*
* @param emoji
* @param jsonData
* @param isGlobal
* Whether the FFZ emotes to be loaded are the FFZ global emotes
* @throws IOException
*/
private void parseFrankerFaceZEmoteJson(TypedEmojiMap emoji, String jsonData, boolean isGlobal) throws IOException {
JsonParser jp = new JsonParser();
JsonObject root = jp.parse(jsonData).getAsJsonObject();
if (root.get("error") != null) {
String errorMessage = "Unable to load FrankerFaceZ emotes";
if (!root.get("message").isJsonNull()) {
errorMessage += ": " + root.get("message");
}
logBox.log(errorMessage);
return;
} else if (root.get("sets").isJsonNull() || (isGlobal && root.get("default_sets").isJsonNull())) {
logBox.log("Unable to load FrankerFaceZ global emotes");
return;
}
List<String> setsToLoad;
if (isGlobal) {
setsToLoad = new ArrayList<String>();
JsonArray defaultSetsArray = root.get("default_sets").getAsJsonArray();
for (int i = 0; i < defaultSetsArray.size(); i++) {
setsToLoad.add(defaultSetsArray.get(i).getAsString());
}
} else {
setsToLoad = null;
}
JsonObject sets = root.get("sets").getAsJsonObject();
Gson gson = new Gson();
Type emoteType = new TypeToken<FfzEmote[]>() {
}.getType();
int frankerCount = 0;
int eMultiCount = 0;
List<String> setNames = new ArrayList<String>();
for (Map.Entry<String, JsonElement> entry : sets.entrySet()) {
setNames.add(entry.getKey());
JsonElement emoteElement = entry.getValue().getAsJsonObject().get("emoticons");
FfzEmote[] jsonEmoteObjects = gson.fromJson(emoteElement, emoteType);
for (FfzEmote e : jsonEmoteObjects) {
LazyLoadEmoji lle = null;
for (String key : e.getUrls().keySet()) {
lle = new LazyLoadEmoji(e.getName(), "http:" + e.getUrls().get(key), e.getWidth(), e.getHeight(), isGlobal ? EmojiType.FRANKERFACEZ_GLOBAL : EmojiType.FRANKERFACEZ_CHANNEL);
break;
}
if (e.getUrls().size() > 1) {
eMultiCount++;
}
emoji.put(e.getName(), lle);
frankerCount++;
}
}
String allSets = "";
for (int n = 0; n < setNames.size(); n++) {
allSets += (n == 0 ? "" : ", ") + setNames.get(n);
}
logBox.log(setNames.size() + " FrankerFaceZ set" + (setNames.size() == 1 ? "" : "s") + " found: {" + allSets + "}");
logBox.log(frankerCount + " FrankerFaceZ emote" + (frankerCount == 1 ? "" : "s") + " loaded (" + eMultiCount + " multi-image emote" + (eMultiCount == 1 ? "" : "s") + ")");
}
use of com.glitchcog.fontificator.emoji.LazyLoadEmoji in project ChatGameFontificator by GlitchCog.
the class Message method processEmoji.
/**
* Convert the content of the message into the appropriate emoji. Add those emoji and the remaining characters
* between them to the specified keyList array.
*
* @param content
* @param privmsg
* @param keyList
* The array to add the emoji and remaining characters to
* @param emojiManager
* @param emojiConfig
* @param isManualMessage
*/
private static void processEmoji(String content, TwitchPrivmsg privmsg, List<SpriteCharacterKey> keyList, EmojiManager emojiManager, ConfigEmoji emojiConfig, boolean isManualMessage, MessageCasing casing) {
Map<Integer, EmoteAndIndices> emotes = privmsg.getEmotes();
String[] words = content.split(SPACE_BOUNDARY_REGEX);
int codeIndex = 0;
LazyLoadEmoji emoji = null;
for (int w = 0; w < words.length; w++) {
EmoteAndIndices eai = emotes.get(codeIndex);
if (eai != null && emojiConfig.isTwitchEnabled()) {
// This catches subscriber emotes and any non-global emotes
emoji = emojiManager.getEmojiById(eai.getEmoteId(), words[w], emojiConfig);
if (emoji == null) {
// The already loaded Twitch V1 emoji map doesn't this emote ID yet, so add it
try {
emoji = emojiManager.putEmojiById(eai.getEmoteId(), words[w], emojiConfig);
} catch (MalformedURLException e) {
logger.error("Unable to load emote for emote ID " + eai.getEmoteId(), e);
}
}
} else // At this point, only 3rd party emoji should be a possibility for this word (with the exception of
// manual messages)
{
// This is the manual message exception
if (isManualMessage) {
// As a known bug here, all manual messages will have access to all Twitch emotes, regardless of
// subscriber status
emoji = emojiManager.getEmoji(EmojiType.MANUAL_EMOJI_TYPES, words[w], emojiConfig);
} else // Only check 3rd party emotes
{
emoji = emojiManager.getEmoji(EmojiType.THIRD_PARTY_EMOJI_TYPES, words[w], emojiConfig);
}
}
if (emoji == null) {
keyList.addAll(toSpriteArray(applyCasing(words[w], casing)));
} else {
keyList.add(new SpriteCharacterKey(emoji, false));
}
// Increment the codeIndex by the current word's code point count
// Emoji indexes are in code points, but java is counting in fixed 16-bit units
codeIndex += words[w].codePointCount(0, words[w].length());
}
}
Aggregations