From 9720c4f598fe8a0ada518f504129d60737b0b904 Mon Sep 17 00:00:00 2001 From: PinkGoosik Date: Tue, 28 May 2024 15:54:14 +0400 Subject: [PATCH] debug webhook --- .../kitsun/{Bot.java => DiscordApp.java} | 4 +- .../ru/pinkgoosik/kitsun/api/FabricMeta.java | 6 +-- .../ru/pinkgoosik/kitsun/api/Modrinth.java | 12 ++--- .../ru/pinkgoosik/kitsun/api/QuiltMeta.java | 8 +-- .../kitsun/api/curseforge/CurseForgeAPI.java | 8 +-- .../kitsun/api/mojang/MojangAPI.java | 6 +-- .../kitsun/api/mojang/PatchNotes.java | 4 +- .../ru/pinkgoosik/kitsun/cache/Cached.java | 10 ++-- .../kitsun/command/KitsunCommands.java | 6 +-- .../command/admin/AutoChannelsCommand.java | 4 +- .../ru/pinkgoosik/kitsun/config/Secrets.java | 1 + .../kitsun/debug/KitsunDebugWebhook.java | 49 +++++++++++++++++++ .../kitsun/event/DiscordEventsListener.java | 27 +++++----- .../kitsun/feature/AutoChannelsManager.java | 19 +++---- .../kitsun/feature/KitsunDebugger.java | 47 ------------------ .../kitsun/feature/MCUpdatesPublisher.java | 6 +-- .../ru/pinkgoosik/kitsun/feature/ModCard.java | 3 +- .../kitsun/feature/ModUpdatesPublisher.java | 7 +-- .../kitsun/feature/QuiltUpdatesPublisher.java | 4 +- .../kitsun/feature/ServerLogger.java | 4 +- .../pinkgoosik/kitsun/http/GithubWebhook.java | 10 ++-- .../kitsun/http/KitsunHttpHandler.java | 10 ++-- .../kitsun/http/KitsunHttpServer.java | 8 +-- .../kitsun/http/ModUpdateWebhook.java | 10 ++-- .../kitsun/schedule/MCUpdatesScheduler.java | 4 +- .../kitsun/schedule/ModCardsScheduler.java | 10 ++-- .../kitsun/schedule/ModUpdatesScheduler.java | 4 +- .../schedule/QuiltUpdatesScheduler.java | 4 +- .../pinkgoosik/kitsun/schedule/Scheduler.java | 2 - .../pinkgoosik/kitsun/util/ChannelUtils.java | 6 +-- .../ru/pinkgoosik/kitsun/util/SelfUtils.java | 4 +- .../pinkgoosik/kitsun/util/ServerUtils.java | 8 +-- 32 files changed, 158 insertions(+), 157 deletions(-) rename src/main/java/ru/pinkgoosik/kitsun/{Bot.java => DiscordApp.java} (97%) create mode 100644 src/main/java/ru/pinkgoosik/kitsun/debug/KitsunDebugWebhook.java delete mode 100644 src/main/java/ru/pinkgoosik/kitsun/feature/KitsunDebugger.java diff --git a/src/main/java/ru/pinkgoosik/kitsun/Bot.java b/src/main/java/ru/pinkgoosik/kitsun/DiscordApp.java similarity index 97% rename from src/main/java/ru/pinkgoosik/kitsun/Bot.java rename to src/main/java/ru/pinkgoosik/kitsun/DiscordApp.java index 63a6848..bf742b7 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/Bot.java +++ b/src/main/java/ru/pinkgoosik/kitsun/DiscordApp.java @@ -16,13 +16,13 @@ import java.util.Arrays; -public class Bot { +public class DiscordApp { public static final Logger LOGGER = LoggerFactory.getLogger("Kitsun"); public static Cached secrets = Cached.of("secrets", Secrets.class, () -> Secrets.DEFAULT); public static JDA jda; public static void main(String[] args) { - Bot.init(); + DiscordApp.init(); KitsunHttpServer.init(); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/api/FabricMeta.java b/src/main/java/ru/pinkgoosik/kitsun/api/FabricMeta.java index cbaa292..3eda32f 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/api/FabricMeta.java +++ b/src/main/java/ru/pinkgoosik/kitsun/api/FabricMeta.java @@ -1,6 +1,6 @@ package ru.pinkgoosik.kitsun.api; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.UrlParser; import java.util.ArrayList; @@ -16,7 +16,7 @@ public static Optional> getFabricVersions() { return Optional.of(new ArrayList<>(List.of(versions))); } catch(Exception e) { - KitsunDebugger.report("Failed to parse fabric versions due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse fabric versions due to an exception:\n" + e); } return Optional.empty(); } @@ -27,7 +27,7 @@ public static Optional> getFabricVersions(String gameVersion) { return Optional.of(new ArrayList<>(List.of(entries))); } catch(Exception e) { - KitsunDebugger.report("Failed to parse fabric versions for game version " + gameVersion + " due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse fabric versions for game version " + gameVersion + " due to an exception:\n" + e); } return Optional.empty(); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/api/Modrinth.java b/src/main/java/ru/pinkgoosik/kitsun/api/Modrinth.java index 00bad72..7fad9d5 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/api/Modrinth.java +++ b/src/main/java/ru/pinkgoosik/kitsun/api/Modrinth.java @@ -6,8 +6,8 @@ import masecla.modrinth4j.model.project.Project; import masecla.modrinth4j.model.user.ModrinthUser; import masecla.modrinth4j.model.version.ProjectVersion; -import ru.pinkgoosik.kitsun.Bot; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.DiscordApp; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import java.util.ArrayList; import java.util.Optional; @@ -16,14 +16,14 @@ public class Modrinth { public static final String PROJECT_URL = "https://modrinth.com/project/%slug%"; public static final ModrinthAPI API = ModrinthAPI.rateLimited( UserAgent.builder().authorUsername("tyap-lyap").projectName("kitsun").projectVersion("latest").build(), - Bot.secrets.get().modrinthApiKey); + DiscordApp.secrets.get().modrinthApiKey); public static Optional getProject(String project) { try { return Optional.of(API.projects().get(project).join()); } catch (Exception e) { - KitsunDebugger.report("Failed to get modrinth project " + project + " due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to get modrinth project " + project + " due to an exception:\n" + e); } return Optional.empty(); } @@ -33,7 +33,7 @@ public static Optional> getVersions(String project) { return Optional.of(new ArrayList<>(API.versions().getProjectVersions(project, GetProjectVersions.GetProjectVersionsRequest.builder().build()).get())); } catch (Exception e) { - KitsunDebugger.report("Failed to get modrinth project " + project + " versions due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to get modrinth project " + project + " versions due to an exception:\n" + e); } return Optional.empty(); } @@ -43,7 +43,7 @@ public static Optional getUser(String id) { return Optional.of(API.users().getUser(id).join()); } catch (Exception e) { - KitsunDebugger.report("Failed to get modrinth user " + id + " due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to get modrinth user " + id + " due to an exception:\n" + e); } return Optional.empty(); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/api/QuiltMeta.java b/src/main/java/ru/pinkgoosik/kitsun/api/QuiltMeta.java index 2ed8549..a3fb953 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/api/QuiltMeta.java +++ b/src/main/java/ru/pinkgoosik/kitsun/api/QuiltMeta.java @@ -1,6 +1,6 @@ package ru.pinkgoosik.kitsun.api; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.UrlParser; import java.util.ArrayList; @@ -17,7 +17,7 @@ public static Optional> getQuiltVersions() { return Optional.of(new ArrayList<>(List.of(versions))); } catch(Exception e) { - KitsunDebugger.report("Failed to parse quilt versions due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse quilt versions due to an exception:\n" + e); } return Optional.empty(); } @@ -28,7 +28,7 @@ public static Optional> getQuiltVersions(String gameVersion) { return Optional.of(new ArrayList<>(List.of(entries))); } catch(Exception e) { - KitsunDebugger.report("Failed to parse quilt versions for game version " + gameVersion + " due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse quilt versions for game version " + gameVersion + " due to an exception:\n" + e); } return Optional.empty(); } @@ -39,7 +39,7 @@ public static Optional> getQuiltMappingsVersions return Optional.of(new ArrayList<>(List.of(versions))); } catch(Exception e) { - KitsunDebugger.report("Failed to parse quilt mappings versions for game version " + gameVersion + " due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse quilt mappings versions for game version " + gameVersion + " due to an exception:\n" + e); } return Optional.empty(); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/api/curseforge/CurseForgeAPI.java b/src/main/java/ru/pinkgoosik/kitsun/api/curseforge/CurseForgeAPI.java index f29f43d..e71abb0 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/api/curseforge/CurseForgeAPI.java +++ b/src/main/java/ru/pinkgoosik/kitsun/api/curseforge/CurseForgeAPI.java @@ -2,9 +2,9 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.api.curseforge.entity.CurseForgeMod; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import java.io.FileNotFoundException; import java.io.InputStream; @@ -26,7 +26,7 @@ public static Optional getMod(String id) { HttpRequest request = HttpRequest.newBuilder() .GET() .uri(new URI(API_MOD_URL.replace("%id%", id))) - .headers("x-api-key", Bot.secrets.get().curseforgeApiKey) + .headers("x-api-key", DiscordApp.secrets.get().curseforgeApiKey) .build(); HttpResponse response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofInputStream()); @@ -38,7 +38,7 @@ public static Optional getMod(String id) { return Optional.empty(); } catch(Exception e) { - KitsunDebugger.report("Failed to parse curseforge mod " + id + " due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse curseforge mod " + id + " due to an exception:\n" + e); } return Optional.empty(); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/api/mojang/MojangAPI.java b/src/main/java/ru/pinkgoosik/kitsun/api/mojang/MojangAPI.java index cac2cc0..7676bda 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/api/mojang/MojangAPI.java +++ b/src/main/java/ru/pinkgoosik/kitsun/api/mojang/MojangAPI.java @@ -2,7 +2,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.UrlParser; import java.io.InputStreamReader; @@ -26,7 +26,7 @@ public static Optional getManifest() { return Optional.empty(); } catch(Exception e) { - KitsunDebugger.report("Failed to parse minecraft versions manifest due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse minecraft versions manifest due to an exception:\n" + e); } return Optional.empty(); } @@ -61,7 +61,7 @@ public static Optional getUuid(String nickname) { return Optional.of(fromTrimmed(element.getAsJsonObject().get("id").getAsString())); } catch(Exception e) { - KitsunDebugger.report("Failed to parse " + nickname + "'s UUID due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to parse " + nickname + "'s UUID due to an exception:\n" + e); return Optional.empty(); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/api/mojang/PatchNotes.java b/src/main/java/ru/pinkgoosik/kitsun/api/mojang/PatchNotes.java index c313b4c..0cae59f 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/api/mojang/PatchNotes.java +++ b/src/main/java/ru/pinkgoosik/kitsun/api/mojang/PatchNotes.java @@ -1,7 +1,7 @@ package ru.pinkgoosik.kitsun.api.mojang; import com.google.gson.*; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import java.io.InputStreamReader; import java.net.URL; @@ -25,7 +25,7 @@ public static Optional getEntry(String version) { } } catch(Exception e) { - Bot.LOGGER.error("Failed to parse patch note entry due to an exception:\n" + e); + DiscordApp.LOGGER.error("Failed to parse patch note entry due to an exception:\n" + e); } return Optional.empty(); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/cache/Cached.java b/src/main/java/ru/pinkgoosik/kitsun/cache/Cached.java index 765b728..318a7f0 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/cache/Cached.java +++ b/src/main/java/ru/pinkgoosik/kitsun/cache/Cached.java @@ -2,8 +2,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import ru.pinkgoosik.kitsun.Bot; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.DiscordApp; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.FileUtils; import java.io.BufferedReader; @@ -44,14 +44,14 @@ public T read(Class type) { return GSON.fromJson(reader, type); } catch(FileNotFoundException e) { - Bot.LOGGER.info("File " + filePath + " is not found! Setting to default."); + DiscordApp.LOGGER.info("File " + filePath + " is not found! Setting to default."); var dat = defaultBuilder.create(); this.data = dat; this.save(); return dat; } catch(Exception e) { - Bot.LOGGER.error("Failed to read cached data due to an exception:\n" + e + "\n Setting to default."); + DiscordApp.LOGGER.error("Failed to read cached data due to an exception:\n" + e + "\n Setting to default."); return defaultBuilder.create(); } } @@ -65,7 +65,7 @@ public void save() { } } catch(Exception e) { - KitsunDebugger.ping("Failed to save cached data due to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to save cached data due to an exception:\n" + e); e.printStackTrace(); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/command/KitsunCommands.java b/src/main/java/ru/pinkgoosik/kitsun/command/KitsunCommands.java index 5c81349..9aeedae 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/command/KitsunCommands.java +++ b/src/main/java/ru/pinkgoosik/kitsun/command/KitsunCommands.java @@ -2,7 +2,7 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.command.member.*; import ru.pinkgoosik.kitsun.command.admin.*; @@ -51,8 +51,8 @@ public static void onConnect() { } }); - Bot.jda.updateCommands().addCommands(globalCommands).queue(); - var guild = Bot.getGuild("854349856164020244"); + DiscordApp.jda.updateCommands().addCommands(globalCommands).queue(); + var guild = DiscordApp.getGuild("854349856164020244"); if(guild != null) { guild.updateCommands().addCommands(tlCommands).queue(); diff --git a/src/main/java/ru/pinkgoosik/kitsun/command/admin/AutoChannelsCommand.java b/src/main/java/ru/pinkgoosik/kitsun/command/admin/AutoChannelsCommand.java index 420416a..2b2becf 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/command/admin/AutoChannelsCommand.java +++ b/src/main/java/ru/pinkgoosik/kitsun/command/admin/AutoChannelsCommand.java @@ -5,7 +5,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.cache.ServerData; import ru.pinkgoosik.kitsun.command.CommandHelper; import ru.pinkgoosik.kitsun.command.KitsunCommand; @@ -48,7 +48,7 @@ public void respond(SlashCommandInteractionEvent ctx, CommandHelper helper) { if(channel instanceof VoiceChannel vc) { var category = vc.getParentCategory(); if(category != null) { - var perms = category.getPermissionOverride(Objects.requireNonNull(Objects.requireNonNull(Bot.jda.getGuildById(dat.server)).getMemberById(Bot.jda.getSelfUser().getId()))); + var perms = category.getPermissionOverride(Objects.requireNonNull(Objects.requireNonNull(DiscordApp.jda.getGuildById(dat.server)).getMemberById(DiscordApp.jda.getSelfUser().getId()))); if(perms != null && !perms.getAllowed().contains(Permission.ADMINISTRATOR)) { helper.ephemeral(Embeds.error("Bot doesn't have permission of administrator! It required for auto channels to work properly.")); return; diff --git a/src/main/java/ru/pinkgoosik/kitsun/config/Secrets.java b/src/main/java/ru/pinkgoosik/kitsun/config/Secrets.java index 97af12f..569ac9a 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/config/Secrets.java +++ b/src/main/java/ru/pinkgoosik/kitsun/config/Secrets.java @@ -7,6 +7,7 @@ public class Secrets { public String githubToken = ""; public String note = ""; public String activity = ""; + public String debugWebhook = ""; public HttpConfig http = new HttpConfig(); public static final Secrets DEFAULT = new Secrets(); diff --git a/src/main/java/ru/pinkgoosik/kitsun/debug/KitsunDebugWebhook.java b/src/main/java/ru/pinkgoosik/kitsun/debug/KitsunDebugWebhook.java new file mode 100644 index 0000000..47f54dd --- /dev/null +++ b/src/main/java/ru/pinkgoosik/kitsun/debug/KitsunDebugWebhook.java @@ -0,0 +1,49 @@ +package ru.pinkgoosik.kitsun.debug; + +import ru.pinkgoosik.kitsun.DiscordApp; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; + +public class KitsunDebugWebhook { + private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder().build(); + + public static void ping(String message) { + DiscordApp.LOGGER.error(message); + sendMessage("<@287598520268095488>\n" + message); + } + + public static void report(String message) { + DiscordApp.LOGGER.error(message); + sendMessage(message); + } + + public static void info(String text) { + DiscordApp.LOGGER.info(text); + sendMessage(text); + } + + private static void sendMessage(String content) { + if(DiscordApp.secrets.get().debugWebhook.isBlank()) return; + + try { + byte[] out = ("{\"content\":\"" + content + "\"}").getBytes(StandardCharsets.UTF_8); + int length = out.length; + + HttpRequest request = HttpRequest.newBuilder() + .POST(HttpRequest.BodyPublishers.ofByteArray(out)) + .uri(new URI(DiscordApp.secrets.get().debugWebhook)) + .header("Content-Type", "application/json") + .build(); + + HTTP_CLIENT.sendAsync(request, HttpResponse.BodyHandlers.ofString()); + } + catch (Exception e) { + DiscordApp.LOGGER.info("Failed to execute webhook due to an exception: " + e); + } + } + +} diff --git a/src/main/java/ru/pinkgoosik/kitsun/event/DiscordEventsListener.java b/src/main/java/ru/pinkgoosik/kitsun/event/DiscordEventsListener.java index 9b9ac71..0bef176 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/event/DiscordEventsListener.java +++ b/src/main/java/ru/pinkgoosik/kitsun/event/DiscordEventsListener.java @@ -16,12 +16,12 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.apache.commons.collections4.map.HashedMap; import org.jetbrains.annotations.NotNull; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.cache.ServerData; import ru.pinkgoosik.kitsun.command.CommandHelper; import ru.pinkgoosik.kitsun.command.KitsunCommands; import ru.pinkgoosik.kitsun.feature.AutoReaction; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.schedule.Scheduler; import ru.pinkgoosik.kitsun.util.ServerUtils; @@ -33,10 +33,7 @@ public class DiscordEventsListener extends ListenerAdapter { public static void onConnect(ReadyEvent event) { - Bot.jda = event.getJDA(); - String note = Bot.secrets.get().note; - KitsunDebugger.onConnect(event); - KitsunDebugger.info(note.isEmpty() ? "Kitsun is now running!" : note); + DiscordApp.jda = event.getJDA(); Scheduler.start(); KitsunCommands.onConnect(); } @@ -62,7 +59,7 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even }); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed chat input interaction event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed chat input interaction event due to an exception:\n" + e); } } @@ -76,7 +73,7 @@ public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInterac }); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed command auto complete interaction event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed command auto complete interaction event due to an exception:\n" + e); } } @@ -129,7 +126,7 @@ public void onMessageUpdate(@NotNull MessageUpdateEvent event) { ServerUtils.runFor(guildId, data -> data.logger.get().ifEnabled(log -> log.onMessageUpdate(oldMessage, newMessage))); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed message update event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed message update event due to an exception:\n" + e); } } @@ -141,7 +138,7 @@ public void onMessageDelete(@NotNull MessageDeleteEvent event) { ServerUtils.runFor(guildId, data -> data.logger.get().ifEnabled(log -> log.onMessageDelete(cachedMessages.get(messageId)))); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed message delete event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed message delete event due to an exception:\n" + e); } } @@ -161,7 +158,7 @@ public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { }); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed member join event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed member join event due to an exception:\n" + e); } } @@ -171,7 +168,7 @@ public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) { ServerUtils.runFor(event.getGuild().getId(), data -> data.logger.get().ifEnabled(log -> log.onMemberLeave(event.getUser()))); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed member leave event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed member leave event due to an exception:\n" + e); } } @@ -191,7 +188,7 @@ public void onChannelUpdateName(@NotNull ChannelUpdateNameEvent event) { } catch(Exception e) { - KitsunDebugger.report("Failed to proceed voice channel update event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed voice channel update event due to an exception:\n" + e); } } } @@ -206,7 +203,7 @@ public void onChannelDelete(@NotNull ChannelDeleteEvent event) { ServerUtils.forEach(data -> data.autoChannels.modify(manager -> { manager.getSession(channelId).ifPresent(session -> { - var guild = Bot.jda.getGuildById(data.server); + var guild = DiscordApp.jda.getGuildById(data.server); if(guild != null) { var member = guild.getMemberById(session.owner); data.logger.get().ifEnabled(log -> log.onVoiceChannelDelete(session, member, channel)); @@ -223,7 +220,7 @@ public void onChannelDelete(@NotNull ChannelDeleteEvent event) { })); } catch(Exception e) { - KitsunDebugger.report("Failed to proceed voice channel delete event due to an exception:\n" + e); + KitsunDebugWebhook.report("Failed to proceed voice channel delete event due to an exception:\n" + e); } } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/AutoChannelsManager.java b/src/main/java/ru/pinkgoosik/kitsun/feature/AutoChannelsManager.java index 2a0c4a4..e6cae7a 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/AutoChannelsManager.java +++ b/src/main/java/ru/pinkgoosik/kitsun/feature/AutoChannelsManager.java @@ -4,8 +4,9 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.cache.ServerData; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.ChannelUtils; import java.time.Instant; @@ -36,7 +37,7 @@ public void disable() { // TODO: rewrite this disaster public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) { try { - if(Bot.jda.getGuildChannelById(this.parentChannel) instanceof VoiceChannel channel) { + if(DiscordApp.jda.getGuildChannelById(this.parentChannel) instanceof VoiceChannel channel) { var members = channel.getMembers(); for (var member : members) { var state = member.getVoiceState(); @@ -60,15 +61,15 @@ public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) { ServerData.get(this.server).autoChannels.save(); } else { - KitsunDebugger.ping("Failed to get parent channel duo to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to get parent channel duo to an exception:\n" + e); } } this.sessions.forEach(session -> { try { - if(Bot.jda.getGuildChannelById(session.channel) instanceof VoiceChannel channel) { + if(DiscordApp.jda.getGuildChannelById(session.channel) instanceof VoiceChannel channel) { var members = ChannelUtils.getMembers(channel); if(members.isPresent() && members.get() == 0) { - var guild = Bot.jda.getGuildById(server); + var guild = DiscordApp.jda.getGuildById(server); if (guild != null) { var member = guild.getMemberById(session.owner); ServerData.get(server).logger.get().ifEnabled(log -> log.onVoiceChannelDelete(session, member, channel)); @@ -83,7 +84,7 @@ public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) { session.shouldBeRemoved = true; } else { - KitsunDebugger.ping("Failed to delete auto channel duo to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to delete auto channel duo to an exception:\n" + e); } } }); @@ -98,7 +99,7 @@ public void onParentChannelJoin(Member member) { private boolean hasEmptySession(Member member) { for(var session : this.sessions) { - var chan = Bot.jda.getGuildChannelById(session.channel); + var chan = DiscordApp.jda.getGuildChannelById(session.channel); if(session.owner.equals(member.getId()) && chan instanceof VoiceChannel channel) { var members = ChannelUtils.getMembers(channel); if(members.isPresent() && members.get() == 0) { @@ -111,8 +112,8 @@ private boolean hasEmptySession(Member member) { } public void createSession(Member member) { - var parentChannel = Bot.jda.getGuildChannelById(this.parentChannel); - var guild = Bot.jda.getGuildById(server); + var parentChannel = DiscordApp.jda.getGuildChannelById(this.parentChannel); + var guild = DiscordApp.jda.getGuildById(server); if(parentChannel == null || guild == null) return; if(parentChannel instanceof VoiceChannel vc) { diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/KitsunDebugger.java b/src/main/java/ru/pinkgoosik/kitsun/feature/KitsunDebugger.java deleted file mode 100644 index abca76b..0000000 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/KitsunDebugger.java +++ /dev/null @@ -1,47 +0,0 @@ -package ru.pinkgoosik.kitsun.feature; - -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import net.dv8tion.jda.api.events.session.ReadyEvent; -import ru.pinkgoosik.kitsun.Bot; - -import java.util.ArrayList; - -public class KitsunDebugger { - private static String debugChannel = "967506328190877726"; - public static final ArrayList CACHE = new ArrayList<>(); - - public static void onConnect(ReadyEvent event) { - if(event.getJDA().getSelfUser().getId().equals("935826731925913630")) debugChannel = "1081197875830206475"; - } - - public static void ping(String message) { - Bot.LOGGER.error(message); - sendMessage("<@287598520268095488>\n" + message); - } - - public static void report(String message) { - Bot.LOGGER.error(message); - sendMessage(message); - } - - public static void info(String text) { - Bot.LOGGER.info(text); - sendMessage(text); - } - - private static void sendMessage(String text) { -// for(String reported : CACHE) { -// if(reported.equals(text)) return; -// } - try { - if(Bot.jda.getGuildChannelById(debugChannel) instanceof TextChannel textChannel) { - textChannel.sendMessage(text).queue(); - } -// CACHE.add(text); - } - catch(Exception e) { - Bot.LOGGER.error("Failed to send debug message due to an exception:\n" + e); - } - } - -} diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/MCUpdatesPublisher.java b/src/main/java/ru/pinkgoosik/kitsun/feature/MCUpdatesPublisher.java index 7b15bbf..e5d9848 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/MCUpdatesPublisher.java +++ b/src/main/java/ru/pinkgoosik/kitsun/feature/MCUpdatesPublisher.java @@ -3,7 +3,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.api.mojang.MojangAPI; import ru.pinkgoosik.kitsun.api.mojang.PatchNotes; import ru.pinkgoosik.kitsun.api.mojang.VersionManifest; @@ -74,7 +74,7 @@ public void check(VersionManifest manifest) { private void publish(String version, String type) { ServerData.get(server).save(); - if(Bot.jda.getGuildChannelById(channel) instanceof TextChannel textChannel) { + if(DiscordApp.jda.getGuildChannelById(channel) instanceof TextChannel textChannel) { textChannel.sendMessageEmbeds(createEmbed(version, type)).queue(); } tryToPublishPatchNotes(version); @@ -96,7 +96,7 @@ private void tryToPublishPatchNotes(String version) { } private void publishPatchNotesEntry(PatchNotes.PatchNotesEntry entry) { - if(Bot.jda.getGuildChannelById(channel) instanceof TextChannel textChannel) { + if(DiscordApp.jda.getGuildChannelById(channel) instanceof TextChannel textChannel) { textChannel.sendMessageEmbeds(createPatchNotesEmbed(entry)).queue(); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/ModCard.java b/src/main/java/ru/pinkgoosik/kitsun/feature/ModCard.java index 3d97055..b1aa7dd 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/ModCard.java +++ b/src/main/java/ru/pinkgoosik/kitsun/feature/ModCard.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable; import ru.pinkgoosik.kitsun.api.curseforge.CurseForgeAPI; import ru.pinkgoosik.kitsun.api.curseforge.entity.CurseForgeMod; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.KitsunColors; import ru.pinkgoosik.kitsun.api.Modrinth; @@ -79,7 +80,7 @@ private void updateMessage(Message message, @Nullable Project project, @Nullable this.shouldBeRemoved = true; } else { - KitsunDebugger.report("Failed to update " + this.modrinthSlug + " card's message due to an exception:\n" + throwable); + KitsunDebugWebhook.report("Failed to update " + this.modrinthSlug + " card's message due to an exception:\n" + throwable); } }); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/ModUpdatesPublisher.java b/src/main/java/ru/pinkgoosik/kitsun/feature/ModUpdatesPublisher.java index f575033..c8639d6 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/ModUpdatesPublisher.java +++ b/src/main/java/ru/pinkgoosik/kitsun/feature/ModUpdatesPublisher.java @@ -6,9 +6,10 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.api.Modrinth; import ru.pinkgoosik.kitsun.cache.ServerData; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.KitsunColors; import java.util.ArrayList; @@ -60,9 +61,9 @@ private boolean updated(ArrayList versions) { private void publish(ArrayList versions, long delay) { ProjectVersion modVersion = versions.get(0); - if(Bot.jda.getGuildChannelById(channel) instanceof StandardGuildMessageChannel messageChannel) { + if(DiscordApp.jda.getGuildChannelById(channel) instanceof StandardGuildMessageChannel messageChannel) { messageChannel.sendMessageEmbeds(createEmbed(this.cachedProject, modVersion)).queueAfter(delay, TimeUnit.SECONDS, message -> {},throwable -> { - KitsunDebugger.ping("Failed to send update message of the " + this.project + " project due to an exception:\n" + throwable); + KitsunDebugWebhook.ping("Failed to send update message of the " + this.project + " project due to an exception:\n" + throwable); }); } latestVersion = modVersion.getId(); diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/QuiltUpdatesPublisher.java b/src/main/java/ru/pinkgoosik/kitsun/feature/QuiltUpdatesPublisher.java index 2230ce6..e885963 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/QuiltUpdatesPublisher.java +++ b/src/main/java/ru/pinkgoosik/kitsun/feature/QuiltUpdatesPublisher.java @@ -3,7 +3,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.api.QuiltMeta; import ru.pinkgoosik.kitsun.cache.ServerData; import ru.pinkgoosik.kitsun.util.KitsunColors; @@ -50,7 +50,7 @@ public void check() { private void publish(String version) { ServerData.get(server).save(); - if(Bot.jda.getGuildChannelById(channel) instanceof TextChannel textChannel) { + if(DiscordApp.jda.getGuildChannelById(channel) instanceof TextChannel textChannel) { textChannel.sendMessageEmbeds(createEmbed(version)).queue(); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/feature/ServerLogger.java b/src/main/java/ru/pinkgoosik/kitsun/feature/ServerLogger.java index 87fd5cd..5e82d3d 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/feature/ServerLogger.java +++ b/src/main/java/ru/pinkgoosik/kitsun/feature/ServerLogger.java @@ -9,7 +9,7 @@ import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import org.jetbrains.annotations.Nullable; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.event.DiscordEventsListener; import ru.pinkgoosik.kitsun.util.DurationUtils; import ru.pinkgoosik.kitsun.util.KitsunColors; @@ -121,7 +121,7 @@ public void onAutoChannelCreate(Member member, Channel voiceChannel) { } public void log(MessageEmbed embed) { - if(Bot.jda.getGuildChannelById(ChannelType.TEXT, channel) instanceof GuildMessageChannel chan) { + if(DiscordApp.jda.getGuildChannelById(ChannelType.TEXT, channel) instanceof GuildMessageChannel chan) { chan.sendMessageEmbeds(embed).queue(); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/http/GithubWebhook.java b/src/main/java/ru/pinkgoosik/kitsun/http/GithubWebhook.java index 13d9027..ebe2530 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/http/GithubWebhook.java +++ b/src/main/java/ru/pinkgoosik/kitsun/http/GithubWebhook.java @@ -1,8 +1,8 @@ package ru.pinkgoosik.kitsun.http; import com.sun.net.httpserver.HttpExchange; -import ru.pinkgoosik.kitsun.Bot; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.DiscordApp; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -15,7 +15,7 @@ public class GithubWebhook extends KitsunHttpHandler { public void handle(HttpExchange exchange) { var map = parseParams(exchange); - if(map.containsKey("token") && Bot.secrets.get().http.token.equals(map.get("token")) && exchange.getRequestMethod().equals("POST") && exchange.getRequestHeaders().containsKey("x-github-event")) { + if(map.containsKey("token") && DiscordApp.secrets.get().http.token.equals(map.get("token")) && exchange.getRequestMethod().equals("POST") && exchange.getRequestHeaders().containsKey("x-github-event")) { var event = exchange.getRequestHeaders().get("x-github-event").get(0); var is = exchange.getRequestBody(); StringBuilder textBuilder = new StringBuilder(); @@ -27,11 +27,11 @@ public void handle(HttpExchange exchange) { } } catch (Exception e) { - Bot.LOGGER.info("Failed to handle github webhook due to an exception: " + e); + DiscordApp.LOGGER.info("Failed to handle github webhook due to an exception: " + e); } String body = textBuilder.toString(); - KitsunDebugger.info(event + ": \n" + body); + KitsunDebugWebhook.info(event + ": \n" + body); success(exchange, "Accepted", 202); return; diff --git a/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpHandler.java b/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpHandler.java index cf49d88..b4ee36e 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpHandler.java +++ b/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpHandler.java @@ -2,7 +2,7 @@ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import java.io.OutputStream; import java.net.URLDecoder; @@ -31,7 +31,7 @@ static Map splitParams(String params) { } } catch (Exception e) { - Bot.LOGGER.error("Failed to split parameters: " + params + ", " + e); + DiscordApp.LOGGER.error("Failed to split parameters: " + params + ", " + e); } return queryPairs; } @@ -47,7 +47,7 @@ static void notFound(HttpExchange exchange) { exchange.close(); } catch (Exception e) { - Bot.LOGGER.error("Failed to send not found response " + e); + DiscordApp.LOGGER.error("Failed to send not found response " + e); } } @@ -59,7 +59,7 @@ static void success(HttpExchange exchange, String text) { os.close(); } catch (Exception e) { - Bot.LOGGER.error("Failed to send success response " + e); + DiscordApp.LOGGER.error("Failed to send success response " + e); } } @@ -71,7 +71,7 @@ static void success(HttpExchange exchange, String text, int status) { os.close(); } catch (Exception e) { - Bot.LOGGER.error("Failed to send success response " + e); + DiscordApp.LOGGER.error("Failed to send success response " + e); } } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpServer.java b/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpServer.java index 344d3a7..0c89f6b 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpServer.java +++ b/src/main/java/ru/pinkgoosik/kitsun/http/KitsunHttpServer.java @@ -1,16 +1,16 @@ package ru.pinkgoosik.kitsun.http; import com.sun.net.httpserver.HttpServer; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import java.net.InetSocketAddress; public class KitsunHttpServer { public static HttpServer server; public static void init() { - if(Bot.secrets.get().http.port > 0) { + if(DiscordApp.secrets.get().http.port > 0) { try { - HttpServer server = HttpServer.create(new InetSocketAddress(Bot.secrets.get().http.hostname, Bot.secrets.get().http.port), 0); + HttpServer server = HttpServer.create(new InetSocketAddress(DiscordApp.secrets.get().http.hostname, DiscordApp.secrets.get().http.port), 0); server.createContext("/github", new GithubWebhook()); server.createContext("/mod_update", new ModUpdateWebhook()); @@ -20,7 +20,7 @@ public static void init() { KitsunHttpServer.server = server; } catch (Exception e) { - Bot.LOGGER.error("Failed to setup http server due to an exception: " + e); + DiscordApp.LOGGER.error("Failed to setup http server due to an exception: " + e); } } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/http/ModUpdateWebhook.java b/src/main/java/ru/pinkgoosik/kitsun/http/ModUpdateWebhook.java index 43e2593..7766c65 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/http/ModUpdateWebhook.java +++ b/src/main/java/ru/pinkgoosik/kitsun/http/ModUpdateWebhook.java @@ -2,9 +2,9 @@ import com.sun.net.httpserver.HttpExchange; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.api.Modrinth; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.feature.ModUpdatesPublisher; import ru.pinkgoosik.kitsun.util.ChannelUtils; import ru.pinkgoosik.kitsun.util.ServerUtils; @@ -19,7 +19,7 @@ public class ModUpdateWebhook extends KitsunHttpHandler { public void handle(HttpExchange exchange) { var map = parseParams(exchange); - if (map.containsKey("token") && Bot.secrets.get().http.token.equals(map.get("token"))) { + if (map.containsKey("token") && DiscordApp.secrets.get().http.token.equals(map.get("token"))) { if(map.containsKey("server") && map.containsKey("project") && map.containsKey("channel")) { if (!ServerUtils.exist(map.get("server"))) { success(exchange, "Server not found"); @@ -38,10 +38,10 @@ public void handle(HttpExchange exchange) { var project = Modrinth.getProject(map.get("project")); var versions = Modrinth.getVersions(map.get("project")); - if(project.isPresent() && versions.isPresent() && !publishedVersions.contains(versions.get().get(0).getId()) && Bot.jda.getGuildChannelById(map.get("channel")) instanceof StandardGuildMessageChannel messageChannel) { + if(project.isPresent() && versions.isPresent() && !publishedVersions.contains(versions.get().get(0).getId()) && DiscordApp.jda.getGuildChannelById(map.get("channel")) instanceof StandardGuildMessageChannel messageChannel) { publishedVersions.add(versions.get().get(0).getId()); messageChannel.sendMessageEmbeds(ModUpdatesPublisher.createEmbed(project.get(), versions.get().get(0))).queue(message -> {}, throwable -> { - KitsunDebugger.ping("Failed to send update message of the " + project.get() + " project due to an exception:\n" + throwable); + KitsunDebugWebhook.ping("Failed to send update message of the " + project.get() + " project due to an exception:\n" + throwable); }); } } catch (Exception ignored) {} diff --git a/src/main/java/ru/pinkgoosik/kitsun/schedule/MCUpdatesScheduler.java b/src/main/java/ru/pinkgoosik/kitsun/schedule/MCUpdatesScheduler.java index e259bfc..e7ca243 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/schedule/MCUpdatesScheduler.java +++ b/src/main/java/ru/pinkgoosik/kitsun/schedule/MCUpdatesScheduler.java @@ -1,7 +1,7 @@ package ru.pinkgoosik.kitsun.schedule; import ru.pinkgoosik.kitsun.api.mojang.MojangAPI; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.ServerUtils; public class MCUpdatesScheduler { @@ -16,7 +16,7 @@ public static void schedule() { } catch(Exception e) { - KitsunDebugger.ping("Failed to schedule mc updates publishers duo to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to schedule mc updates publishers duo to an exception:\n" + e); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/schedule/ModCardsScheduler.java b/src/main/java/ru/pinkgoosik/kitsun/schedule/ModCardsScheduler.java index 8c9f7c6..5a2ba4d 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/schedule/ModCardsScheduler.java +++ b/src/main/java/ru/pinkgoosik/kitsun/schedule/ModCardsScheduler.java @@ -1,9 +1,9 @@ package ru.pinkgoosik.kitsun.schedule; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.cache.ServerData; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.feature.ModCard; import ru.pinkgoosik.kitsun.util.ServerUtils; @@ -18,7 +18,7 @@ public static void schedule() { ServerUtils.forEach(ModCardsScheduler::proceed); } catch(Exception e) { - KitsunDebugger.ping("Failed to schedule mod cards duo to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to schedule mod cards duo to an exception:\n" + e); } } @@ -32,13 +32,13 @@ private static void proceed(ServerData data) { for(var card : modCards) { index++; - if(Bot.jda.getGuildChannelById(card.channel) instanceof MessageChannel channel) { + if(DiscordApp.jda.getGuildChannelById(card.channel) instanceof MessageChannel channel) { channel.retrieveMessageById(card.message).queueAfter(index * 10L, TimeUnit.SECONDS, card::update, throwable -> { if(throwable.getMessage().contains("Unknown Message")) { card.shouldBeRemoved = true; } else { - KitsunDebugger.ping("Failed to get " + card.modrinthSlug + " card's message due to an exception:\n" + throwable); + KitsunDebugWebhook.ping("Failed to get " + card.modrinthSlug + " card's message due to an exception:\n" + throwable); } }); } diff --git a/src/main/java/ru/pinkgoosik/kitsun/schedule/ModUpdatesScheduler.java b/src/main/java/ru/pinkgoosik/kitsun/schedule/ModUpdatesScheduler.java index 15f33f1..0818752 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/schedule/ModUpdatesScheduler.java +++ b/src/main/java/ru/pinkgoosik/kitsun/schedule/ModUpdatesScheduler.java @@ -1,7 +1,7 @@ package ru.pinkgoosik.kitsun.schedule; import ru.pinkgoosik.kitsun.feature.ModUpdatesPublisher; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.cache.ServerData; import ru.pinkgoosik.kitsun.util.ServerUtils; @@ -18,7 +18,7 @@ public static void schedule() { ServerUtils.forEach(ModUpdatesScheduler::proceed); } catch(Exception e) { - KitsunDebugger.ping("Failed to schedule mod changelog publishers duo to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to schedule mod changelog publishers duo to an exception:\n" + e); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/schedule/QuiltUpdatesScheduler.java b/src/main/java/ru/pinkgoosik/kitsun/schedule/QuiltUpdatesScheduler.java index 96bc461..9994b24 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/schedule/QuiltUpdatesScheduler.java +++ b/src/main/java/ru/pinkgoosik/kitsun/schedule/QuiltUpdatesScheduler.java @@ -1,6 +1,6 @@ package ru.pinkgoosik.kitsun.schedule; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; +import ru.pinkgoosik.kitsun.debug.KitsunDebugWebhook; import ru.pinkgoosik.kitsun.util.ServerUtils; public class QuiltUpdatesScheduler { @@ -14,7 +14,7 @@ public static void schedule() { }); } catch(Exception e) { - KitsunDebugger.ping("Failed to schedule quilt updates publishers duo to an exception:\n" + e); + KitsunDebugWebhook.ping("Failed to schedule quilt updates publishers duo to an exception:\n" + e); } } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/schedule/Scheduler.java b/src/main/java/ru/pinkgoosik/kitsun/schedule/Scheduler.java index b45b384..cc469b8 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/schedule/Scheduler.java +++ b/src/main/java/ru/pinkgoosik/kitsun/schedule/Scheduler.java @@ -1,7 +1,5 @@ package ru.pinkgoosik.kitsun.schedule; -import ru.pinkgoosik.kitsun.feature.KitsunDebugger; - import java.util.*; public class Scheduler { diff --git a/src/main/java/ru/pinkgoosik/kitsun/util/ChannelUtils.java b/src/main/java/ru/pinkgoosik/kitsun/util/ChannelUtils.java index 70536dd..33ebd67 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/util/ChannelUtils.java +++ b/src/main/java/ru/pinkgoosik/kitsun/util/ChannelUtils.java @@ -1,14 +1,14 @@ package ru.pinkgoosik.kitsun.util; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import java.util.Optional; public class ChannelUtils { public static boolean exist(String serverId, String channelId) { - var guild = Bot.jda.getGuildById(serverId); + var guild = DiscordApp.jda.getGuildById(serverId); if(guild != null) { var channel = guild.getGuildChannelById(channelId); @@ -29,7 +29,7 @@ public static boolean exist(String serverId, String channelId) { } public static boolean isVoiceChannel(String serverId, String channelId) { - var guild = Bot.jda.getGuildById(serverId); + var guild = DiscordApp.jda.getGuildById(serverId); if(guild != null) { var channel = guild.getGuildChannelById(channelId); diff --git a/src/main/java/ru/pinkgoosik/kitsun/util/SelfUtils.java b/src/main/java/ru/pinkgoosik/kitsun/util/SelfUtils.java index cbf0154..93bfea0 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/util/SelfUtils.java +++ b/src/main/java/ru/pinkgoosik/kitsun/util/SelfUtils.java @@ -1,10 +1,10 @@ package ru.pinkgoosik.kitsun.util; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; public class SelfUtils { public static String getId() { - return Bot.jda.getSelfUser().getId(); + return DiscordApp.jda.getSelfUser().getId(); } } diff --git a/src/main/java/ru/pinkgoosik/kitsun/util/ServerUtils.java b/src/main/java/ru/pinkgoosik/kitsun/util/ServerUtils.java index 955cdc4..a598464 100644 --- a/src/main/java/ru/pinkgoosik/kitsun/util/ServerUtils.java +++ b/src/main/java/ru/pinkgoosik/kitsun/util/ServerUtils.java @@ -1,19 +1,19 @@ package ru.pinkgoosik.kitsun.util; -import ru.pinkgoosik.kitsun.Bot; +import ru.pinkgoosik.kitsun.DiscordApp; import ru.pinkgoosik.kitsun.cache.ServerData; public class ServerUtils { public static void forEach(ServerRunnable runnable) { - Bot.jda.getGuilds().forEach(guild -> { + DiscordApp.jda.getGuilds().forEach(guild -> { String serverId = guild.getId(); runnable.run(ServerData.get(serverId)); }); } public static void runFor(String serverId, ServerRunnable runnable) { - Bot.jda.getGuilds().forEach(guild -> { + DiscordApp.jda.getGuilds().forEach(guild -> { if(guild.getId().equals(serverId)) { runnable.run(ServerData.get(serverId)); } @@ -21,7 +21,7 @@ public static void runFor(String serverId, ServerRunnable runnable) { } public static boolean exist(String serverId) { - for(var guild : Bot.jda.getGuilds()) { + for(var guild : DiscordApp.jda.getGuilds()) { if(guild.getId().equals(serverId)) return true; } return false;