From 17158443b86074f3ae90b0408845eca4176c0ea8 Mon Sep 17 00:00:00 2001 From: Presti Date: Thu, 27 Apr 2023 18:09:17 +0200 Subject: [PATCH] Clean up and fixing stuff. --- .../de/presti/ree6/bot/version/BotVersion.java | 4 ++-- .../de/presti/ree6/commands/impl/info/Stats.java | 1 + src/main/java/de/presti/ree6/main/Main.java | 4 ++-- .../java/de/presti/ree6/utils/apis/Notifier.java | 12 ++++++++---- .../ree6/utils/apis/SpotifyAPIHandler.java | 16 +++++++++++++--- .../java/de/presti/ree6/utils/data/Config.java | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/presti/ree6/bot/version/BotVersion.java b/src/main/java/de/presti/ree6/bot/version/BotVersion.java index 235d37625..903234b14 100644 --- a/src/main/java/de/presti/ree6/bot/version/BotVersion.java +++ b/src/main/java/de/presti/ree6/bot/version/BotVersion.java @@ -8,11 +8,11 @@ public enum BotVersion { /** * Version for Development tests. */ - DEVELOPMENT_BUILD("bot.tokens.dev", 1, true), + DEVELOPMENT("bot.tokens.dev", 1, true), /** * Version for a not yet fully stable release. */ - BETA_BUILD("bot.tokens.beta", 5, false), + BETA("bot.tokens.beta", 5, false), /** * Version for a stable release. */ diff --git a/src/main/java/de/presti/ree6/commands/impl/info/Stats.java b/src/main/java/de/presti/ree6/commands/impl/info/Stats.java index 2ac267f69..ff0f836cf 100644 --- a/src/main/java/de/presti/ree6/commands/impl/info/Stats.java +++ b/src/main/java/de/presti/ree6/commands/impl/info/Stats.java @@ -93,6 +93,7 @@ public void onPerform(CommandEvent commandEvent) { MessageEditBuilder messageEditBuilder = new MessageEditBuilder(); + messageEditBuilder.setContent(""); messageEditBuilder.setEmbeds(em.build()); commandEvent.update(message, messageEditBuilder.build()); diff --git a/src/main/java/de/presti/ree6/main/Main.java b/src/main/java/de/presti/ree6/main/Main.java index cc9d3c642..4d5e6aba0 100644 --- a/src/main/java/de/presti/ree6/main/Main.java +++ b/src/main/java/de/presti/ree6/main/Main.java @@ -189,11 +189,11 @@ public static void main(String[] args) { List argList = Arrays.stream(args).map(String::toLowerCase).toList(); if (argList.contains("--dev")) { - BotWorker.createBot(BotVersion.DEVELOPMENT_BUILD); + BotWorker.createBot(BotVersion.DEVELOPMENT); } else if (argList.contains("--prod")) { BotWorker.createBot(BotVersion.RELEASE); } else if (argList.contains("--beta")) { - BotWorker.createBot(BotVersion.BETA_BUILD); + BotWorker.createBot(BotVersion.BETA); } else { BotWorker.createBot(BotVersion.RELEASE); } diff --git a/src/main/java/de/presti/ree6/utils/apis/Notifier.java b/src/main/java/de/presti/ree6/utils/apis/Notifier.java index 1437e483d..9c052f3de 100644 --- a/src/main/java/de/presti/ree6/utils/apis/Notifier.java +++ b/src/main/java/de/presti/ree6/utils/apis/Notifier.java @@ -20,7 +20,6 @@ import com.github.twitch4j.events.ChannelFollowCountUpdateEvent; import com.github.twitch4j.events.ChannelGoLiveEvent; import com.github.twitch4j.eventsub.events.ChannelSubscribeEvent; -import com.github.twitch4j.helix.domain.SubscriptionEvent; import com.github.twitch4j.helix.domain.User; import com.github.twitch4j.pubsub.PubSubSubscription; import com.github.twitch4j.pubsub.events.FollowingEvent; @@ -46,6 +45,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import masecla.reddit4j.client.Reddit4J; +import masecla.reddit4j.exceptions.AuthenticationException; import masecla.reddit4j.objects.Sorting; import masecla.reddit4j.objects.subreddit.RedditSubreddit; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; @@ -148,7 +148,7 @@ public Notifier() { TwitchAuth.registerIdentityProvider(credentialManager, Main.getInstance().getConfig().getConfiguration().getString("twitch.client.id"), Main.getInstance().getConfig().getConfiguration().getString("twitch.client.secret"), - (BotWorker.getVersion() != BotVersion.DEVELOPMENT_BUILD ? "https://cp.ree6.de" : "http://localhost:8888") + "/twitch/auth/callback"); + (BotWorker.getVersion() != BotVersion.DEVELOPMENT ? "https://cp.ree6.de" : "http://localhost:8888") + "/twitch/auth/callback"); twitchIdentityProvider = (TwitchIdentityProvider) credentialManager.getIdentityProviderByName("twitch").orElse(null); @@ -228,7 +228,11 @@ public Notifier() { redditClient.userlessConnect(); createRedditPostStream(); } catch (Exception exception) { - log.error("Failed to connect to Reddit API.", exception); + if (exception instanceof AuthenticationException) { + log.warn("Reddit Credentials are invalid, you can ignore this if you don't use Reddit."); + } else { + log.error("Failed to connect to Reddit API.", exception); + } } log.info("Initializing Instagram Client..."); @@ -250,7 +254,7 @@ public Notifier() { .password(Main.getInstance().getConfig().getConfiguration().getString("instagram.password")) .onChallenge(challengeHandler).build(); instagramClient.sendLoginRequest().exceptionally(throwable -> { - log.error("Failed to login to Instagram API.", throwable); + log.error("Failed to login to Instagram API, you can ignore this if you don't use Instagram.", throwable); return null; }); createInstagramPostStream(); diff --git a/src/main/java/de/presti/ree6/utils/apis/SpotifyAPIHandler.java b/src/main/java/de/presti/ree6/utils/apis/SpotifyAPIHandler.java index 7a87fb524..24bac887f 100644 --- a/src/main/java/de/presti/ree6/utils/apis/SpotifyAPIHandler.java +++ b/src/main/java/de/presti/ree6/utils/apis/SpotifyAPIHandler.java @@ -6,6 +6,7 @@ import org.apache.hc.core5.http.ParseException; import se.michaelthelin.spotify.SpotifyApi; import se.michaelthelin.spotify.exceptions.SpotifyWebApiException; +import se.michaelthelin.spotify.exceptions.detailed.BadRequestException; import se.michaelthelin.spotify.exceptions.detailed.UnauthorizedException; import se.michaelthelin.spotify.model_objects.credentials.ClientCredentials; import se.michaelthelin.spotify.model_objects.specification.ArtistSimplified; @@ -60,9 +61,18 @@ public SpotifyAPIHandler() { public void initSpotify() throws ParseException, SpotifyWebApiException, IOException { this.spotifyApi = new SpotifyApi.Builder().setClientId(Main.getInstance().getConfig().getConfiguration().getString("spotify.client.id")).setClientSecret(Main.getInstance().getConfig().getConfiguration().getString("spotify.client.secret")).build(); - ClientCredentialsRequest.Builder request = new ClientCredentialsRequest.Builder(spotifyApi.getClientId(), spotifyApi.getClientSecret()); - ClientCredentials credentials = request.grant_type("client_credentials").build().execute(); - spotifyApi.setAccessToken(credentials.getAccessToken()); + try { + ClientCredentialsRequest.Builder request = new ClientCredentialsRequest.Builder(spotifyApi.getClientId(), spotifyApi.getClientSecret()); + ClientCredentials credentials = request.grant_type("client_credentials").build().execute(); + spotifyApi.setAccessToken(credentials.getAccessToken()); + } catch (Exception exception) { + if (exception.getMessage().equalsIgnoreCase("Invalid client")) { + log.warn("Spotify Credentials are invalid, you can ignore this if you don't use Spotify."); + } else { + throw exception; + } + } + } /** diff --git a/src/main/java/de/presti/ree6/utils/data/Config.java b/src/main/java/de/presti/ree6/utils/data/Config.java index 191f7c36c..91becfe97 100644 --- a/src/main/java/de/presti/ree6/utils/data/Config.java +++ b/src/main/java/de/presti/ree6/utils/data/Config.java @@ -65,7 +65,7 @@ public void init() { .parent().path("host").addDefault("localhost") .parent().path("port").addDefault(3306) .parent().parent().path("misc").comment("Misc Configuration").blankLine() - .path("storage").addDefault("sqlite") + .path("storage").addDefault("sqlite").commentSide("Either use sqlite or mariadb.") .parent().path("storageFile").addDefault("storage/Ree6.db") .parent().path("poolSize").addDefault(10);