From 31d21ddfbf60f18bb697f85603ef9295ce47faeb Mon Sep 17 00:00:00 2001 From: beanbeanjuice Date: Sat, 13 Jul 2024 18:13:14 -0400 Subject: [PATCH] Fixed the Twitch Handler --- ...Listener.java => TwitchGoLiveEventListener.java} | 13 ++++--------- .../utility/sections/twitch/TwitchHandler.java | 7 +------ 2 files changed, 5 insertions(+), 15 deletions(-) rename src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/{TwitchLiveEventListener.java => TwitchGoLiveEventListener.java} (90%) diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchLiveEventListener.java b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchGoLiveEventListener.java similarity index 90% rename from src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchLiveEventListener.java rename to src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchGoLiveEventListener.java index 6dc44720..9c4d172d 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchLiveEventListener.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchGoLiveEventListener.java @@ -8,7 +8,6 @@ import com.github.philippheuer.events4j.simple.domain.EventSubscriber; import com.github.twitch4j.TwitchClient; import com.github.twitch4j.events.ChannelGoLiveEvent; -import com.github.twitch4j.events.ChannelGoOfflineEvent; import com.github.twitch4j.helix.domain.GameList; import com.github.twitch4j.helix.domain.UserList; import net.dv8tion.jda.api.EmbedBuilder; @@ -25,12 +24,12 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -public class TwitchLiveEventListener extends SimpleEventHandler { +public class TwitchGoLiveEventListener extends SimpleEventHandler { private final TwitchClient twitchClient; private final CafeBot cafeBot; - public TwitchLiveEventListener(final TwitchClient twitchClient, final CafeBot cafeBot) { + public TwitchGoLiveEventListener(final TwitchClient twitchClient, final CafeBot cafeBot) { this.twitchClient = twitchClient; this.cafeBot = cafeBot; } @@ -41,14 +40,14 @@ public void onChannelGoLive(final ChannelGoLiveEvent event) { String twitchID = event.getChannel().getId(); String gameID = event.getStream().getGameId(); - cafeBot.getLogger().log(TwitchLiveEventListener.class, LogLevel.DEBUG, "LIVE: " + event.getChannel().getName()); + cafeBot.getLogger().log(TwitchGoLiveEventListener.class, LogLevel.DEBUG, "LIVE: " + event.getChannel().getName()); CompletableFuture userFuture = CompletableFuture.supplyAsync(() -> { try { return twitchClient.getHelix().getUsers(null, List.of(twitchID), null).queue().get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }); - cafeBot.getLogger().log(TwitchLiveEventListener.class, LogLevel.DEBUG, "GAME ID: " + gameID); + cafeBot.getLogger().log(TwitchGoLiveEventListener.class, LogLevel.DEBUG, "GAME ID: " + gameID); if (gameID == null || gameID.isBlank()) { userFuture.thenAcceptAsync((users) -> { handleLiveEvent(event, users.getUsers().getFirst().getProfileImageUrl(), null); @@ -67,10 +66,6 @@ public void onChannelGoLive(final ChannelGoLiveEvent event) { }); } - // TODO: Add offline edit. - @EventSubscriber - public void onChannelGoOffline(final ChannelGoOfflineEvent event) { } - private void handleLiveEvent(final ChannelGoLiveEvent event, final String profileImageURL, @Nullable final String boxArtURL) { String twitchName = event.getChannel().getName().toLowerCase(); diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchHandler.java b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchHandler.java index 9c6b4bf3..ff091507 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchHandler.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/twitch/TwitchHandler.java @@ -1,6 +1,5 @@ package com.beanbeanjuice.cafebot.utility.sections.twitch; -import com.beanbeanjuice.cafeapi.wrapper.CafeAPI; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; import com.github.philippheuer.credentialmanager.domain.OAuth2Credential; @@ -18,14 +17,10 @@ public TwitchHandler(final String token, final CafeBot cafeBot) { twitchClient = TwitchClientBuilder.builder() .withEnableHelix(true) .withDefaultAuthToken(new OAuth2Credential("twitch", token)) -// .withDefaultEventHandler(TwitchLiveEventListener.class) .build(); -// twitchClient.getEventManager().registerEventHandler(new TwitchLiveEventListener(twitchClient, cafeBot)); twitchClient.getEventManager().registerEventHandler(new SimpleEventHandler()); - twitchClient.getEventManager().getEventHandler(SimpleEventHandler.class).registerListener(new TwitchLiveEventListener(twitchClient, cafeBot)); - -// twitchClient.getEventManager().registerEventHandler(new SimpleEventHandler()); // TODO: CONFIRM THIS WORKS + twitchClient.getEventManager().getEventHandler(SimpleEventHandler.class).registerListener(new TwitchGoLiveEventListener(twitchClient, cafeBot)); handleStartup(cafeBot); }