Skip to content

Commit

Permalink
Add FrankerFaceZ global emotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinrobot committed Nov 19, 2023
1 parent 0ddc6ee commit f5237fa
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.vinrobot.mcemote.client.font.impl;
package net.vinrobot.mcemote.client.providers;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.vinrobot.mcemote.client.providers;

import net.vinrobot.mcemote.api.FrankerFaceZService;
import net.vinrobot.mcemote.api.ffz.GlobalEmoteSets;
import net.vinrobot.mcemote.config.Configuration;

import java.util.Arrays;

public class FFZGlobalEmoteProvider implements IEmoteProvider {
@Override
public int priority() {
return 10;
}

@Override
public void registerEmotes(final Configuration config, final IEmoteRegistry registry) throws Exception {
final FrankerFaceZService service = new FrankerFaceZService();

final GlobalEmoteSets emoteSets = service.fetchGlobalEmoteSet();

Arrays.stream(emoteSets.default_sets())
.mapToObj(Integer::toString)
.map(emoteSets.sets()::get)
.flatMap((emoteSet) -> emoteSet.emoticons().stream())
.map(FFZEmote::new)
.forEach(registry::registerEmote);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.vinrobot.mcemote.api.FrankerFaceZService;
import net.vinrobot.mcemote.api.ffz.Platform;
import net.vinrobot.mcemote.client.font.impl.FFZEmote;
import net.vinrobot.mcemote.config.Configuration;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.vinrobot.mcemote.client.providers;

import net.vinrobot.mcemote.api.SevenTVService;
import net.vinrobot.mcemote.client.font.impl.SevenTVEmote;
import net.vinrobot.mcemote.config.Configuration;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.vinrobot.mcemote.api.SevenTVService;
import net.vinrobot.mcemote.api.seventv.Platform;
import net.vinrobot.mcemote.client.font.impl.SevenTVEmote;
import net.vinrobot.mcemote.config.Configuration;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.vinrobot.mcemote.client.font.impl;
package net.vinrobot.mcemote.client.providers;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
net.vinrobot.mcemote.client.providers.STVGlobalEmoteProvider
net.vinrobot.mcemote.client.providers.STVUserEmoteProvider
net.vinrobot.mcemote.client.providers.FFZGlobalEmoteProvider
net.vinrobot.mcemote.client.providers.FFZRoomEmoteProvider
12 changes: 12 additions & 0 deletions src/main/java/net/vinrobot/mcemote/api/FrankerFaceZService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.vinrobot.mcemote.api;

import com.google.gson.Gson;
import net.vinrobot.mcemote.api.ffz.GlobalEmoteSets;
import net.vinrobot.mcemote.api.ffz.Platform;
import net.vinrobot.mcemote.api.ffz.RoomResponse;

Expand All @@ -12,6 +13,7 @@

public class FrankerFaceZService {
public static final String BASE_API = "https://api.frankerfacez.com/v1";
public static final URI GLOBAL_EMOTE_SET_URI = URI.create(BASE_API + "/set/global");

private final HttpClient httpClient;
private final Gson gson = new Gson();
Expand All @@ -24,6 +26,16 @@ public FrankerFaceZService(HttpClient httpClient) {
this.httpClient = httpClient;
}

public GlobalEmoteSets fetchGlobalEmoteSet() throws IOException, InterruptedException {
final HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(GLOBAL_EMOTE_SET_URI)
.build();

final HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());

return gson.fromJson(httpResponse.body(), GlobalEmoteSets.class);
}

public RoomResponse fetchRoom(Platform platform, String roomId) throws IOException, InterruptedException {
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(BASE_API + "/room/" + platform.path + "/" + roomId))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.vinrobot.mcemote.api.ffz;

import java.util.Map;

public record GlobalEmoteSets(
int[] default_sets,
Map<String, EmoteSet> sets
) {
}

0 comments on commit f5237fa

Please sign in to comment.