Skip to content

Commit

Permalink
Clean up and fixing stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Apr 27, 2023
1 parent b7c2b4b commit 1715844
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/presti/ree6/bot/version/BotVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/presti/ree6/commands/impl/info/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void onPerform(CommandEvent commandEvent) {

MessageEditBuilder messageEditBuilder = new MessageEditBuilder();

messageEditBuilder.setContent("");
messageEditBuilder.setEmbeds(em.build());

commandEvent.update(message, messageEditBuilder.build());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/presti/ree6/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ public static void main(String[] args) {
List<String> 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);
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/de/presti/ree6/utils/apis/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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...");
Expand All @@ -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();
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/de/presti/ree6/utils/apis/SpotifyAPIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/presti/ree6/utils/data/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1715844

Please sign in to comment.