From 6174a46622c7b45089ebc7485099d0243f4faf2a Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:23:09 +0200 Subject: [PATCH 001/845] Create README.md --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..8b906d47 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +
+ + + ![GitHub Release](https://img.shields.io/github/v/release/Vxrpenter/SCPToolsBot?include_prereleases&sort=date&display_name=tag&style=for-the-badge&label=LATEST%20RELEASE&color=%23802af9)  + ![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/vxrpenter/ScpToolsBot/total?style=for-the-badge&color=%2323802af9)  + + | Languages | Api's | + | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | Java yaml  | jda apachecommons  | +
+ +## What is ScpToolsBot +ScpToolsBot is a discord bot application written in Java for Scp Secret Laboratory discord servers. It includes support functions, cedmod api syncing, community and even team management features + +## Installation +1. Download the `.jar` file from the latest **STABLE** release +2. Install `JDK-17` or higher on your machine +3. Run the jar using `java -jar ` +4. The process will automatically crash and create two new folders called `configs` and `translations`. Go into the `configs` folder and edit the `config.yml` file +5. After putting in required info start the bot again and it should be running + +## Handling Issues +**Bot not starting, why?** +- Outdated JDK, install higher version +- Missing token or guild ID in config + +--- + +**Got error: _"Couldn't commence HTTP request to get banID, is the user banned?"_** + +This means that no banId could be found meaning that the user isn't banned + +--- + +**Got error: _"Unbanning of ID failed, does it exist?"_** + +This means that the unban process failed because the user is not banned/the ban id is invalid and does not exist + +--- +> [!NOTE] +> If you are getting an error, not stated in this explanation and or not able to fix it, please create an issue so the issue can be resolved From d397f1754eaa6923e0969ad68687dc8db3c3a789 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:40:38 +0200 Subject: [PATCH 002/845] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b906d47..bd82a89d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@
- ![GitHub Release](https://img.shields.io/github/v/release/Vxrpenter/SCPToolsBot?include_prereleases&sort=date&display_name=tag&style=for-the-badge&label=LATEST%20RELEASE&color=%23802af9)  - ![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/vxrpenter/ScpToolsBot/total?style=for-the-badge&color=%2323802af9)  + ![GitHub Release](https://img.shields.io/github/v/release/Vxrpenter/SCPToolsBot?include_prereleases&sort=date&display_name=tag&style=for-the-badge&label=LATEST%20RELEASE&color=%23c9631f)  + ![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/vxrpenter/ScpToolsBot/total?style=for-the-badge&color=%23c9631f)  | Languages | Api's | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | From 4551ba6d62d2a10331746963ce41cf5fab06e855 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:46:30 +0200 Subject: [PATCH 003/845] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd82a89d..4bed30dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
- ![GitHub Release](https://img.shields.io/github/v/release/Vxrpenter/SCPToolsBot?include_prereleases&sort=date&display_name=tag&style=for-the-badge&label=LATEST%20RELEASE&color=%23c9631f)  +   ![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/vxrpenter/ScpToolsBot/total?style=for-the-badge&color=%23c9631f)  | Languages | Api's | From 3a0f9b729085816f0c338e6eed2668574f6bce76 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:01:58 +0200 Subject: [PATCH 004/845] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..f2d1ae45 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Vxrpenter + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 18b58d6c56d044758486f43d15040d280f7c28e9 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:53:20 +0200 Subject: [PATCH 005/845] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bed30dc..0c70e871 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,4 @@ This means that the unban process failed because the user is not banned/the ban --- > [!NOTE] -> If you are getting an error, not stated in this explanation and or not able to fix it, please create an issue so the issue can be resolved +> If you are getting an error, not stated in this documentation and are not able to fix it, please create an issue so the issue can be resolved From 01c37db351871c30c6f04fde5938f9c781fa4fa0 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 15 Oct 2024 22:11:39 +0200 Subject: [PATCH 006/845] Unban system fully working --- README.md | 8 +-- .../commands/templates/TemplateCommand.java | 3 +- .../{ => rules}/RulesTemplateUnit.java | 3 +- .../templates}/support/Support.java | 2 +- .../vxrp/bot/config/util/TRANSLATIONS.java | 3 ++ .../dev/vxrp/bot/events/buttons/Rules.java | 2 +- .../dev/vxrp/bot/events/buttons/Unban.java | 6 +-- .../dev/vxrp/bot/events/modals/Support.java | 2 +- .../dev/vxrp/bot/events/modals/Unban.java | 51 +++++++++++++++++++ .../resources/translations/translations.yml | 30 +++++++++-- 10 files changed, 92 insertions(+), 18 deletions(-) rename src/main/java/dev/vxrp/bot/commands/templates/{ => rules}/RulesTemplateUnit.java (95%) rename src/main/java/dev/vxrp/bot/{ => commands/templates}/support/Support.java (97%) diff --git a/README.md b/README.md index 0c70e871..f412dc8b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@
- + ScpToolsBot   ![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/vxrpenter/ScpToolsBot/total?style=for-the-badge&color=%23c9631f)  - | Languages | Api's | - | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - | Java yaml  | jda apachecommons  | + | Languages | Api's | + |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + | Java yaml  | jda apachecommons  |
## What is ScpToolsBot diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index 39cf954e..a0900c73 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -1,10 +1,9 @@ package dev.vxrp.bot.commands.templates; -import dev.vxrp.bot.support.Support; +import dev.vxrp.bot.commands.templates.support.Support; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.slf4j.Logger; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java similarity index 95% rename from src/main/java/dev/vxrp/bot/commands/templates/RulesTemplateUnit.java rename to src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index 8e8d20d2..09d119c8 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.commands.templates; +package dev.vxrp.bot.commands.templates.rules; import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.util.CONFIG; @@ -9,7 +9,6 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.util.List; diff --git a/src/main/java/dev/vxrp/bot/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java similarity index 97% rename from src/main/java/dev/vxrp/bot/support/Support.java rename to src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index 37d8ed68..be8f4cc2 100644 --- a/src/main/java/dev/vxrp/bot/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.support; +package dev.vxrp.bot.commands.templates.support; import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; diff --git a/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java index 5d6e1548..67f8b15a 100644 --- a/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java @@ -36,6 +36,9 @@ public static final class TICKET { public static final String UNBAN_BODY = "support.ticket_unban_body"; public static final String UNBAN_FOOTER = "support.ticket_unban_footer"; public static final String UNBAN_CREATED = "support.ticket_unban_created"; + public static final String UNBAN_MESSAGE_ACCEPTED = "support.ticket_unban_message_accepted"; + public static final String UNBAN_MESSAGE_DISMISSED = "support.ticket_unban_message_dismissed"; + public static final String UNBAN_MESSAGE_SENT = "support.ticket_unban_message_sent"; } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Rules.java b/src/main/java/dev/vxrp/bot/events/buttons/Rules.java index 55ced862..e152efb9 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Rules.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Rules.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.events.buttons; import org.slf4j.Logger; -import dev.vxrp.bot.commands.templates.RulesTemplateUnit; +import dev.vxrp.bot.commands.templates.rules.RulesTemplateUnit; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import java.util.Objects; diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 410cfbcd..5887f4f4 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -9,7 +9,6 @@ import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; import net.dv8tion.jda.api.interactions.modals.Modal; -import java.io.IOException; import java.util.Objects; public class Unban { @@ -34,16 +33,15 @@ public static void createUnbanTicket(ButtonInteractionEvent event, TranslationMa } public static void dismissTicket(ButtonInteractionEvent event, TranslationManager translationManager, User user) { + String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_unban_dismiss:"+user.getId()+":"+event.getMessageId()+":", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)) + Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)) .addComponents(ActionRow.of(shortModal( "reason_action_reason", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_TITLE), translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_PLACEHOLDER), 10, 100 ))).build()).queue(); - - event.getMessage().delete().queue(); } public static void acceptTicket(ButtonInteractionEvent event, TranslationManager translationManager, User user) { diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 3afeed82..d80a4eb4 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -109,7 +109,7 @@ public static void createUnbanTicket(ModalInteractionEvent event, TranslationMan event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( Button.success("accept_support_ticket:"+userID+":"+steamID+":", "Accept Ticket"), - Button.danger("dismiss_unban_ticket:"+userID+":", "Dismiss Ticket"), + Button.danger("dismiss_unban_ticket:"+userID+":"+steamID+":", "Dismiss Ticket"), Button.secondary("settings_unban_ticket", "Settings") ).queue(); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index b734df58..8b740fba 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -2,7 +2,9 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.util.CONFIG; +import dev.vxrp.bot.config.util.TRANSLATIONS; import dev.vxrp.bot.util.cedmod.CedModApi; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; @@ -24,9 +26,58 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { String banListID = ScpTools.getConfigManager().getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID); String banID = CedModApi.getBanId(instanceUrl, apiKey, banListID, steamID); + bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( + builderAccepted(bannedUser.getGlobalName()).build(), + new EmbedBuilder() + .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_ACCEPTED) + .replace("%steamID%", steamID) + .replace("%reason%", reason)) + .build() + )).queue(); + CedModApi.executeUnban(instanceUrl, apiKey, banID, reason); + + event.reply(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT)).setEphemeral(true).queue(); } public static void dismissUnban(ModalInteractionEvent event) { + String messageID = event.getModalId().split(":")[3]; + Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); + + User bannedUser = Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getMemberById(event.getModalId().split(":")[1])).getUser(); + String steamID = event.getModalId().split(":")[2]; + String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); + + bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( + builderDismissed(event.getUser().getGlobalName()).build(), + new EmbedBuilder() + .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED) + .replace("%steamID%", steamID) + .replace("%reason%", reason)) + .build() + )).queue(); + + event.reply(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT)).setEphemeral(true).queue(); + } + + private static EmbedBuilder builderDismissed(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Answer: Dismissed ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" +  + ``` + """); + } + private static EmbedBuilder builderAccepted(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Answer: Accepted ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" +  + ``` + """); } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index e0517c0b..725d59d9 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -66,8 +66,8 @@ support: ticket_unban_body: " Unban Request is getting reviewed. A response from our moderation team may take a bit\n - __**Steam ID:**__ - ||%steamID%|| + __**Steam ID:**__\n + ||%steamID%||\n __**Ban Reason:**__\n ```%reason%``` @@ -76,4 +76,28 @@ support: ```%reasoning%``` " ticket_unban_footer: "Created on the %date% at %time%h" - ticket_unban_created: "Your unban request has been issued" \ No newline at end of file + ticket_unban_created: "Your unban request has been issued" + + ticket_unban_message_accepted: " + Your unban request under the steam ID (see down below) was accepted. You may now join the + server again without any punishment. We are sorry for the inconvenience and hope that you + will enjoy our Server again\n + + __**Steam ID:**__\n + ||%steamID%||\n + + __**Acceptance Reason:**__\n + ```%reason%``` + " + ticket_unban_message_dismissed: " + Your unban request under the steam ID (see down below) was dismissed, you may not appeal this + ban again until given permission by server administration or if this case resolves and another + one arises\n + + __**Steam ID:**__\n + ||%steamID%||\n + + __**Dismiss Reason:**__\n + ```%reason%``` + " + ticket_unban_message_sent: "Your answer was sent and actions corresponding to it have been taken" \ No newline at end of file From d88edb60e9f401fe21b252c663bb10733be44c82 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:32:38 +0200 Subject: [PATCH 007/845] Improved logger unit and added choices for coming features --- src/main/java/dev/vxrp/bot/commands/CommandManager.java | 8 ++++++-- .../dev/vxrp/bot/commands/templates/TemplateCommand.java | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index 0771aade..57a6d032 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -35,7 +35,11 @@ public void Initialize(JDA api) { .setDefaultPermissions(DefaultMemberPermissions.enabledFor(new PermissionListConverter(templateDefaultPermissions).convert())) .addOptions( new OptionData(OptionType.STRING, "template", "What template are you referring to", true) - .addChoice("rules", "rules").addChoice("support", "support") + .addChoice("rules", "rules") + .addChoice("support", "support") + .addChoice("deregistration", "deregistration") + .addChoice("regulars", "regulars") + .addChoice("adminpanel", "adminpanel") )); } for (String command : activeCommands) { @@ -43,4 +47,4 @@ public void Initialize(JDA api) { logger.info("Initialized command: {}", command); } } -} +} \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index a0900c73..be76385f 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -26,11 +26,13 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { Button.danger("update_rules", "Update Rules") ) .setEphemeral(true).queue(); - logger.info("User {} executed command template with args 'rules'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName())); } if (template.equals("support")) { Support.pasteSupportTemplate(Objects.requireNonNull(event.getGuild()), event.getChannelId()); - logger.info("User {} executed command template with args 'support'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName())); } + if (template.equals("deregistration")) { + + } + logger.info("User {} executed command template with args '{}'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName()), template); } } From efcedf0aa1d3e56755e7a23b31aec042742fa849 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:39:05 +0200 Subject: [PATCH 008/845] Little improvement to the commands working with fewer variables --- .../bot/commands/templates/TemplateCommand.java | 3 ++- .../templates/rules/RulesTemplateUnit.java | 7 +++---- .../bot/commands/templates/support/Support.java | 17 +++++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index be76385f..d2d73583 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.commands.templates; +import dev.vxrp.bot.commands.templates.deregistration.DeRegistration; import dev.vxrp.bot.commands.templates.support.Support; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; @@ -31,7 +32,7 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { Support.pasteSupportTemplate(Objects.requireNonNull(event.getGuild()), event.getChannelId()); } if (template.equals("deregistration")) { - + DeRegistration.pasteDeRegisterTemplate(); } logger.info("User {} executed command template with args '{}'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName()), template); } diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index 09d119c8..aacefe09 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -9,6 +9,7 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import java.io.IOException; import java.util.List; @@ -30,10 +31,8 @@ private static EmbedBuilder embed(Guild guild, TextChannel channel) { .setFooter(ScpTools.getConfigManager().getString(CONFIG.RULES.EMBED_FOOTER), guild.getIconUrl()); } - public static void pasteRules(Guild guild, String channelID) { - TextChannel channel = guild.getTextChannelById(channelID); - assert channel != null; - channel.sendMessageEmbeds(Objects.requireNonNull(embed(guild, channel)).build()).queue(); + public static void pasteRules(SlashCommandInteractionEvent event) { + event.getChannel().sendMessageEmbeds(Objects.requireNonNull(embed(event.getGuild(), event.getChannel().asTextChannel())).build()).queue(); } public static void updateRules(Guild guild, String channelID,String messageId) { TextChannel channel = guild.getTextChannelById(channelID); diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index be8f4cc2..938ebaf2 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -6,6 +6,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import java.awt.*; @@ -14,15 +15,15 @@ public class Support { private static final TranslationManager translationManager = ScpTools.getTranslationManager(); - public static void pasteSupportTemplate(Guild guild, String ChannelID) { - Objects.requireNonNull(guild.getTextChannelById(ChannelID)).sendMessageEmbeds(new EmbedBuilder() - .setColor(Color.decode("#5865F2")) - .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)) - .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY)) - .setColor(Color.DARK_GRAY) - .build()) + public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { + event.getChannel().sendMessageEmbeds(new EmbedBuilder() + .setColor(Color.decode("#5865F2")) + .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)) + .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY)) + .setColor(Color.DARK_GRAY) + .build()) .queue(); - Objects.requireNonNull(guild.getTextChannelById(ChannelID)).sendMessageEmbeds(new EmbedBuilder() + event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE)) .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY)) From 86a601173dcd284a1626696cc5c872ade0ec4041 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:40:36 +0200 Subject: [PATCH 009/845] Made TemplateCommand work with the templates again --- .../java/dev/vxrp/bot/commands/templates/TemplateCommand.java | 4 ++-- src/main/java/dev/vxrp/bot/events/ButtonListener.java | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index d2d73583..b2143e0e 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -29,10 +29,10 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { .setEphemeral(true).queue(); } if (template.equals("support")) { - Support.pasteSupportTemplate(Objects.requireNonNull(event.getGuild()), event.getChannelId()); + Support.pasteSupportTemplate(event); } if (template.equals("deregistration")) { - DeRegistration.pasteDeRegisterTemplate(); + DeRegistration.pasteDeRegisterTemplate(event); } logger.info("User {} executed command template with args '{}'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName()), template); } diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index eae18f14..a278c5eb 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -11,8 +11,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - public class ButtonListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ButtonListener.class); TranslationManager translationManager = ScpTools.getTranslationManager(); From 11f9c2d1dd465e1290fe307a107dd4b08596f2a7 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:46:48 +0200 Subject: [PATCH 010/845] Moved methods to their responding classes --- .../dev/vxrp/bot/events/modals/Support.java | 60 +----------- .../dev/vxrp/bot/events/modals/Unban.java | 94 ++++++++++++++----- .../vxrp/bot/util/builder/StatsBuilder.java | 36 +++++++ 3 files changed, 111 insertions(+), 79 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index d80a4eb4..b72547dd 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -5,6 +5,7 @@ import dev.vxrp.bot.config.util.CONFIG; import dev.vxrp.bot.config.util.TRANSLATIONS; import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; @@ -50,7 +51,7 @@ public static void createSupportTicket(ModalInteractionEvent event, TranslationM .grant(EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND)) .queue(); } - textChannel.sendMessageEmbeds(builderStatus(userName).build()).queue(); + textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); textChannel.sendMessageEmbeds( builder(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_TITLE).replace("%name%", name), translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY) .replace("%subject%", subject) @@ -68,53 +69,6 @@ public static void createSupportTicket(ModalInteractionEvent event, TranslationM logger.info("Created new support ticket by user {} - under name {}", ColorTool.apply(DCColor.GREEN, userName), ColorTool.apply(DCColor.RED, name)); } - public static void createUnbanTicket(ModalInteractionEvent event, TranslationManager translationManager, Logger logger) { - Member member = event.getMember(); - assert member != null; - String userName = Objects.requireNonNull(member.getUser().getGlobalName()); - String userID = Objects.requireNonNull(member.getUser().getId()); - Guild guild = event.getGuild(); - if (guild == null) return; - - String steamID = Objects.requireNonNull(event.getValue("unban_steamID")).getAsString(); - String reason = Objects.requireNonNull(event.getValue("unban_ban_reason")).getAsString(); - String reasoning = Objects.requireNonNull(event.getValue("unban_reasoning")).getAsString(); - String name = "Request #" + ThreadLocalRandom.current().nextInt(1535, 75808); - String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); - String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); - - TextChannel textChannel = event.getGuild().getTextChannelById(ScpTools.getConfigManager().getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID)); - - assert textChannel != null; - event.reply(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_CREATED) - .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); - - List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_UNBAN_TICKETS); - for (String id : roleIDs) { - textChannel.upsertPermissionOverride( - Objects.requireNonNull(guild.getRoleById(id))) - .grant(EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND)) - .queue(); - } - textChannel.sendMessageEmbeds( - builderStatus(userName).build(), - builder(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_TITLE).replace("%name%", name), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_BODY) - .replace("%steamID%", steamID) - .replace("%reason%", reason) - .replace("%reasoning%", reasoning), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_FOOTER) - .replace("%date%", date) - .replace("%time%", time), - event.getGuild().getIconUrl(), event.getUser()).build()) - .addActionRow( - Button.success("accept_support_ticket:"+userID+":"+steamID+":", "Accept Ticket"), - Button.danger("dismiss_unban_ticket:"+userID+":"+steamID+":", "Dismiss Ticket"), - Button.secondary("settings_unban_ticket", "Settings") - ).queue(); - - logger.info("Created new unban request by user {} - under name {}", ColorTool.apply(DCColor.GREEN, userName), ColorTool.apply(DCColor.RED, name)); - } private static EmbedBuilder builder(String title, String body, String footerText, String IconURL, User user) { EmbedBuilder builder = new EmbedBuilder(); @@ -125,15 +79,5 @@ private static EmbedBuilder builder(String title, String body, String footerText builder.setFooter(footerText, IconURL); return builder; } - private static EmbedBuilder builderStatus(String username) { - return new EmbedBuilder() - .setDescription(""" - ```ansi - ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Status: Open ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s - ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Handler: None | Creator: """ +username+""" -  - ``` - """); - } } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 8b740fba..da09326c 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,17 +1,80 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.CONFIG; import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.cedmod.CedModApi; +import dev.vxrp.bot.util.colors.ColorTool; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import org.slf4j.Logger; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.EnumSet; +import java.util.List; import java.util.Objects; +import java.util.concurrent.ThreadLocalRandom; public class Unban { + public static void createUnbanTicket(ModalInteractionEvent event, TranslationManager translationManager, Logger logger) { + Member member = event.getMember(); + assert member != null; + String userName = Objects.requireNonNull(member.getUser().getGlobalName()); + String userID = Objects.requireNonNull(member.getUser().getId()); + Guild guild = event.getGuild(); + if (guild == null) return; + + String steamID = Objects.requireNonNull(event.getValue("unban_steamID")).getAsString(); + String reason = Objects.requireNonNull(event.getValue("unban_ban_reason")).getAsString(); + String reasoning = Objects.requireNonNull(event.getValue("unban_reasoning")).getAsString(); + String name = "Request #" + ThreadLocalRandom.current().nextInt(1535, 75808); + String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); + String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); + + TextChannel textChannel = event.getGuild().getTextChannelById(ScpTools.getConfigManager().getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID)); + + assert textChannel != null; + event.reply(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_CREATED) + .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); + + List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_UNBAN_TICKETS); + for (String id : roleIDs) { + textChannel.upsertPermissionOverride( + Objects.requireNonNull(guild.getRoleById(id))) + .grant(EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND)) + .queue(); + } + textChannel.sendMessageEmbeds( + StatsBuilder.buildStatus(userName).build(), + builder(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_TITLE).replace("%name%", name), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_BODY) + .replace("%steamID%", steamID) + .replace("%reason%", reason) + .replace("%reasoning%", reasoning), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_FOOTER) + .replace("%date%", date) + .replace("%time%", time), + event.getGuild().getIconUrl(), event.getUser()).build()) + .addActionRow( + Button.success("accept_support_ticket:"+userID+":"+steamID+":", "Accept Ticket"), + Button.danger("dismiss_unban_ticket:"+userID+":"+steamID+":", "Dismiss Ticket"), + Button.secondary("settings_unban_ticket", "Settings") + ).queue(); + + logger.info("Created new unban request by user {} - under name {}", ColorTool.apply(DCColor.GREEN, userName), ColorTool.apply(DCColor.RED, name)); + } + public static void acceptUnban(ModalInteractionEvent event) throws IOException { String messageID = event.getModalId().split(":")[3]; @@ -27,7 +90,7 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { String banID = CedModApi.getBanId(instanceUrl, apiKey, banListID, steamID); bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( - builderAccepted(bannedUser.getGlobalName()).build(), + StatsBuilder.buildAccepted(bannedUser.getGlobalName()).build(), new EmbedBuilder() .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_ACCEPTED) .replace("%steamID%", steamID) @@ -49,7 +112,7 @@ public static void dismissUnban(ModalInteractionEvent event) { String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( - builderDismissed(event.getUser().getGlobalName()).build(), + StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED) .replace("%steamID%", steamID) @@ -60,24 +123,13 @@ public static void dismissUnban(ModalInteractionEvent event) { event.reply(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT)).setEphemeral(true).queue(); } - private static EmbedBuilder builderDismissed(String username) { - return new EmbedBuilder() - .setDescription(""" - ```ansi - ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Answer: Dismissed ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s - ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" -  - ``` - """); - } - private static EmbedBuilder builderAccepted(String username) { - return new EmbedBuilder() - .setDescription(""" - ```ansi - ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Answer: Accepted ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s - ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" -  - ``` - """); + private static EmbedBuilder builder(String title, String body, String footerText, String IconURL, User user) { + EmbedBuilder builder = new EmbedBuilder(); + + builder.setThumbnail(user.getAvatarUrl()); + builder.setTitle(title); + builder.setDescription(body); + builder.setFooter(footerText, IconURL); + return builder; } } diff --git a/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java b/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java new file mode 100644 index 00000000..3c603056 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java @@ -0,0 +1,36 @@ +package dev.vxrp.bot.util.builder; + +import net.dv8tion.jda.api.EmbedBuilder; + +public class StatsBuilder { + public static EmbedBuilder buildStatus(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Status: Open ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Handler: None | Creator: """ +username+""" +  + ``` + """); + } + public static EmbedBuilder buildDismissed(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Answer: Dismissed ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" +  + ``` + """); + } + public static EmbedBuilder buildAccepted(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Ticket Answer: Accepted ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" +  + ``` + """); + } +} From 42f6972c5d4af574c7a7b9b938b3fa9fd7ea2dd2 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:49:02 +0200 Subject: [PATCH 011/845] Fixed some issues created in the latest commits --- .../vxrp/bot/commands/templates/rules/RulesTemplateUnit.java | 3 ++- src/main/java/dev/vxrp/bot/events/ModalListener.java | 2 +- src/main/java/dev/vxrp/bot/events/buttons/Rules.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index aacefe09..07e38a97 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import java.io.IOException; import java.util.List; @@ -31,7 +32,7 @@ private static EmbedBuilder embed(Guild guild, TextChannel channel) { .setFooter(ScpTools.getConfigManager().getString(CONFIG.RULES.EMBED_FOOTER), guild.getIconUrl()); } - public static void pasteRules(SlashCommandInteractionEvent event) { + public static void pasteRules(ButtonInteractionEvent event) { event.getChannel().sendMessageEmbeds(Objects.requireNonNull(embed(event.getGuild(), event.getChannel().asTextChannel())).build()).queue(); } public static void updateRules(Guild guild, String channelID,String messageId) { diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index e8299c35..31a9e2d3 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -21,7 +21,7 @@ public void onModalInteraction(ModalInteractionEvent event) { Support.createSupportTicket(event, translationManager, logger); } if (event.getModalId().equals("unbanTicket")) { - Support.createUnbanTicket(event, translationManager, logger); + Unban.createUnbanTicket(event, translationManager, logger); } if (event.getModalId().startsWith("reason_action_unban_accept")) { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Rules.java b/src/main/java/dev/vxrp/bot/events/buttons/Rules.java index e152efb9..36a43a29 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Rules.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Rules.java @@ -10,7 +10,7 @@ public class Rules { public static void paste(Logger logger, ButtonInteractionEvent event) { event.reply("Pasting rules...").setEphemeral(true).queue(); logger.warn("Rule pasting might take a while and the usage of the parser may create performance issues"); - RulesTemplateUnit.pasteRules(Objects.requireNonNull(event.getGuild()), event.getChannelId()); + RulesTemplateUnit.pasteRules(event); } public static void update(Logger logger, ButtonInteractionEvent event) { RulesTemplateUnit.updateRules(Objects.requireNonNull(event.getGuild()),event.getChannelId(), event.getMessageId()); From c355be778ea3de3c386773f6017542afe0bd3519 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:59:17 +0200 Subject: [PATCH 012/845] Removed unused imports, methods, exceptions --- .idea/misc.xml | 4 --- src/main/java/dev/vxrp/bot/ScpTools.java | 4 +-- .../deregistration/DeRegistration.java | 32 +++++++++++++++++++ .../templates/rules/RulesTemplateUnit.java | 1 - .../commands/templates/support/Support.java | 2 -- .../bot/config/managers/ConfigManager.java | 6 ---- .../config/managers/TranslationManager.java | 1 - .../dev/vxrp/bot/events/ButtonListener.java | 8 +++-- .../dev/vxrp/bot/events/modals/Support.java | 1 - .../dev/vxrp/bot/util/colors/ColorTool.java | 4 --- 10 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 81458116..fe0b0dab 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,5 @@ - - diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index ac611845..8e455cdf 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -9,7 +9,6 @@ import dev.vxrp.bot.config.util.CONFIG; import dev.vxrp.bot.config.managers.ConfigManager; import dev.vxrp.bot.events.ModalListener; -import dev.vxrp.bot.util.cedmod.CedModApi; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.Enums.DCColor; import net.dv8tion.jda.api.JDA; @@ -21,7 +20,6 @@ import org.slf4j.LoggerFactory; import java.io.File; -import java.io.IOException; import java.nio.file.Paths; import java.util.*; @@ -31,7 +29,7 @@ public class ScpTools { static ColorConfigManager colorConfigManager; public final static Logger logger = LoggerFactory.getLogger(ScpTools.class); - public static void main(String[] args) throws IOException { + public static void main(String[] args) { List folders = Arrays.asList("configs", "translations"); for (String folder : folders) { String folderPath = Paths.get(folder).toString(); diff --git a/src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java b/src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java new file mode 100644 index 00000000..762ea646 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java @@ -0,0 +1,32 @@ +package dev.vxrp.bot.commands.templates.deregistration; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.config.util.TRANSLATIONS; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; + +import java.awt.*; + +public class DeRegistration { + private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + + public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { + event.getChannel().sendMessageEmbeds(new EmbedBuilder() + .setColor(Color.decode("#5865F2")) + .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)) + .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY)) + .setColor(Color.DARK_GRAY) + .build()) + .queue(); + event.getChannel().sendMessageEmbeds(new EmbedBuilder() + .setColor(Color.decode("#5865F2")) + .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE)) + .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY)) + .setColor(Color.DARK_GRAY) + .build()) + .addActionRow( + + ).queue(); + } +} diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index 07e38a97..b1dc9692 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -9,7 +9,6 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import java.io.IOException; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index 938ebaf2..03d157f3 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -4,13 +4,11 @@ import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.TRANSLATIONS; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import java.awt.*; -import java.util.Objects; public class Support { private static final TranslationManager translationManager = ScpTools.getTranslationManager(); diff --git a/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java b/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java index 2f3dd106..1b508331 100644 --- a/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java +++ b/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java @@ -31,15 +31,9 @@ private YamlConfiguration getYamlConfig() { final File file = new File(configPath.toString()); return YamlConfiguration.loadConfiguration(file); } - public Object getObject(String key) { - return getYamlConfig().getConfigurationSection(key); - } public String getString(String key) { return getYamlConfig().getString(key); } - public int getInt(String key) { - return getYamlConfig().getInt(key); - } public boolean getBoolean(String key) { return getYamlConfig().getBoolean(key); } diff --git a/src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java b/src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java index fed45c12..e67a2346 100644 --- a/src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java +++ b/src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java @@ -8,7 +8,6 @@ import java.io.InputStream; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; public class TranslationManager { public final Path configPath = Paths.get("./translations/translation.yml"); diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index a278c5eb..4ba3a02a 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -46,11 +46,15 @@ public void onButtonInteraction(ButtonInteractionEvent event) { } if (event.getComponentId().startsWith("accept_support_ticket")) { User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); - Unban.acceptTicket(event, translationManager, user); + if (user != null) { + Unban.acceptTicket(event, translationManager, user); + } } if (event.getComponentId().startsWith("dismiss_unban_ticket")) { User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); - Unban.dismissTicket(event, translationManager, user); + if (user != null) { + Unban.dismissTicket(event, translationManager, user); + } } if (event.getComponentId().equals("settings_unban_ticket")) { //WIP diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index b72547dd..f2cda47c 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -12,7 +12,6 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.slf4j.Logger; diff --git a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java index 33e6e00d..f9418818 100644 --- a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java +++ b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java @@ -1,10 +1,6 @@ package dev.vxrp.bot.util.colors; -import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.Enums.SLColors; - -import java.util.*; public class ColorTool { From f195001040588f21d775b4065e3b8285b0214c11 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:14:07 +0200 Subject: [PATCH 013/845] Removed unneeded nonsense --- src/main/java/dev/vxrp/bot/events/ButtonListener.java | 9 ++++----- src/main/java/dev/vxrp/bot/events/ModalListener.java | 7 ++----- src/main/java/dev/vxrp/bot/events/buttons/Support.java | 5 ++++- src/main/java/dev/vxrp/bot/events/buttons/Unban.java | 9 ++++++--- src/main/java/dev/vxrp/bot/events/modals/Support.java | 4 +++- src/main/java/dev/vxrp/bot/events/modals/Unban.java | 4 +++- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 4ba3a02a..d7cc5fcc 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -13,7 +13,6 @@ public class ButtonListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ButtonListener.class); - TranslationManager translationManager = ScpTools.getTranslationManager(); @Override public void onButtonInteraction(ButtonInteractionEvent event) { @@ -26,7 +25,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { } // Support if (event.getComponentId().equals("createNewTicket")) { - Support.createSupportTicket(event, translationManager); + Support.createSupportTicket(event); } if (event.getComponentId().startsWith("close_support_ticket")) { User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); @@ -42,18 +41,18 @@ public void onButtonInteraction(ButtonInteractionEvent event) { } if (event.getComponentId().equals("createNewUnban")) { - Unban.createUnbanTicket(event, translationManager); + Unban.createUnbanTicket(event); } if (event.getComponentId().startsWith("accept_support_ticket")) { User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); if (user != null) { - Unban.acceptTicket(event, translationManager, user); + Unban.acceptTicket(event, user); } } if (event.getComponentId().startsWith("dismiss_unban_ticket")) { User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); if (user != null) { - Unban.dismissTicket(event, translationManager, user); + Unban.dismissTicket(event, user); } } if (event.getComponentId().equals("settings_unban_ticket")) { diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index 31a9e2d3..896d8a7b 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -1,7 +1,5 @@ package dev.vxrp.bot.events; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.events.modals.Support; import dev.vxrp.bot.events.modals.Unban; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; @@ -13,15 +11,14 @@ public class ModalListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ModalListener.class); - TranslationManager translationManager = ScpTools.getTranslationManager(); @Override public void onModalInteraction(ModalInteractionEvent event) { if (event.getModalId().equals("supportTicket")) { - Support.createSupportTicket(event, translationManager, logger); + Support.createSupportTicket(event, logger); } if (event.getModalId().equals("unbanTicket")) { - Unban.createUnbanTicket(event, translationManager, logger); + Unban.createUnbanTicket(event, logger); } if (event.getModalId().startsWith("reason_action_unban_accept")) { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index c99abfb4..bd72daf0 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.TRANSLATIONS; import net.dv8tion.jda.api.EmbedBuilder; @@ -15,7 +16,9 @@ import java.util.List; public class Support { - public static void createSupportTicket(ButtonInteractionEvent event, TranslationManager translationManager) { + private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + + public static void createSupportTicket(ButtonInteractionEvent event) { if (event.getComponentId().equals("createNewTicket")) { event.replyModal( Modal.create("supportTicket", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_TITLE)) diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 5887f4f4..f27a7bf1 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.TRANSLATIONS; import net.dv8tion.jda.api.entities.User; @@ -12,7 +13,9 @@ import java.util.Objects; public class Unban { - public static void createUnbanTicket(ButtonInteractionEvent event, TranslationManager translationManager) { + private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + + public static void createUnbanTicket(ButtonInteractionEvent event) { event.replyModal( Modal.create("unbanTicket", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_TITLE)) .addComponents( @@ -32,7 +35,7 @@ public static void createUnbanTicket(ButtonInteractionEvent event, TranslationMa .build()).queue(); } - public static void dismissTicket(ButtonInteractionEvent event, TranslationManager translationManager, User user) { + public static void dismissTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)) @@ -44,7 +47,7 @@ public static void dismissTicket(ButtonInteractionEvent event, TranslationManage ))).build()).queue(); } - public static void acceptTicket(ButtonInteractionEvent event, TranslationManager translationManager, User user) { + public static void acceptTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)) diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index f2cda47c..d26f3765 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -21,7 +21,9 @@ import java.util.concurrent.ThreadLocalRandom; public class Support { - public static void createSupportTicket(ModalInteractionEvent event, TranslationManager translationManager, Logger logger) { + private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + + public static void createSupportTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); assert member != null; String userName = Objects.requireNonNull(member.getUser().getGlobalName()); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index da09326c..f2ed8a58 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -27,7 +27,9 @@ import java.util.concurrent.ThreadLocalRandom; public class Unban { - public static void createUnbanTicket(ModalInteractionEvent event, TranslationManager translationManager, Logger logger) { + private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + + public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); assert member != null; String userName = Objects.requireNonNull(member.getUser().getGlobalName()); From f7a44219d8caa8454dec2594acf678cd3903193a Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:48:43 +0200 Subject: [PATCH 014/845] New Feature named notice of departure entering production --- .../dev/vxrp/bot/commands/CommandManager.java | 2 +- .../commands/templates/TemplateCommand.java | 6 +++--- .../NoticeOfDeparture.java} | 21 +++++++------------ .../vxrp/bot/config/util/TRANSLATIONS.java | 4 ++++ .../resources/translations/translations.yml | 14 ++++++++++++- 5 files changed, 29 insertions(+), 18 deletions(-) rename src/main/java/dev/vxrp/bot/commands/templates/{deregistration/DeRegistration.java => noticeOfDeparture/NoticeOfDeparture.java} (59%) diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index 57a6d032..8221ef2b 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -37,7 +37,7 @@ public void Initialize(JDA api) { new OptionData(OptionType.STRING, "template", "What template are you referring to", true) .addChoice("rules", "rules") .addChoice("support", "support") - .addChoice("deregistration", "deregistration") + .addChoice("notice of departure", "notice_of_departure") .addChoice("regulars", "regulars") .addChoice("adminpanel", "adminpanel") )); diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index b2143e0e..4a7b3e4f 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -1,6 +1,6 @@ package dev.vxrp.bot.commands.templates; -import dev.vxrp.bot.commands.templates.deregistration.DeRegistration; +import dev.vxrp.bot.commands.templates.noticeOfDeparture.NoticeOfDeparture; import dev.vxrp.bot.commands.templates.support.Support; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; @@ -31,8 +31,8 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { if (template.equals("support")) { Support.pasteSupportTemplate(event); } - if (template.equals("deregistration")) { - DeRegistration.pasteDeRegisterTemplate(event); + if (template.equals("notice_of_departure")) { + NoticeOfDeparture.pasteDeRegisterTemplate(event); } logger.info("User {} executed command template with args '{}'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName()), template); } diff --git a/src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java similarity index 59% rename from src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java rename to src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index 762ea646..0cb45424 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/deregistration/DeRegistration.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,32 +1,27 @@ -package dev.vxrp.bot.commands.templates.deregistration; +package dev.vxrp.bot.commands.templates.noticeOfDeparture; import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.TRANSLATIONS; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import java.awt.*; -public class DeRegistration { +public class NoticeOfDeparture { private static final TranslationManager translationManager = ScpTools.getTranslationManager(); public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)) - .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY)) - .setColor(Color.DARK_GRAY) - .build()) - .queue(); - event.getChannel().sendMessageEmbeds(new EmbedBuilder() - .setColor(Color.decode("#5865F2")) - .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE)) - .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY)) + .setTitle(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_TITLE)) + .setDescription(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY)) .setColor(Color.DARK_GRAY) .build()) .addActionRow( - - ).queue(); + Button.success("file_nod", "File Notice of Departure") + ) + .queue(); } } diff --git a/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java index 67f8b15a..e52a73fb 100644 --- a/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java @@ -41,4 +41,8 @@ public static final class TICKET { public static final String UNBAN_MESSAGE_SENT = "support.ticket_unban_message_sent"; } } + public static final class NOTICE_OF_DEPARTURE { + public static final String FIRST_TITLE = "notice_of_departure.first_title"; + public static final String FIRST_BODY = "notice_of_departure.first_body"; + } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 725d59d9..187c3c7a 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -100,4 +100,16 @@ support: __**Dismiss Reason:**__\n ```%reason%``` " - ticket_unban_message_sent: "Your answer was sent and actions corresponding to it have been taken" \ No newline at end of file + ticket_unban_message_sent: "Your answer was sent and actions corresponding to it have been taken" + +notice_of_departure: + first_title: "Notice of Departure for Discord and Secret Lab" + first_body: " + If you know that you are not going to be able to come online for a specified time, please fill out this form\n + + __**Information to give:**__\n + - How to long will you be away, FORMAT: **[dd.MM.yyyy]**\n + - Please provide a short explanation on why you will be away without any details\n + + Every timespan over 1 year will not be accepted and will be asked to leave the team + " From 679eb149d11ebe2671944499b9c163365a0fcb36 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:15:44 +0200 Subject: [PATCH 015/845] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f412dc8b..6a2aa2fa 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ ScpToolsBot is a discord bot application written in Java for Scp Secret Laborato 4. The process will automatically crash and create two new folders called `configs` and `translations`. Go into the `configs` folder and edit the `config.yml` file 5. After putting in required info start the bot again and it should be running +Get a full guide [here](https://github.com/Vxrpenter/SCPToolsBot/wiki/Installation) ## Handling Issues **Bot not starting, why?** - Outdated JDK, install higher version @@ -36,6 +37,9 @@ This means that no banId could be found meaning that the user isn't banned This means that the unban process failed because the user is not banned/the ban id is invalid and does not exist +Get a full guide [here](https://github.com/Vxrpenter/SCPToolsBot/wiki/Issue-Handling) + --- + > [!NOTE] > If you are getting an error, not stated in this documentation and are not able to fix it, please create an issue so the issue can be resolved From fc9aa2a191b32c9bc3da98493d173a0015372dd1 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:42:28 +0200 Subject: [PATCH 016/845] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6a2aa2fa..9aee8a89 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ ## What is ScpToolsBot ScpToolsBot is a discord bot application written in Java for Scp Secret Laboratory discord servers. It includes support functions, cedmod api syncing, community and even team management features +If you need any more information check out the [wiki](https://github.com/Vxrpenter/SCPToolsBot/wiki) + ## Installation 1. Download the `.jar` file from the latest **STABLE** release 2. Install `JDK-17` or higher on your machine From 3c64eb55d8f3e20bcf52d53508535ca1d12b873f Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:44:26 +0200 Subject: [PATCH 017/845] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..38fac2e7 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +discord. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From 7c098216046707832dc7cc118ff9da24ffbc524a Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:23:22 +0200 Subject: [PATCH 018/845] Moved PermissionListConverter and PastebinUtil --- .../vxrp/bot/util/{ => converter}/PermissionListConverter.java | 2 +- .../java/dev/vxrp/bot/util/{ => pastebin}/PastebinUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/dev/vxrp/bot/util/{ => converter}/PermissionListConverter.java (93%) rename src/main/java/dev/vxrp/bot/util/{ => pastebin}/PastebinUtil.java (93%) diff --git a/src/main/java/dev/vxrp/bot/util/PermissionListConverter.java b/src/main/java/dev/vxrp/bot/util/converter/PermissionListConverter.java similarity index 93% rename from src/main/java/dev/vxrp/bot/util/PermissionListConverter.java rename to src/main/java/dev/vxrp/bot/util/converter/PermissionListConverter.java index 286bec33..7c891f7b 100644 --- a/src/main/java/dev/vxrp/bot/util/PermissionListConverter.java +++ b/src/main/java/dev/vxrp/bot/util/converter/PermissionListConverter.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util; +package dev.vxrp.bot.util.converter; import net.dv8tion.jda.api.Permission; diff --git a/src/main/java/dev/vxrp/bot/util/PastebinUtil.java b/src/main/java/dev/vxrp/bot/util/pastebin/PastebinUtil.java similarity index 93% rename from src/main/java/dev/vxrp/bot/util/PastebinUtil.java rename to src/main/java/dev/vxrp/bot/util/pastebin/PastebinUtil.java index 2743154e..01671886 100644 --- a/src/main/java/dev/vxrp/bot/util/PastebinUtil.java +++ b/src/main/java/dev/vxrp/bot/util/pastebin/PastebinUtil.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util; +package dev.vxrp.bot.util.pastebin; import java.io.BufferedReader; import java.io.IOException; From 419d082cd97b05739f0da0bdeae162f6b522f769 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:20:50 +0200 Subject: [PATCH 019/845] Fixed a fatal error in user processing with the unban forms --- .../commands/templates/TemplateCommand.java | 2 ++ .../templates/rules/RulesTemplateUnit.java | 2 +- .../dev/vxrp/bot/events/ButtonListener.java | 17 ++++++++------ .../dev/vxrp/bot/events/ModalListener.java | 2 ++ .../dev/vxrp/bot/events/modals/Support.java | 16 +++++++------- .../dev/vxrp/bot/events/modals/Unban.java | 22 ++++++++++--------- src/main/resources/configs/config.yml | 7 ++++-- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index 4a7b3e4f..4167f1f6 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -35,5 +35,7 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { NoticeOfDeparture.pasteDeRegisterTemplate(event); } logger.info("User {} executed command template with args '{}'", ColorTool.apply(DCColor.GREEN, event.getUser().getGlobalName()), template); + + } } diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index b1dc9692..86fd46d8 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -2,7 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.util.CONFIG; -import dev.vxrp.bot.util.PastebinUtil; +import dev.vxrp.bot.util.pastebin.PastebinUtil; import dev.vxrp.bot.util.parser.CustomColorParser; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Guild; diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index d7cc5fcc..d4a74103 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -43,22 +43,25 @@ public void onButtonInteraction(ButtonInteractionEvent event) { if (event.getComponentId().equals("createNewUnban")) { Unban.createUnbanTicket(event); } - if (event.getComponentId().startsWith("accept_support_ticket")) { - User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); - if (user != null) { + if (event.getComponentId().startsWith("accept_unban_ticket")) { + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { Unban.acceptTicket(event, user); - } + }); } if (event.getComponentId().startsWith("dismiss_unban_ticket")) { - User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); - if (user != null) { + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { Unban.dismissTicket(event, user); - } + }); } if (event.getComponentId().equals("settings_unban_ticket")) { //WIP event.reply("Feature currently under development").queue(); } + + //Notice of Departure + if (event.getComponentId().equals("file_nod")) { + + } } } diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index 896d8a7b..b21d9bee 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -8,6 +8,8 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class ModalListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ModalListener.class); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index d26f3765..fe50d342 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -48,19 +48,19 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_SUPPORT_TICKETS); for (String id : roleIDs) { textChannel.upsertPermissionOverride( - Objects.requireNonNull(guild.getRoleById(id))) + Objects.requireNonNull(guild.getRoleById(id))) .grant(EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND)) .queue(); } textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); textChannel.sendMessageEmbeds( builder(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_TITLE).replace("%name%", name), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY) - .replace("%subject%", subject) - .replace("%body%", body), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_FOOTER) - .replace("%date%", date) - .replace("%time%", time), - event.getGuild().getIconUrl(), event.getUser()).build()) + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY) + .replace("%subject%", subject) + .replace("%body%", body), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_FOOTER) + .replace("%date%", date) + .replace("%time%", time), + event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( Button.danger("close_support_ticket:"+userID+":", "Close Ticket"), Button.primary("claim_support_ticket:"+userID+":", "Claim Ticket"), diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index f2ed8a58..9938fd0c 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -69,7 +69,7 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( - Button.success("accept_support_ticket:"+userID+":"+steamID+":", "Accept Ticket"), + Button.success("accept_unban_ticket:"+userID+":"+steamID+":", "Accept Ticket"), Button.danger("dismiss_unban_ticket:"+userID+":"+steamID+":", "Dismiss Ticket"), Button.secondary("settings_unban_ticket", "Settings") ).queue(); @@ -109,18 +109,20 @@ public static void dismissUnban(ModalInteractionEvent event) { Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); - User bannedUser = Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getMemberById(event.getModalId().split(":")[1])).getUser(); String steamID = event.getModalId().split(":")[2]; String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); - bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( - StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), - new EmbedBuilder() - .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED) - .replace("%steamID%", steamID) - .replace("%reason%", reason)) - .build() - )).queue(); + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> { + user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( + StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), + new EmbedBuilder() + .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED) + .replace("%steamID%", steamID) + .replace("%reason%", reason)) + .build() + )).queue(); + }); + event.reply(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT)).setEphemeral(true).queue(); } diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index a5c3b06a..beae4149 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -14,7 +14,7 @@ rules: pastebin: "" embed_footer: "Official Server Ruleset" -# Commands that are activated by default remove to deactivate, default ["help"] +# Commands that are activated by default remove to deactivate, default ["help", "template"]] commands: ["help", "template"] # Command settings # 'default_permissions' is pretty clear, find all permissions in this Javadoc https://docs.jda.wiki/net/dv8tion/jda/api/Permission.html. @@ -27,8 +27,11 @@ command_settings: description: "Command for pasting certain templates" support_settings: + # Enter ROLEIDS of roles to automatically add to new tickets roles_access_support_tickets: [] + # Enter ROLEIDS of roles that should be able to interact with unban requests roles_access_unban_tickets: [] + # Which channel should unban requests be send to unban_channel_id: "" cedmod: @@ -36,7 +39,7 @@ cedmod: active: false # Include https:// instance_url: "" - # Exclude Bearer, just plain api key + # Exclude Bearer, put plain api key api_key: "" # This bot is only able to unban people that are on this banlist (feature for multi banlist bans coming in the future) master_ban_list_id: "" \ No newline at end of file From 75d368fd74882001c0d2277efd691d09affc7083 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:21:08 +0200 Subject: [PATCH 020/845] NEW CONTENT --- .../java/dev/vxrp/bot/commands/CommandManager.java | 2 +- .../noticeOfDeparture/NoticeOfDeparture.java | 2 +- .../vxrp/bot/events/modals/NoticeOfDeparture.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index 8221ef2b..fd9a25b4 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -2,7 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.util.CONFIG; -import dev.vxrp.bot.util.PermissionListConverter; +import dev.vxrp.bot.util.converter.PermissionListConverter; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; import net.dv8tion.jda.api.interactions.commands.OptionType; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index 0cb45424..7108841a 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -24,4 +24,4 @@ public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { ) .queue(); } -} +} \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java new file mode 100644 index 00000000..984cbec7 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -0,0 +1,13 @@ +package dev.vxrp.bot.events.modals; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.config.managers.TranslationManager; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; + +public class NoticeOfDeparture { + private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + + public static void createNewNoticeOfDeparture(ButtonInteractionEvent event) { + + } +} \ No newline at end of file From 2aa5be592431b1477754e605731e03bf3b071350 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:58:32 +0200 Subject: [PATCH 021/845] Translations are now getting loaded in Hashsets before usage --- src/main/java/dev/vxrp/bot/ScpTools.java | 8 + .../noticeOfDeparture/NoticeOfDeparture.java | 11 +- .../commands/templates/support/Support.java | 15 +- .../java/dev/vxrp/bot/config/util/CONFIG.java | 4 + .../dev/vxrp/bot/events/ButtonListener.java | 2 - .../dev/vxrp/bot/events/buttons/Support.java | 17 +- .../dev/vxrp/bot/events/buttons/Unban.java | 33 +- .../dev/vxrp/bot/events/modals/Support.java | 14 +- .../dev/vxrp/bot/events/modals/Unban.java | 21 +- .../configuration/LoadedConfigurations.java | 38 +++ .../translations/TranslationLoader.java | 55 +++ .../groups/NoticeOfDepartureGroup.java | 25 ++ .../translations/groups/SupportGroup.java | 312 ++++++++++++++++++ src/main/resources/configs/config.yml | 10 +- .../resources/translations/translations.yml | 2 + 15 files changed, 506 insertions(+), 61 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 8e455cdf..0026ff68 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -11,6 +11,7 @@ import dev.vxrp.bot.events.ModalListener; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.configuration.translations.TranslationLoader; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; @@ -41,6 +42,13 @@ public static void main(String[] args) { translationManager = new TranslationManager(); colorConfigManager = new ColorConfigManager(); + try { + new TranslationLoader(); + logger.info("Loaded translations into memory"); + } catch (Exception e) { + logger.error("Could not load translation to memory {}", e.getMessage()); + } + Activity.ActivityType activityType = Activity.ActivityType.valueOf(configManager.getString(CONFIG.ACTIVITY_TYPE)); logger.info("ActivityType set to {}", ColorTool.apply(DCColor.RED, activityType.toString())); String activityContent = configManager.getString(CONFIG.ACTIVITY_CONTENT); diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index 7108841a..09d06c7e 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,8 +1,7 @@ package dev.vxrp.bot.commands.templates.noticeOfDeparture; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -10,13 +9,13 @@ import java.awt.*; public class NoticeOfDeparture { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_TITLE)) - .setDescription(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY)) + .setTitle(translations.getFirst_title()) + .setDescription(translations.getFirst_body()) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index 03d157f3..3a905230 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -1,8 +1,7 @@ package dev.vxrp.bot.commands.templates.support; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -11,20 +10,20 @@ import java.awt.*; public class Support { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)) - .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY)) + .setTitle(translations.getFirst_title()) + .setDescription(translations.getFirst_body()) .setColor(Color.DARK_GRAY) .build()) .queue(); event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE)) - .setDescription(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY)) + .setTitle(translations.getSecond_title()) + .setDescription(translations.getSecond_body()) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/config/util/CONFIG.java b/src/main/java/dev/vxrp/bot/config/util/CONFIG.java index 58389730..481a47f5 100644 --- a/src/main/java/dev/vxrp/bot/config/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/config/util/CONFIG.java @@ -29,4 +29,8 @@ public static final class CEDMOD { public static final String API_KEY = "cedmod.api_key"; public static final String MASTER_BAN_LIST_ID = "cedmod.master_ban_list_id"; } + public static final class NOTICE_OF_DEPARTURE { + public static final String DESCISION_CHANNEL_ID = "notice_of_departure.decision_channel_id"; + public static final String NOTICE_CHANNEL_ID = "notice_of_departure.notice_channel_id"; + } } diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index d4a74103..939e5220 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -1,7 +1,5 @@ package dev.vxrp.bot.events; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.events.buttons.Rules; import dev.vxrp.bot.events.buttons.Support; import dev.vxrp.bot.events.buttons.Unban; diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index bd72daf0..a545ab04 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,8 +1,7 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; @@ -16,20 +15,20 @@ import java.util.List; public class Support { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void createSupportTicket(ButtonInteractionEvent event) { if (event.getComponentId().equals("createNewTicket")) { event.replyModal( - Modal.create("supportTicket", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_TITLE)) + Modal.create("supportTicket", translations.getModal_support_title()) .addComponents( ActionRow.of(shortModal( - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_PLACEHOLDER) + translations.getModal_support_first_title(), + translations.getModal_support_first_placeholder() )), ActionRow.of(paragraphModal( - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_PLACEHOLDER)))) + translations.getModal_support_second_title(), + translations.getModal_support_second_placeholder()))) .build()).queue(); } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index f27a7bf1..442da2c1 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,8 +1,7 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; @@ -13,36 +12,36 @@ import java.util.Objects; public class Unban { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void createUnbanTicket(ButtonInteractionEvent event) { event.replyModal( - Modal.create("unbanTicket", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_TITLE)) + Modal.create("unbanTicket", translations.getModal_unban_title()) .addComponents( ActionRow.of(shortModal( "unban_steamID", - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_PLACEHOLDER), + translations.getModal_unban_first_title(), + translations.getModal_unban_first_placeholder(), 17, 17)), ActionRow.of(shortModal( "unban_ban_reason", - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_PLACEHOLDER), + translations.getModal_unban_second_title(), + translations.getModal_unban_second_placeholder(), 5, 100)), ActionRow.of(paragraphModal( - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_PLACEHOLDER)))) + translations.getModal_unban_third_title(), + translations.getModal_unban_third_placeholder()))) .build()).queue(); } public static void dismissTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)) + Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.getModal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_PLACEHOLDER), + translations.getModal_reason_action_first_title(), + translations.getModal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } @@ -50,11 +49,11 @@ public static void dismissTicket(ButtonInteractionEvent event, User user) { public static void acceptTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)) + Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.getModal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_PLACEHOLDER), + translations.getModal_reason_action_first_title(), + translations.getModal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index fe50d342..5a995b84 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,12 +1,12 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.CONFIG; -import dev.vxrp.bot.config.util.TRANSLATIONS; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; @@ -21,7 +21,7 @@ import java.util.concurrent.ThreadLocalRandom; public class Support { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void createSupportTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); @@ -42,7 +42,7 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .addPermissionOverride(guild.getPublicRole(), null, EnumSet.of(Permission.VIEW_CHANNEL)) .setSlowmode(1) .queue(textChannel -> { - event.reply(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_CREATED) + event.reply(translations.getTicket_support_created() .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_SUPPORT_TICKETS); @@ -53,11 +53,11 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .queue(); } textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); - textChannel.sendMessageEmbeds( builder(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_TITLE).replace("%name%", name), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY) + textChannel.sendMessageEmbeds(builder(translations.getTicket_support_title().replace("%name%", name), + translations.getTicket_support_body() .replace("%subject%", subject) .replace("%body%", body), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_FOOTER) + translations.getTicket_support_footer() .replace("%date%", date) .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 9938fd0c..91b81d27 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,13 +1,14 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.config.util.CONFIG; import dev.vxrp.bot.config.util.TRANSLATIONS; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.cedmod.CedModApi; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; @@ -27,7 +28,7 @@ import java.util.concurrent.ThreadLocalRandom; public class Unban { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); @@ -47,7 +48,7 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) TextChannel textChannel = event.getGuild().getTextChannelById(ScpTools.getConfigManager().getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID)); assert textChannel != null; - event.reply(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_CREATED) + event.reply(translations.getTicket_unban_created() .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_UNBAN_TICKETS); @@ -59,12 +60,12 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) } textChannel.sendMessageEmbeds( StatsBuilder.buildStatus(userName).build(), - builder(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_TITLE).replace("%name%", name), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_BODY) + builder(translations.getTicket_unban_title().replace("%name%", name), + translations.getTicket_unban_body() .replace("%steamID%", steamID) .replace("%reason%", reason) .replace("%reasoning%", reasoning), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_FOOTER) + translations.getTicket_unban_footer() .replace("%date%", date) .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) @@ -94,7 +95,7 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildAccepted(bannedUser.getGlobalName()).build(), new EmbedBuilder() - .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_ACCEPTED) + .setDescription(translations.getTicket_unban_message_accepted() .replace("%steamID%", steamID) .replace("%reason%", reason)) .build() @@ -102,7 +103,7 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { CedModApi.executeUnban(instanceUrl, apiKey, banID, reason); - event.reply(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT)).setEphemeral(true).queue(); + event.reply(translations.getTicket_unban_message_sent()).setEphemeral(true).queue(); } public static void dismissUnban(ModalInteractionEvent event) { String messageID = event.getModalId().split(":")[3]; @@ -116,7 +117,7 @@ public static void dismissUnban(ModalInteractionEvent event) { user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED) + .setDescription(translations.getTicket_unban_message_dismissed() .replace("%steamID%", steamID) .replace("%reason%", reason)) .build() @@ -124,7 +125,7 @@ public static void dismissUnban(ModalInteractionEvent event) { }); - event.reply(ScpTools.getTranslationManager().getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT)).setEphemeral(true).queue(); + event.reply(translations.getTicket_unban_message_sent()).setEphemeral(true).queue(); } private static EmbedBuilder builder(String title, String body, String footerText, String IconURL, User user) { diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java new file mode 100644 index 00000000..cee0cfca --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java @@ -0,0 +1,38 @@ +package dev.vxrp.bot.util.configuration; + +import dev.vxrp.bot.util.configuration.translations.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; + +import java.util.HashSet; +import java.util.Iterator; + +public class LoadedConfigurations { + public static HashSet supportTranslationMemoryLoad = new HashSet<>(); + public static HashSet noticeOfDepartureMemoryLoad = new HashSet<>(); + + public static SupportGroup getSupportTranslationMemoryLoad() { + Iterator iterator = supportTranslationMemoryLoad.iterator(); + SupportGroup supportGroup = null; + while (iterator.hasNext()) { + supportGroup = iterator.next(); + } + return supportGroup; + } + + public static void setSupportTranslationMemoryLoad(SupportGroup supportMemoryLoad) { + LoadedConfigurations.supportTranslationMemoryLoad.add(supportMemoryLoad); + } + + public static NoticeOfDepartureGroup getNoticeOfDepartureMemoryLoad() { + Iterator iterator = noticeOfDepartureMemoryLoad.iterator(); + NoticeOfDepartureGroup noticeOfDepartureGroup = null; + while (iterator.hasNext()) { + noticeOfDepartureGroup = iterator.next(); + } + return noticeOfDepartureGroup; + } + + public static void setNoticeOfDepartureMemoryLoad(NoticeOfDepartureGroup noticeOfDepartureMemoryLoad) { + LoadedConfigurations.noticeOfDepartureMemoryLoad.add(noticeOfDepartureMemoryLoad); + } +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java new file mode 100644 index 00000000..80677400 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -0,0 +1,55 @@ +package dev.vxrp.bot.util.configuration.translations; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.translations.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; + +public class TranslationLoader { + public TranslationLoader() { + TranslationManager translationManager = ScpTools.getTranslationManager(); + + SupportGroup supportGroup = new SupportGroup( + translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY), + translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_FOOTER), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_CREATED), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_BODY), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_FOOTER), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_CREATED), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_ACCEPTED), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED), + translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT) + ); + + NoticeOfDepartureGroup noticeOfDepartureGroup = new NoticeOfDepartureGroup( + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_TITLE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY) + ); + + LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); + LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); + } +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java new file mode 100644 index 00000000..7e824667 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java @@ -0,0 +1,25 @@ +package dev.vxrp.bot.util.configuration.translations.groups; + +public class NoticeOfDepartureGroup { + private String first_title; + private String first_body; + + public NoticeOfDepartureGroup(String first_title, String first_body) { + this.first_title = first_title; + this.first_body = first_body; + } + public String getFirst_title() { + return first_title; + } + public String getFirst_body() { + return first_body; + } + + public void setFirst_title(String first_title) { + this.first_title = first_title; + } + + public void setFirst_body(String first_body) { + this.first_body = first_body; + } +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java new file mode 100644 index 00000000..7dbb2a04 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java @@ -0,0 +1,312 @@ +package dev.vxrp.bot.util.configuration.translations.groups; + +public class SupportGroup { + private String first_title; + private String first_body; + private String second_title; + private String second_body; + + private String modal_support_title; + private String modal_support_first_title; + private String modal_support_first_placeholder; + private String modal_support_second_title; + private String modal_support_second_placeholder; + + private String modal_unban_title; + private String modal_unban_first_title; + private String modal_unban_first_placeholder; + private String modal_unban_second_title; + private String modal_unban_second_placeholder; + private String modal_unban_third_title; + private String modal_unban_third_placeholder; + + private String modal_reason_action_title; + private String modal_reason_action_first_title; + private String modal_reason_action_first_placeholder; + + private String ticket_support_title; + private String ticket_support_body; + private String ticket_support_footer; + private String ticket_support_created; + + private String ticket_unban_title; + private String ticket_unban_body; + private String ticket_unban_footer; + private String ticket_unban_created; + private String ticket_unban_message_accepted; + private String ticket_unban_message_dismissed; + private String ticket_unban_message_sent; + + public String getFirst_title() { + return first_title; + } + + public void setFirst_title(String first_title) { + this.first_title = first_title; + } + + public String getFirst_body() { + return first_body; + } + + public void setFirst_body(String first_body) { + this.first_body = first_body; + } + + public String getSecond_title() { + return second_title; + } + + public void setSecond_title(String second_title) { + this.second_title = second_title; + } + + public String getSecond_body() { + return second_body; + } + + public void setSecond_body(String second_body) { + this.second_body = second_body; + } + + public String getModal_support_title() { + return modal_support_title; + } + + public void setModal_support_title(String modal_support_title) { + this.modal_support_title = modal_support_title; + } + + public String getModal_support_first_title() { + return modal_support_first_title; + } + + public void setModal_support_first_title(String modal_support_first_title) { + this.modal_support_first_title = modal_support_first_title; + } + + public String getModal_support_first_placeholder() { + return modal_support_first_placeholder; + } + + public void setModal_support_first_placeholder(String modal_support_first_placeholder) { + this.modal_support_first_placeholder = modal_support_first_placeholder; + } + + public String getModal_support_second_title() { + return modal_support_second_title; + } + + public void setModal_support_second_title(String modal_support_second_title) { + this.modal_support_second_title = modal_support_second_title; + } + + public String getModal_support_second_placeholder() { + return modal_support_second_placeholder; + } + + public void setModal_support_second_placeholder(String modal_support_second_placeholder) { + this.modal_support_second_placeholder = modal_support_second_placeholder; + } + + public String getModal_unban_title() { + return modal_unban_title; + } + + public void setModal_unban_title(String modal_unban_title) { + this.modal_unban_title = modal_unban_title; + } + + public String getModal_unban_first_title() { + return modal_unban_first_title; + } + + public void setModal_unban_first_title(String modal_unban_first_title) { + this.modal_unban_first_title = modal_unban_first_title; + } + + public String getModal_unban_first_placeholder() { + return modal_unban_first_placeholder; + } + + public void setModal_unban_first_placeholder(String modal_unban_first_placeholder) { + this.modal_unban_first_placeholder = modal_unban_first_placeholder; + } + + public String getModal_unban_second_title() { + return modal_unban_second_title; + } + + public void setModal_unban_second_title(String modal_unban_second_title) { + this.modal_unban_second_title = modal_unban_second_title; + } + + public String getModal_unban_second_placeholder() { + return modal_unban_second_placeholder; + } + + public void setModal_unban_second_placeholder(String modal_unban_second_placeholder) { + this.modal_unban_second_placeholder = modal_unban_second_placeholder; + } + + public String getModal_unban_third_title() { + return modal_unban_third_title; + } + + public void setModal_unban_third_title(String modal_unban_third_title) { + this.modal_unban_third_title = modal_unban_third_title; + } + + public String getModal_unban_third_placeholder() { + return modal_unban_third_placeholder; + } + + public void setModal_unban_third_placeholder(String modal_unban_third_placeholder) { + this.modal_unban_third_placeholder = modal_unban_third_placeholder; + } + + public String getModal_reason_action_title() { + return modal_reason_action_title; + } + + public void setModal_reason_action_title(String modal_reason_action_title) { + this.modal_reason_action_title = modal_reason_action_title; + } + + public String getModal_reason_action_first_title() { + return modal_reason_action_first_title; + } + + public void setModal_reason_action_first_title(String modal_reason_action_first_title) { + this.modal_reason_action_first_title = modal_reason_action_first_title; + } + + public String getModal_reason_action_first_placeholder() { + return modal_reason_action_first_placeholder; + } + + public void setModal_reason_action_first_placeholder(String modal_reason_action_first_placeholder) { + this.modal_reason_action_first_placeholder = modal_reason_action_first_placeholder; + } + + public String getTicket_support_title() { + return ticket_support_title; + } + + public void setTicket_support_title(String ticket_support_title) { + this.ticket_support_title = ticket_support_title; + } + + public String getTicket_support_body() { + return ticket_support_body; + } + + public void setTicket_support_body(String ticket_support_body) { + this.ticket_support_body = ticket_support_body; + } + + public String getTicket_support_footer() { + return ticket_support_footer; + } + + public void setTicket_support_footer(String ticket_support_footer) { + this.ticket_support_footer = ticket_support_footer; + } + + public String getTicket_support_created() { + return ticket_support_created; + } + + public void setTicket_support_created(String ticket_support_created) { + this.ticket_support_created = ticket_support_created; + } + + public String getTicket_unban_title() { + return ticket_unban_title; + } + + public void setTicket_unban_title(String ticket_unban_title) { + this.ticket_unban_title = ticket_unban_title; + } + + public String getTicket_unban_body() { + return ticket_unban_body; + } + + public void setTicket_unban_body(String ticket_unban_body) { + this.ticket_unban_body = ticket_unban_body; + } + + public String getTicket_unban_footer() { + return ticket_unban_footer; + } + + public void setTicket_unban_footer(String ticket_unban_footer) { + this.ticket_unban_footer = ticket_unban_footer; + } + + public String getTicket_unban_created() { + return ticket_unban_created; + } + + public void setTicket_unban_created(String ticket_unban_created) { + this.ticket_unban_created = ticket_unban_created; + } + + public String getTicket_unban_message_accepted() { + return ticket_unban_message_accepted; + } + + public void setTicket_unban_message_accepted(String ticket_unban_message_accepted) { + this.ticket_unban_message_accepted = ticket_unban_message_accepted; + } + + public String getTicket_unban_message_dismissed() { + return ticket_unban_message_dismissed; + } + + public void setTicket_unban_message_dismissed(String ticket_unban_message_dismissed) { + this.ticket_unban_message_dismissed = ticket_unban_message_dismissed; + } + + public String getTicket_unban_message_sent() { + return ticket_unban_message_sent; + } + + public void setTicket_unban_message_sent(String ticket_unban_message_sent) { + this.ticket_unban_message_sent = ticket_unban_message_sent; + } + + public SupportGroup(String first_title, String first_body, String second_title, String second_body, String modal_support_title, String modal_support_first_title, String modal_support_first_placeholder, String modal_support_second_title, String modal_support_second_placeholder, String modal_unban_title, String modal_unban_first_title, String modal_unban_first_placeholder, String modal_unban_second_title, String modal_unban_second_placeholder, String modal_unban_third_title, String modal_unban_third_placeholder, String modal_reason_action_title, String modal_reason_action_first_title, String modal_reason_action_first_placeholder, String ticket_support_title, String ticket_support_body, String ticket_support_footer, String ticket_support_created, String ticket_unban_title, String ticket_unban_body, String ticket_unban_footer, String ticket_unban_created, String ticket_unban_message_accepted, String ticket_unban_message_dismissed, String ticket_unban_message_sent) { + this.first_title = first_title; + this.first_body = first_body; + this.second_title = second_title; + this.second_body = second_body; + this.modal_support_title = modal_support_title; + this.modal_support_first_title = modal_support_first_title; + this.modal_support_first_placeholder = modal_support_first_placeholder; + this.modal_support_second_title = modal_support_second_title; + this.modal_support_second_placeholder = modal_support_second_placeholder; + this.modal_unban_title = modal_unban_title; + this.modal_unban_first_title = modal_unban_first_title; + this.modal_unban_first_placeholder = modal_unban_first_placeholder; + this.modal_unban_second_title = modal_unban_second_title; + this.modal_unban_second_placeholder = modal_unban_second_placeholder; + this.modal_unban_third_title = modal_unban_third_title; + this.modal_unban_third_placeholder = modal_unban_third_placeholder; + this.modal_reason_action_title = modal_reason_action_title; + this.modal_reason_action_first_title = modal_reason_action_first_title; + this.modal_reason_action_first_placeholder = modal_reason_action_first_placeholder; + this.ticket_support_title = ticket_support_title; + this.ticket_support_body = ticket_support_body; + this.ticket_support_footer = ticket_support_footer; + this.ticket_support_created = ticket_support_created; + this.ticket_unban_title = ticket_unban_title; + this.ticket_unban_body = ticket_unban_body; + this.ticket_unban_footer = ticket_unban_footer; + this.ticket_unban_created = ticket_unban_created; + this.ticket_unban_message_accepted = ticket_unban_message_accepted; + this.ticket_unban_message_dismissed = ticket_unban_message_dismissed; + this.ticket_unban_message_sent = ticket_unban_message_sent; + } +} diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index beae4149..083ed17b 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -29,11 +29,17 @@ command_settings: support_settings: # Enter ROLEIDS of roles to automatically add to new tickets roles_access_support_tickets: [] - # Enter ROLEIDS of roles that should be able to interact with unban requests + # Enter ROLEIDS of roles that should be able to interact with unbanning requests roles_access_unban_tickets: [] - # Which channel should unban requests be send to + # Which channel should unban requests be sent to unban_channel_id: "" +notice_of_departure: + # Which channel should the form be sent to be accepted by moderators? + decision_channel_id: "" + # Which channel should the departures be sent to? + notice_channel_id: "" + cedmod: # Should Cedmod integration features be established or deactivated? active: false diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 187c3c7a..67c3071a 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -113,3 +113,5 @@ notice_of_departure: Every timespan over 1 year will not be accepted and will be asked to leave the team " + + modal_ From 73d412b4deb2b0e602227e0f410f9418f80a4c89 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:15:07 +0200 Subject: [PATCH 022/845] Turned NoticeOfDepartureGroup and SupportGroup to record classes --- src/main/java/dev/vxrp/bot/ScpTools.java | 2 +- .../dev/vxrp/bot/commands/CommandManager.java | 2 +- .../noticeOfDeparture/NoticeOfDeparture.java | 6 +- .../templates/rules/RulesTemplateUnit.java | 2 +- .../commands/templates/support/Support.java | 10 +- .../dev/vxrp/bot/events/buttons/Support.java | 12 +- .../dev/vxrp/bot/events/buttons/Unban.java | 28 +- .../dev/vxrp/bot/events/modals/Support.java | 12 +- .../dev/vxrp/bot/events/modals/Unban.java | 21 +- .../configuration/LoadedConfigurations.java | 4 +- .../groups/NoticeOfDepartureGroup.java | 4 + .../configuration/groups/SupportGroup.java | 17 + .../translations/TranslationLoader.java | 6 +- .../groups/NoticeOfDepartureGroup.java | 25 -- .../translations/groups/SupportGroup.java | 312 ------------------ .../configuration}/util/CONFIG.java | 2 +- .../configuration}/util/TRANSLATIONS.java | 2 +- 17 files changed, 75 insertions(+), 392 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java delete mode 100644 src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java delete mode 100644 src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java rename src/main/java/dev/vxrp/bot/{config => util/configuration}/util/CONFIG.java (97%) rename src/main/java/dev/vxrp/bot/{config => util/configuration}/util/TRANSLATIONS.java (98%) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 0026ff68..e84be458 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -6,7 +6,7 @@ import dev.vxrp.bot.commands.templates.TemplateCommand; import dev.vxrp.bot.config.managers.ColorConfigManager; import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.config.util.CONFIG; +import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.config.managers.ConfigManager; import dev.vxrp.bot.events.ModalListener; import dev.vxrp.bot.util.colors.ColorTool; diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index fd9a25b4..6e4d1c6d 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.commands; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.util.CONFIG; +import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.converter.PermissionListConverter; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index 09d06c7e..be2970de 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.commands.templates.noticeOfDeparture; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -14,8 +14,8 @@ public class NoticeOfDeparture { public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translations.getFirst_title()) - .setDescription(translations.getFirst_body()) + .setTitle(translations.first_title()) + .setDescription(translations.first_body()) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index 86fd46d8..56b76b89 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.commands.templates.rules; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.util.CONFIG; +import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.pastebin.PastebinUtil; import dev.vxrp.bot.util.parser.CustomColorParser; import net.dv8tion.jda.api.EmbedBuilder; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index 3a905230..cfdcfcc1 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.commands.templates.support; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -15,15 +15,15 @@ public class Support { public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translations.getFirst_title()) - .setDescription(translations.getFirst_body()) + .setTitle(translations.first_title()) + .setDescription(translations.first_body()) .setColor(Color.DARK_GRAY) .build()) .queue(); event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translations.getSecond_title()) - .setDescription(translations.getSecond_body()) + .setTitle(translations.second_title()) + .setDescription(translations.second_body()) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index a545ab04..b30bad65 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.events.buttons; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; @@ -20,15 +20,15 @@ public class Support { public static void createSupportTicket(ButtonInteractionEvent event) { if (event.getComponentId().equals("createNewTicket")) { event.replyModal( - Modal.create("supportTicket", translations.getModal_support_title()) + Modal.create("supportTicket", translations.modal_support_title()) .addComponents( ActionRow.of(shortModal( - translations.getModal_support_first_title(), - translations.getModal_support_first_placeholder() + translations.modal_support_first_title(), + translations.modal_support_first_placeholder() )), ActionRow.of(paragraphModal( - translations.getModal_support_second_title(), - translations.getModal_support_second_placeholder()))) + translations.modal_support_second_title(), + translations.modal_support_second_placeholder()))) .build()).queue(); } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 442da2c1..45dde301 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.events.buttons; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; @@ -16,32 +16,32 @@ public class Unban { public static void createUnbanTicket(ButtonInteractionEvent event) { event.replyModal( - Modal.create("unbanTicket", translations.getModal_unban_title()) + Modal.create("unbanTicket", translations.modal_unban_title()) .addComponents( ActionRow.of(shortModal( "unban_steamID", - translations.getModal_unban_first_title(), - translations.getModal_unban_first_placeholder(), + translations.modal_unban_first_title(), + translations.modal_unban_first_placeholder(), 17, 17)), ActionRow.of(shortModal( "unban_ban_reason", - translations.getModal_unban_second_title(), - translations.getModal_unban_second_placeholder(), + translations.modal_unban_second_title(), + translations.modal_unban_second_placeholder(), 5, 100)), ActionRow.of(paragraphModal( - translations.getModal_unban_third_title(), - translations.getModal_unban_third_placeholder()))) + translations.modal_unban_third_title(), + translations.modal_unban_third_placeholder()))) .build()).queue(); } public static void dismissTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.getModal_reason_action_title()) + Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - translations.getModal_reason_action_first_title(), - translations.getModal_reason_action_first_placeholder(), + translations.modal_reason_action_first_title(), + translations.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } @@ -49,11 +49,11 @@ public static void dismissTicket(ButtonInteractionEvent event, User user) { public static void acceptTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.getModal_reason_action_title()) + Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - translations.getModal_reason_action_first_title(), - translations.getModal_reason_action_first_placeholder(), + translations.modal_reason_action_first_title(), + translations.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 5a995b84..e0db707f 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,12 +1,12 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.util.CONFIG; +import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; @@ -42,7 +42,7 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .addPermissionOverride(guild.getPublicRole(), null, EnumSet.of(Permission.VIEW_CHANNEL)) .setSlowmode(1) .queue(textChannel -> { - event.reply(translations.getTicket_support_created() + event.reply(translations.ticket_support_created() .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_SUPPORT_TICKETS); @@ -53,11 +53,11 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .queue(); } textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); - textChannel.sendMessageEmbeds(builder(translations.getTicket_support_title().replace("%name%", name), - translations.getTicket_support_body() + textChannel.sendMessageEmbeds(builder(translations.ticket_support_title().replace("%name%", name), + translations.ticket_support_body() .replace("%subject%", subject) .replace("%body%", body), - translations.getTicket_support_footer() + translations.ticket_support_footer() .replace("%date%", date) .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 91b81d27..25dcc541 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,14 +1,13 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.util.CONFIG; -import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.cedmod.CedModApi; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; @@ -48,7 +47,7 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) TextChannel textChannel = event.getGuild().getTextChannelById(ScpTools.getConfigManager().getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID)); assert textChannel != null; - event.reply(translations.getTicket_unban_created() + event.reply(translations.ticket_unban_created() .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_UNBAN_TICKETS); @@ -60,12 +59,12 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) } textChannel.sendMessageEmbeds( StatsBuilder.buildStatus(userName).build(), - builder(translations.getTicket_unban_title().replace("%name%", name), - translations.getTicket_unban_body() + builder(translations.ticket_unban_title().replace("%name%", name), + translations.ticket_unban_body() .replace("%steamID%", steamID) .replace("%reason%", reason) .replace("%reasoning%", reasoning), - translations.getTicket_unban_footer() + translations.ticket_unban_footer() .replace("%date%", date) .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) @@ -95,7 +94,7 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildAccepted(bannedUser.getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.getTicket_unban_message_accepted() + .setDescription(translations.ticket_unban_message_accepted() .replace("%steamID%", steamID) .replace("%reason%", reason)) .build() @@ -103,7 +102,7 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { CedModApi.executeUnban(instanceUrl, apiKey, banID, reason); - event.reply(translations.getTicket_unban_message_sent()).setEphemeral(true).queue(); + event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); } public static void dismissUnban(ModalInteractionEvent event) { String messageID = event.getModalId().split(":")[3]; @@ -117,7 +116,7 @@ public static void dismissUnban(ModalInteractionEvent event) { user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.getTicket_unban_message_dismissed() + .setDescription(translations.ticket_unban_message_dismissed() .replace("%steamID%", steamID) .replace("%reason%", reason)) .build() @@ -125,7 +124,7 @@ public static void dismissUnban(ModalInteractionEvent event) { }); - event.reply(translations.getTicket_unban_message_sent()).setEphemeral(true).queue(); + event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); } private static EmbedBuilder builder(String title, String body, String footerText, String IconURL, User user) { diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java index cee0cfca..a21bbcd2 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.util.configuration; -import dev.vxrp.bot.util.configuration.translations.groups.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; import java.util.HashSet; import java.util.Iterator; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java new file mode 100644 index 00000000..28d3c201 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -0,0 +1,4 @@ +package dev.vxrp.bot.util.configuration.groups; + +public record NoticeOfDepartureGroup(String first_title, String first_body) { +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java new file mode 100644 index 00000000..b9cb0bdb --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java @@ -0,0 +1,17 @@ +package dev.vxrp.bot.util.configuration.groups; + +public record SupportGroup(String first_title, String first_body, String second_title, String second_body, + String modal_support_title, String modal_support_first_title, + String modal_support_first_placeholder, String modal_support_second_title, + String modal_support_second_placeholder, String modal_unban_title, + String modal_unban_first_title, String modal_unban_first_placeholder, + String modal_unban_second_title, String modal_unban_second_placeholder, + String modal_unban_third_title, String modal_unban_third_placeholder, + String modal_reason_action_title, String modal_reason_action_first_title, + String modal_reason_action_first_placeholder, String ticket_support_title, + String ticket_support_body, String ticket_support_footer, String ticket_support_created, + String ticket_unban_title, String ticket_unban_body, String ticket_unban_footer, + String ticket_unban_created, String ticket_unban_message_accepted, + String ticket_unban_message_dismissed, String ticket_unban_message_sent) { + +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 80677400..eb935f8e 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -2,10 +2,10 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.config.util.TRANSLATIONS; +import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.translations.groups.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.translations.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; public class TranslationLoader { public TranslationLoader() { diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java deleted file mode 100644 index 7e824667..00000000 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/NoticeOfDepartureGroup.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.vxrp.bot.util.configuration.translations.groups; - -public class NoticeOfDepartureGroup { - private String first_title; - private String first_body; - - public NoticeOfDepartureGroup(String first_title, String first_body) { - this.first_title = first_title; - this.first_body = first_body; - } - public String getFirst_title() { - return first_title; - } - public String getFirst_body() { - return first_body; - } - - public void setFirst_title(String first_title) { - this.first_title = first_title; - } - - public void setFirst_body(String first_body) { - this.first_body = first_body; - } -} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java deleted file mode 100644 index 7dbb2a04..00000000 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/groups/SupportGroup.java +++ /dev/null @@ -1,312 +0,0 @@ -package dev.vxrp.bot.util.configuration.translations.groups; - -public class SupportGroup { - private String first_title; - private String first_body; - private String second_title; - private String second_body; - - private String modal_support_title; - private String modal_support_first_title; - private String modal_support_first_placeholder; - private String modal_support_second_title; - private String modal_support_second_placeholder; - - private String modal_unban_title; - private String modal_unban_first_title; - private String modal_unban_first_placeholder; - private String modal_unban_second_title; - private String modal_unban_second_placeholder; - private String modal_unban_third_title; - private String modal_unban_third_placeholder; - - private String modal_reason_action_title; - private String modal_reason_action_first_title; - private String modal_reason_action_first_placeholder; - - private String ticket_support_title; - private String ticket_support_body; - private String ticket_support_footer; - private String ticket_support_created; - - private String ticket_unban_title; - private String ticket_unban_body; - private String ticket_unban_footer; - private String ticket_unban_created; - private String ticket_unban_message_accepted; - private String ticket_unban_message_dismissed; - private String ticket_unban_message_sent; - - public String getFirst_title() { - return first_title; - } - - public void setFirst_title(String first_title) { - this.first_title = first_title; - } - - public String getFirst_body() { - return first_body; - } - - public void setFirst_body(String first_body) { - this.first_body = first_body; - } - - public String getSecond_title() { - return second_title; - } - - public void setSecond_title(String second_title) { - this.second_title = second_title; - } - - public String getSecond_body() { - return second_body; - } - - public void setSecond_body(String second_body) { - this.second_body = second_body; - } - - public String getModal_support_title() { - return modal_support_title; - } - - public void setModal_support_title(String modal_support_title) { - this.modal_support_title = modal_support_title; - } - - public String getModal_support_first_title() { - return modal_support_first_title; - } - - public void setModal_support_first_title(String modal_support_first_title) { - this.modal_support_first_title = modal_support_first_title; - } - - public String getModal_support_first_placeholder() { - return modal_support_first_placeholder; - } - - public void setModal_support_first_placeholder(String modal_support_first_placeholder) { - this.modal_support_first_placeholder = modal_support_first_placeholder; - } - - public String getModal_support_second_title() { - return modal_support_second_title; - } - - public void setModal_support_second_title(String modal_support_second_title) { - this.modal_support_second_title = modal_support_second_title; - } - - public String getModal_support_second_placeholder() { - return modal_support_second_placeholder; - } - - public void setModal_support_second_placeholder(String modal_support_second_placeholder) { - this.modal_support_second_placeholder = modal_support_second_placeholder; - } - - public String getModal_unban_title() { - return modal_unban_title; - } - - public void setModal_unban_title(String modal_unban_title) { - this.modal_unban_title = modal_unban_title; - } - - public String getModal_unban_first_title() { - return modal_unban_first_title; - } - - public void setModal_unban_first_title(String modal_unban_first_title) { - this.modal_unban_first_title = modal_unban_first_title; - } - - public String getModal_unban_first_placeholder() { - return modal_unban_first_placeholder; - } - - public void setModal_unban_first_placeholder(String modal_unban_first_placeholder) { - this.modal_unban_first_placeholder = modal_unban_first_placeholder; - } - - public String getModal_unban_second_title() { - return modal_unban_second_title; - } - - public void setModal_unban_second_title(String modal_unban_second_title) { - this.modal_unban_second_title = modal_unban_second_title; - } - - public String getModal_unban_second_placeholder() { - return modal_unban_second_placeholder; - } - - public void setModal_unban_second_placeholder(String modal_unban_second_placeholder) { - this.modal_unban_second_placeholder = modal_unban_second_placeholder; - } - - public String getModal_unban_third_title() { - return modal_unban_third_title; - } - - public void setModal_unban_third_title(String modal_unban_third_title) { - this.modal_unban_third_title = modal_unban_third_title; - } - - public String getModal_unban_third_placeholder() { - return modal_unban_third_placeholder; - } - - public void setModal_unban_third_placeholder(String modal_unban_third_placeholder) { - this.modal_unban_third_placeholder = modal_unban_third_placeholder; - } - - public String getModal_reason_action_title() { - return modal_reason_action_title; - } - - public void setModal_reason_action_title(String modal_reason_action_title) { - this.modal_reason_action_title = modal_reason_action_title; - } - - public String getModal_reason_action_first_title() { - return modal_reason_action_first_title; - } - - public void setModal_reason_action_first_title(String modal_reason_action_first_title) { - this.modal_reason_action_first_title = modal_reason_action_first_title; - } - - public String getModal_reason_action_first_placeholder() { - return modal_reason_action_first_placeholder; - } - - public void setModal_reason_action_first_placeholder(String modal_reason_action_first_placeholder) { - this.modal_reason_action_first_placeholder = modal_reason_action_first_placeholder; - } - - public String getTicket_support_title() { - return ticket_support_title; - } - - public void setTicket_support_title(String ticket_support_title) { - this.ticket_support_title = ticket_support_title; - } - - public String getTicket_support_body() { - return ticket_support_body; - } - - public void setTicket_support_body(String ticket_support_body) { - this.ticket_support_body = ticket_support_body; - } - - public String getTicket_support_footer() { - return ticket_support_footer; - } - - public void setTicket_support_footer(String ticket_support_footer) { - this.ticket_support_footer = ticket_support_footer; - } - - public String getTicket_support_created() { - return ticket_support_created; - } - - public void setTicket_support_created(String ticket_support_created) { - this.ticket_support_created = ticket_support_created; - } - - public String getTicket_unban_title() { - return ticket_unban_title; - } - - public void setTicket_unban_title(String ticket_unban_title) { - this.ticket_unban_title = ticket_unban_title; - } - - public String getTicket_unban_body() { - return ticket_unban_body; - } - - public void setTicket_unban_body(String ticket_unban_body) { - this.ticket_unban_body = ticket_unban_body; - } - - public String getTicket_unban_footer() { - return ticket_unban_footer; - } - - public void setTicket_unban_footer(String ticket_unban_footer) { - this.ticket_unban_footer = ticket_unban_footer; - } - - public String getTicket_unban_created() { - return ticket_unban_created; - } - - public void setTicket_unban_created(String ticket_unban_created) { - this.ticket_unban_created = ticket_unban_created; - } - - public String getTicket_unban_message_accepted() { - return ticket_unban_message_accepted; - } - - public void setTicket_unban_message_accepted(String ticket_unban_message_accepted) { - this.ticket_unban_message_accepted = ticket_unban_message_accepted; - } - - public String getTicket_unban_message_dismissed() { - return ticket_unban_message_dismissed; - } - - public void setTicket_unban_message_dismissed(String ticket_unban_message_dismissed) { - this.ticket_unban_message_dismissed = ticket_unban_message_dismissed; - } - - public String getTicket_unban_message_sent() { - return ticket_unban_message_sent; - } - - public void setTicket_unban_message_sent(String ticket_unban_message_sent) { - this.ticket_unban_message_sent = ticket_unban_message_sent; - } - - public SupportGroup(String first_title, String first_body, String second_title, String second_body, String modal_support_title, String modal_support_first_title, String modal_support_first_placeholder, String modal_support_second_title, String modal_support_second_placeholder, String modal_unban_title, String modal_unban_first_title, String modal_unban_first_placeholder, String modal_unban_second_title, String modal_unban_second_placeholder, String modal_unban_third_title, String modal_unban_third_placeholder, String modal_reason_action_title, String modal_reason_action_first_title, String modal_reason_action_first_placeholder, String ticket_support_title, String ticket_support_body, String ticket_support_footer, String ticket_support_created, String ticket_unban_title, String ticket_unban_body, String ticket_unban_footer, String ticket_unban_created, String ticket_unban_message_accepted, String ticket_unban_message_dismissed, String ticket_unban_message_sent) { - this.first_title = first_title; - this.first_body = first_body; - this.second_title = second_title; - this.second_body = second_body; - this.modal_support_title = modal_support_title; - this.modal_support_first_title = modal_support_first_title; - this.modal_support_first_placeholder = modal_support_first_placeholder; - this.modal_support_second_title = modal_support_second_title; - this.modal_support_second_placeholder = modal_support_second_placeholder; - this.modal_unban_title = modal_unban_title; - this.modal_unban_first_title = modal_unban_first_title; - this.modal_unban_first_placeholder = modal_unban_first_placeholder; - this.modal_unban_second_title = modal_unban_second_title; - this.modal_unban_second_placeholder = modal_unban_second_placeholder; - this.modal_unban_third_title = modal_unban_third_title; - this.modal_unban_third_placeholder = modal_unban_third_placeholder; - this.modal_reason_action_title = modal_reason_action_title; - this.modal_reason_action_first_title = modal_reason_action_first_title; - this.modal_reason_action_first_placeholder = modal_reason_action_first_placeholder; - this.ticket_support_title = ticket_support_title; - this.ticket_support_body = ticket_support_body; - this.ticket_support_footer = ticket_support_footer; - this.ticket_support_created = ticket_support_created; - this.ticket_unban_title = ticket_unban_title; - this.ticket_unban_body = ticket_unban_body; - this.ticket_unban_footer = ticket_unban_footer; - this.ticket_unban_created = ticket_unban_created; - this.ticket_unban_message_accepted = ticket_unban_message_accepted; - this.ticket_unban_message_dismissed = ticket_unban_message_dismissed; - this.ticket_unban_message_sent = ticket_unban_message_sent; - } -} diff --git a/src/main/java/dev/vxrp/bot/config/util/CONFIG.java b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java similarity index 97% rename from src/main/java/dev/vxrp/bot/config/util/CONFIG.java rename to src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java index 481a47f5..c5dbff3b 100644 --- a/src/main/java/dev/vxrp/bot/config/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.config.util; +package dev.vxrp.bot.util.configuration.util; public class CONFIG { public static final String ACTIVITY_TYPE = "activity_type"; diff --git a/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java similarity index 98% rename from src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java rename to src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index e52a73fb..5be56d2f 100644 --- a/src/main/java/dev/vxrp/bot/config/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.config.util; +package dev.vxrp.bot.util.configuration.util; public class TRANSLATIONS { public static final class SUPPORT { From 88618c66efa4222b18c749423c079583c9d7e4a6 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 19 Oct 2024 02:16:54 +0200 Subject: [PATCH 023/845] Fixed some issues with the translation loading and included some more NoticeOfDeparture functions --- .../dev/vxrp/bot/events/ButtonListener.java | 3 +- .../bot/events/buttons/NoticeOfDeparture.java | 44 +++++++++++++++++++ .../groups/NoticeOfDepartureGroup.java | 3 +- .../translations/TranslationLoader.java | 9 +++- .../util/configuration/util/TRANSLATIONS.java | 8 ++++ .../resources/translations/translations.yml | 7 ++- 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 939e5220..41ac1360 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events; +import dev.vxrp.bot.events.buttons.NoticeOfDeparture; import dev.vxrp.bot.events.buttons.Rules; import dev.vxrp.bot.events.buttons.Support; import dev.vxrp.bot.events.buttons.Unban; @@ -59,7 +60,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { //Notice of Departure if (event.getComponentId().equals("file_nod")) { - + NoticeOfDeparture.createNoticeOfDeparture(event); } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java new file mode 100644 index 00000000..d0a40323 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -0,0 +1,44 @@ +package dev.vxrp.bot.events.buttons; + +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import net.dv8tion.jda.api.interactions.components.ActionRow; +import net.dv8tion.jda.api.interactions.components.text.TextInput; +import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; +import net.dv8tion.jda.api.interactions.modals.Modal; + +public class NoticeOfDeparture { + private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + + public static void createNoticeOfDeparture(ButtonInteractionEvent event) { + event.replyModal( + Modal.create("notice_of_departure", translations.modal_title()) + .addComponents( + ActionRow.of(shortModal( + translations.modal_first_title(), + translations.modal_first_placeholder() + )), + ActionRow.of(paragraphModal( + translations.modal_second_title(), + translations.modal_second_placeholder() + ))) + .build()).queue(); + } + + private static TextInput shortModal(String title, String placeholder) { + return TextInput.create("nod_timeframe", title, TextInputStyle.SHORT) + .setPlaceholder(placeholder) + .setRequired(true) + .setMinLength(10) + .setMaxLength(10) + .build(); + } + private static TextInput paragraphModal(String title, String placeholder) { + return TextInput.create("nod_reason", title, TextInputStyle.PARAGRAPH) + .setPlaceholder(placeholder) + .setRequired(true) + .setMaxLength(1000) + .build(); + } +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java index 28d3c201..263a8438 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -1,4 +1,5 @@ package dev.vxrp.bot.util.configuration.groups; -public record NoticeOfDepartureGroup(String first_title, String first_body) { +public record NoticeOfDepartureGroup(String first_title, String first_body, String modal_title, String modal_first_title, + String modal_first_placeholder, String modal_second_title, String modal_second_placeholder) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index eb935f8e..5bf1829a 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -18,7 +18,7 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY), translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_TITLE), translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE), + translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_PLACEHOLDER), translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE), translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_PLACEHOLDER), translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_TITLE), @@ -46,7 +46,12 @@ public TranslationLoader() { NoticeOfDepartureGroup noticeOfDepartureGroup = new NoticeOfDepartureGroup( translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY) + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.TILE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_TITLE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_TITLE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_PLACEHOLDER) ); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 5be56d2f..dbace15e 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -44,5 +44,13 @@ public static final class TICKET { public static final class NOTICE_OF_DEPARTURE { public static final String FIRST_TITLE = "notice_of_departure.first_title"; public static final String FIRST_BODY = "notice_of_departure.first_body"; + + public static final class MODAL { + public static final String TILE = "notice_of_departure.modal_title"; + public static final String FIRST_TITLE = "notice_of_departure.modal_first_title"; + public static final String FIRST_PLACEHOLDER = "notice_of_departure.modal_first_placeholder"; + public static final String SECOND_TITLE = "notice_of_departure.modal_second_title"; + public static final String SECOND_PLACEHOLDER = "notice_of_departure.modal_second_placeholder"; + } } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 67c3071a..27bc6fa4 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -1,4 +1,5 @@ # You can use any form of discord formatting in these translations +# The bot will load the translations in memory on startup. To apply changes, restart the bot # # Support @@ -114,4 +115,8 @@ notice_of_departure: Every timespan over 1 year will not be accepted and will be asked to leave the team " - modal_ + modal_title: "File Notice of Departure" + modal_first_title: "Away time?" + modal_first_placeholder: "How long will you be away **[dd.MM.yyyy]**" + modal_second_title: "Explanation" + modal_second_placeholder: "Why are you going to be away [exclude details]" From 54e4b9ab92d52d728008b139bf3efbf11cc877fe Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:53:21 +0200 Subject: [PATCH 024/845] Updated README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9aee8a89..237b9100 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ ScpToolsBot is a discord bot application written in Java for Scp Secret Laborato If you need any more information check out the [wiki](https://github.com/Vxrpenter/SCPToolsBot/wiki) ## Installation +This bot application should be installed on a alltime running server with good internet connection to handle requests fast and be online all the time + 1. Download the `.jar` file from the latest **STABLE** release 2. Install `JDK-17` or higher on your machine 3. Run the jar using `java -jar ` From 36da5488017e70e97b5db5fae2120f2e254f3d7e Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Mon, 21 Oct 2024 18:42:32 +0200 Subject: [PATCH 025/845] Update README.md --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 237b9100..d982512d 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,19 @@
## What is ScpToolsBot -ScpToolsBot is a discord bot application written in Java for Scp Secret Laboratory discord servers. It includes support functions, cedmod api syncing, community and even team management features +ScpToolsBot is a discord bot application written in Java for Scp Secret Laboratory discord servers. It includes support functions, cedmod api syncing, community and team management features If you need any more information check out the [wiki](https://github.com/Vxrpenter/SCPToolsBot/wiki) +## Feature Overview +Currently the bot comes with: +- Support system with unban file +- SL ruleparsing +- Text translation for features +- Configurable commands + +More coming soon, look [here](https://github.com/Vxrpenter/SCPToolsBot/wiki/Feature-Overview) for more complete overview + ## Installation This bot application should be installed on a alltime running server with good internet connection to handle requests fast and be online all the time From 5d7d02230d21ba721e4cacbe34214fcf3f2303fa Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:01:42 +0200 Subject: [PATCH 026/845] Reorganized main slightly --- src/main/java/dev/vxrp/bot/ScpTools.java | 49 ++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index e84be458..a0608c91 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -31,6 +31,28 @@ public class ScpTools { public final static Logger logger = LoggerFactory.getLogger(ScpTools.class); public static void main(String[] args) { + initializeConfigs(); + loadConfigs(); + + Activity.ActivityType activityType = Activity.ActivityType.valueOf(configManager.getString(CONFIG.ACTIVITY_TYPE)); + logger.info("ActivityType set to {}", ColorTool.apply(DCColor.RED, activityType.toString())); + String activityContent = configManager.getString(CONFIG.ACTIVITY_CONTENT); + logger.info("ActivityContent set to {}", ColorTool.apply(DCColor.RED, activityContent)); + + checkGuildID(); + initializeBot(activityType, activityContent); + } + + private static void loadConfigs() { + try { + new TranslationLoader(); + logger.info("Loaded translations into memory"); + } catch (Exception e) { + logger.error("Could not load translation to memory {}", e.getMessage()); + } + } + + private static void initializeConfigs() { List folders = Arrays.asList("configs", "translations"); for (String folder : folders) { String folderPath = Paths.get(folder).toString(); @@ -38,28 +60,33 @@ public static void main(String[] args) { logger.info("Loading configs from {}", folderPath); } - configManager = new ConfigManager(); - translationManager = new TranslationManager(); - colorConfigManager = new ColorConfigManager(); - try { - new TranslationLoader(); - logger.info("Loaded translations into memory"); + configManager = new ConfigManager(); } catch (Exception e) { - logger.error("Could not load translation to memory {}", e.getMessage()); + logger.error("Could not load configs from configManager : {}", e.getMessage()); + } + try { + translationManager = new TranslationManager(); + } catch (Exception e) { + logger.error("Could not load configs from translationManager : {}", e.getMessage()); + } + try { + colorConfigManager = new ColorConfigManager(); + } catch (Exception e) { + logger.error("Could not load configs from colorConfigManager : {}", e.getMessage()); } + } - Activity.ActivityType activityType = Activity.ActivityType.valueOf(configManager.getString(CONFIG.ACTIVITY_TYPE)); - logger.info("ActivityType set to {}", ColorTool.apply(DCColor.RED, activityType.toString())); - String activityContent = configManager.getString(CONFIG.ACTIVITY_CONTENT); - logger.info("ActivityContent set to {}", ColorTool.apply(DCColor.RED, activityContent)); + private static void checkGuildID() { if (configManager.getString("guild_id") == null || Objects.equals(configManager.getString("guild_id"), "")) { logger.error("Guild id is {}. Process shutting down", ColorTool.apply(DCColor.RED, "null")); return; } else { logger.info("Launching under guild id {}", ColorTool.apply(DCColor.GREEN, configManager.getString("guild_id"))); } + } + private static void initializeBot(Activity.ActivityType activityType, String activityContent) { JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT) .setActivity(Activity.of(activityType, activityContent)) .disableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOJI, CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS) From c4cf8c6fe2cf0932a189916be68753da13f8ea34 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:06:32 +0200 Subject: [PATCH 027/845] Now loading configs more efficiently --- src/main/java/dev/vxrp/bot/ScpTools.java | 7 ++++ .../configuration/LoadedConfigurations.java | 15 ++++++++ .../configuration/configs/ConfigLoader.java | 34 +++++++++++++++++++ .../configuration/groups/ConfigGroup.java | 12 +++++++ .../bot/util/configuration/util/CONFIG.java | 2 ++ 5 files changed, 70 insertions(+) create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index a0608c91..afd40409 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -6,6 +6,7 @@ import dev.vxrp.bot.commands.templates.TemplateCommand; import dev.vxrp.bot.config.managers.ColorConfigManager; import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.util.configuration.configs.ConfigLoader; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.config.managers.ConfigManager; import dev.vxrp.bot.events.ModalListener; @@ -50,6 +51,12 @@ private static void loadConfigs() { } catch (Exception e) { logger.error("Could not load translation to memory {}", e.getMessage()); } + try { + new ConfigLoader(); + logger.info("Loaded config into memory"); + } catch (Exception e) { + logger.error("Could not load config to memory {}", e.getMessage()); + } } private static void initializeConfigs() { diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java index a21bbcd2..cca7d105 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.util.configuration; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; @@ -7,9 +8,23 @@ import java.util.Iterator; public class LoadedConfigurations { + public static HashSet configMemoryLoad = new HashSet<>(); public static HashSet supportTranslationMemoryLoad = new HashSet<>(); public static HashSet noticeOfDepartureMemoryLoad = new HashSet<>(); + public static ConfigGroup getConfigMemoryLoad() { + Iterator iterator = configMemoryLoad.iterator(); + ConfigGroup configGroup = null; + while (iterator.hasNext()) { + configGroup = iterator.next(); + } + return configGroup; + } + + public static void setConfigMemoryLoad(ConfigGroup configGroup) { + LoadedConfigurations.configMemoryLoad.add(configGroup); + } + public static SupportGroup getSupportTranslationMemoryLoad() { Iterator iterator = supportTranslationMemoryLoad.iterator(); SupportGroup supportGroup = null; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java new file mode 100644 index 00000000..d5607186 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -0,0 +1,34 @@ +package dev.vxrp.bot.util.configuration.configs; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.config.managers.ConfigManager; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; +import dev.vxrp.bot.util.configuration.util.CONFIG; + +public class ConfigLoader { + public ConfigLoader() { + ConfigManager configManager = ScpTools.getConfigManager(); + + ConfigGroup configGroup = new ConfigGroup( + configManager.getString(CONFIG.TOKEN), + configManager.getString(CONFIG.GUILD_ID), + configManager.getString(CONFIG.ACTIVITY_TYPE), + configManager.getString(CONFIG.ACTIVITY_CONTENT), + configManager.getString(CONFIG.RULES.PASTEBIN), + configManager.getString(CONFIG.RULES.EMBED_FOOTER), + configManager.getStringList(CONFIG.COMMANDS), + configManager.getStringList(CONFIG.COMMAND_SETTINGS.DEFAULT_PERMISSIONS.HELP), + configManager.getString(CONFIG.COMMAND_SETTINGS.DESCRIPTIONS.HELP), + configManager.getStringList(CONFIG.COMMAND_SETTINGS.DEFAULT_PERMISSIONS.TEMPLATE), + configManager.getString(CONFIG.COMMAND_SETTINGS.DESCRIPTIONS.TEMPLATE), + configManager.getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_SUPPORT_TICKETS), + configManager.getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_UNBAN_TICKETS), + configManager.getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID), + configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.DESCISION_CHANNEL_ID), + configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.NOTICE_CHANNEL_ID), + configManager.getBoolean(CONFIG.CEDMOD.ACTIVE), + configManager.getString(CONFIG.CEDMOD.INSTANCE_URL), + configManager.getString(CONFIG.CEDMOD.API_KEY), + configManager.getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID)); + } +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java new file mode 100644 index 00000000..f3c89406 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java @@ -0,0 +1,12 @@ +package dev.vxrp.bot.util.configuration.groups; + +import java.util.List; + +public record ConfigGroup(String token, String guild_id, String activity_type, String activity_content, + String rules_pastebin, String rules_embed_footer, List commands, List command_setting_help_default_permissions, + String command_settings_help_description, List command_settings_template_default_permissions, + String command_settings_template_descriptions, List support_settings_roles_access_support_tickets, + List support_settings_roles_access_unban_tickets, String support_settings_unban_channel_id, + String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, boolean cedmod_active, + String cedmod_instance_url, String cedmod_api_key, String cedmod_cedmod) { +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java index c5dbff3b..f7fa956e 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java @@ -1,6 +1,8 @@ package dev.vxrp.bot.util.configuration.util; public class CONFIG { + public static final String TOKEN = "token"; + public static final String GUILD_ID = "guild_id"; public static final String ACTIVITY_TYPE = "activity_type"; public static final String ACTIVITY_CONTENT = "activity_content"; public static final String COMMANDS = "commands"; From 0b82b4c09f3992539f1b5c3f97e46eb5be9fe2cb Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:52:04 +0200 Subject: [PATCH 028/845] Change made for every config call to use new method --- .../dev/vxrp/bot/commands/CommandManager.java | 17 ++++++++++------- .../templates/rules/RulesTemplateUnit.java | 7 +++++-- .../dev/vxrp/bot/events/modals/Support.java | 4 +++- .../java/dev/vxrp/bot/events/modals/Unban.java | 14 +++++++------- .../util/configuration/groups/ConfigGroup.java | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index 6e4d1c6d..397a3550 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -1,6 +1,8 @@ package dev.vxrp.bot.commands; import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.converter.PermissionListConverter; import net.dv8tion.jda.api.JDA; @@ -16,22 +18,23 @@ import java.util.List; public class CommandManager { - public final static Logger logger = LoggerFactory.getLogger(CommandManager.class); - public CommandManager() {} + private final static Logger logger = LoggerFactory.getLogger(CommandManager.class); + private final static ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); + public void Initialize(JDA api) { - List activeCommands = ScpTools.getConfigManager().getStringList(CONFIG.COMMANDS); - List helpDefaultPermissions = ScpTools.getConfigManager().getStringList(CONFIG.COMMAND_SETTINGS.DEFAULT_PERMISSIONS.HELP); - List templateDefaultPermissions = ScpTools.getConfigManager().getStringList(CONFIG.COMMAND_SETTINGS.DEFAULT_PERMISSIONS.TEMPLATE); + List activeCommands = configs.commands(); + List helpDefaultPermissions = configs.command_setting_help_default_permissions(); + List templateDefaultPermissions = configs.command_settings_template_default_permissions(); List commands = new ArrayList<>(); if (activeCommands.contains("help")) { - commands.add(Commands.slash("help", ScpTools.getConfigManager().getString(CONFIG.COMMAND_SETTINGS.DESCRIPTIONS.HELP)) + commands.add(Commands.slash("help", configs.command_settings_help_description()) .setDefaultPermissions(DefaultMemberPermissions.enabledFor(new PermissionListConverter(helpDefaultPermissions).convert()))); } else { logger.warn("Command help is deactivated, it is highly recommended to leave this command on"); } if (activeCommands.contains("template")) { - commands.add(Commands.slash("template", ScpTools.getConfigManager().getString(CONFIG.COMMAND_SETTINGS.DESCRIPTIONS.TEMPLATE)) + commands.add(Commands.slash("template", configs.command_settings_template_descriptions()) .setDefaultPermissions(DefaultMemberPermissions.enabledFor(new PermissionListConverter(templateDefaultPermissions).convert())) .addOptions( new OptionData(OptionType.STRING, "template", "What template are you referring to", true) diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index 56b76b89..cf2ad61a 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -1,6 +1,8 @@ package dev.vxrp.bot.commands.templates.rules; import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.pastebin.PastebinUtil; import dev.vxrp.bot.util.parser.CustomColorParser; @@ -16,10 +18,11 @@ import java.util.Objects; public class RulesTemplateUnit { + private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); private static EmbedBuilder embed(Guild guild, TextChannel channel) { String rules; try { - rules = PastebinUtil.getPasteBin("https://pastebin.com/raw/"+ScpTools.getConfigManager().getString(CONFIG.RULES.PASTEBIN)); + rules = PastebinUtil.getPasteBin("https://pastebin.com/raw/"+configs.rules_pastebin()); } catch (IOException e) { assert channel != null; channel.sendMessage("Failed to retrieve rules").queue(); @@ -28,7 +31,7 @@ private static EmbedBuilder embed(Guild guild, TextChannel channel) { return new EmbedBuilder() .setDescription("```ansi\n"+ CustomColorParser.parse(rules) +"\n```") - .setFooter(ScpTools.getConfigManager().getString(CONFIG.RULES.EMBED_FOOTER), guild.getIconUrl()); + .setFooter(configs.rules_embed_footer(), guild.getIconUrl()); } public static void pasteRules(ButtonInteractionEvent event) { diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index e0db707f..004cfb6a 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,6 +1,7 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; @@ -22,6 +23,7 @@ public class Support { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); + private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); public static void createSupportTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); @@ -45,7 +47,7 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge event.reply(translations.ticket_support_created() .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); - List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_SUPPORT_TICKETS); + List roleIDs = configs.support_settings_roles_access_support_tickets(); for (String id : roleIDs) { textChannel.upsertPermissionOverride( Objects.requireNonNull(guild.getRoleById(id))) diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 25dcc541..74355837 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,7 +1,6 @@ package dev.vxrp.bot.events.modals; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.configuration.util.CONFIG; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.cedmod.CedModApi; @@ -28,6 +27,7 @@ public class Unban { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); + private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); @@ -44,13 +44,13 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); - TextChannel textChannel = event.getGuild().getTextChannelById(ScpTools.getConfigManager().getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID)); + TextChannel textChannel = event.getGuild().getTextChannelById(configs.support_settings_unban_channel_id()); assert textChannel != null; event.reply(translations.ticket_unban_created() .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); - List roleIDs = ScpTools.getConfigManager().getStringList(CONFIG.SUPPORT_SETTINGS.ROLES_ACCESS_UNBAN_TICKETS); + List roleIDs = configs.support_settings_roles_access_unban_tickets(); for (String id : roleIDs) { textChannel.upsertPermissionOverride( Objects.requireNonNull(guild.getRoleById(id))) @@ -86,9 +86,9 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { String steamID = event.getModalId().split(":")[2]; String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); - String instanceUrl = ScpTools.getConfigManager().getString(CONFIG.CEDMOD.INSTANCE_URL); - String apiKey = ScpTools.getConfigManager().getString(CONFIG.CEDMOD.API_KEY); - String banListID = ScpTools.getConfigManager().getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID); + String instanceUrl = configs.cedmod_instance_url(); + String apiKey = configs.cedmod_api_key(); + String banListID = configs.cedmod_master_banlist_id(); String banID = CedModApi.getBanId(instanceUrl, apiKey, banListID, steamID); bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java index f3c89406..813e4a42 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java @@ -8,5 +8,5 @@ public record ConfigGroup(String token, String guild_id, String activity_type, S String command_settings_template_descriptions, List support_settings_roles_access_support_tickets, List support_settings_roles_access_unban_tickets, String support_settings_unban_channel_id, String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, boolean cedmod_active, - String cedmod_instance_url, String cedmod_api_key, String cedmod_cedmod) { + String cedmod_instance_url, String cedmod_api_key, String cedmod_master_banlist_id) { } From 31ee3226e13dbcfc70cdc3842d218418185819d5 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:15:51 +0200 Subject: [PATCH 029/845] Added @NotNull to ColorTool --- src/main/java/dev/vxrp/bot/util/colors/ColorTool.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java index f9418818..24482066 100644 --- a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java +++ b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java @@ -1,10 +1,12 @@ package dev.vxrp.bot.util.colors; import dev.vxrp.bot.util.Enums.DCColor; +import org.jetbrains.annotations.NotNull; public class ColorTool { + @NotNull public static String apply(DCColor color, String text) { switch (color) { case DARK_GRAY -> { From 48a053e9382c86e9ac30f807b115c2adea50becf Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:16:29 +0200 Subject: [PATCH 030/845] Some more configuration loading fixes --- .../util/configuration/configs/ConfigLoader.java | 3 +++ .../groups/NoticeOfDepartureGroup.java | 3 ++- .../translations/TranslationLoader.java | 7 +++++-- src/main/resources/translations/translations.yml | 13 ++++++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index d5607186..749dcce0 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.ConfigManager; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; @@ -30,5 +31,7 @@ public ConfigLoader() { configManager.getString(CONFIG.CEDMOD.INSTANCE_URL), configManager.getString(CONFIG.CEDMOD.API_KEY), configManager.getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID)); + + LoadedConfigurations.setConfigMemoryLoad(configGroup); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java index 263a8438..700c9f01 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.util.configuration.groups; public record NoticeOfDepartureGroup(String first_title, String first_body, String modal_title, String modal_first_title, - String modal_first_placeholder, String modal_second_title, String modal_second_placeholder) { + String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, + String ticket_title, String ticket_body, String ticket_footer, String ticket_created) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 5bf1829a..9899ed7a 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -51,8 +51,11 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_TITLE), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_PLACEHOLDER), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_PLACEHOLDER) - ); + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_PLACEHOLDER), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.TITLE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.BODY), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.FOOTER), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.CREATED)); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 27bc6fa4..f1d7aba7 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -65,7 +65,7 @@ support: ticket_unban_title: "%name%" ticket_unban_body: " - Unban Request is getting reviewed. A response from our moderation team may take a bit\n + Unban Request is getting reviewed.\n __**Steam ID:**__\n ||%steamID%||\n @@ -120,3 +120,14 @@ notice_of_departure: modal_first_placeholder: "How long will you be away **[dd.MM.yyyy]**" modal_second_title: "Explanation" modal_second_placeholder: "Why are you going to be away [exclude details]" + + ticket_title: "Notice of departure - #%number%" + ticket_body: " + __**Timespan**__ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ + ```%day%.%month%.%year%``` + + __**Reason:**__ + ```%reason%``` + " + ticket_footer: "Created on the %date% at %time%h" + ticket_created: "Your notice will be reviewed real soon" \ No newline at end of file From 35e28eefbb28d85bbcdebf31331e3de9798ef7cb Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:16:44 +0200 Subject: [PATCH 031/845] Forgot one thing --- .../dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index dbace15e..0f57ac87 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -52,5 +52,11 @@ public static final class MODAL { public static final String SECOND_TITLE = "notice_of_departure.modal_second_title"; public static final String SECOND_PLACEHOLDER = "notice_of_departure.modal_second_placeholder"; } + public static final class TICKET { + public static final String TITLE = "notice_of_departure.ticket_title"; + public static final String BODY = "notice_of_departure.ticket_body"; + public static final String FOOTER = "notice_of_departure.ticket_footer"; + public static final String CREATED = "notice_of_departure.ticket_created"; + } } } From 293799eeaeeb62c3e02aa0da7938a73c838c4af9 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:17:30 +0200 Subject: [PATCH 032/845] A work in progress notice of departure embed request --- .../dev/vxrp/bot/events/ModalListener.java | 7 ++- .../bot/events/buttons/NoticeOfDeparture.java | 2 +- .../bot/events/modals/NoticeOfDeparture.java | 50 +++++++++++++++++-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index b21d9bee..a5c324bd 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events; +import dev.vxrp.bot.events.modals.NoticeOfDeparture; import dev.vxrp.bot.events.modals.Support; import dev.vxrp.bot.events.modals.Unban; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; @@ -8,8 +9,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; public class ModalListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ModalListener.class); @@ -33,5 +32,9 @@ public void onModalInteraction(ModalInteractionEvent event) { if (event.getModalId().startsWith("reason_action_reason_dismiss")) { Unban.dismissUnban(event); } + + if (event.getModalId().equals("notice_of_departure")) { + NoticeOfDeparture.createNewNoticeOfDeparture(event); + } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index d0a40323..976fda31 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -30,7 +30,7 @@ private static TextInput shortModal(String title, String placeholder) { return TextInput.create("nod_timeframe", title, TextInputStyle.SHORT) .setPlaceholder(placeholder) .setRequired(true) - .setMinLength(10) + .setMinLength(8) .setMaxLength(10) .build(); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 984cbec7..ecbae3a0 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -1,13 +1,53 @@ package dev.vxrp.bot.events.modals; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; -import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.builder.StatsBuilder; +import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; +import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; +import net.dv8tion.jda.api.interactions.components.buttons.Button; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Objects; +import java.util.concurrent.ThreadLocalRandom; public class NoticeOfDeparture { - private static final TranslationManager translationManager = ScpTools.getTranslationManager(); + private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); + private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + + public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { + TextChannel channel = Objects.requireNonNull(event.getGuild()).getTextChannelById(configs.notice_of_departure_decision_channel_id()); + String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); + String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); + String[] givenDate = Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString().split("\\."); + String reason = Objects.requireNonNull(event.getValue("nod_reason")).getAsString(); - public static void createNewNoticeOfDeparture(ButtonInteractionEvent event) { + event.reply(translations.ticket_created()).setEphemeral(true).queue(); + assert channel != null; + channel.sendMessageEmbeds( + StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), + new EmbedBuilder() + .setTitle(translations.ticket_title().replace("%number%", String.valueOf(ThreadLocalRandom.current().nextInt(1938, 9750)))) + .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) + .setDescription(translations.ticket_body() + .replace("%day%", ColorTool.apply(DCColor.GREEN, givenDate[0])) + .replace("%month%", ColorTool.apply(DCColor.RED, givenDate[1])) + .replace("%year%", ColorTool.apply(DCColor.GOLD, givenDate[2])) + .replace("%reason%", reason)) + .setFooter(translations.ticket_footer() + .replace("%date%", date) + .replace("%time%", time)) + .build()) + .addActionRow( + Button.success("accept_ticket_notice_of_departure", "Accept Ticket"), + Button.danger("dismiss_ticket_notice_of_departure", "Dismiss Ticket") + ).queue(); } } \ No newline at end of file From 652487bd59f4931e1e206ce79aece3b7b5dd7348 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:19:19 +0200 Subject: [PATCH 033/845] Updated the translations.yml --- .../vxrp/bot/events/modals/NoticeOfDeparture.java | 1 - src/main/resources/translations/translations.yml | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index ecbae3a0..edd22438 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -7,7 +7,6 @@ import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index f1d7aba7..e07e9dc0 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -1,4 +1,6 @@ # You can use any form of discord formatting in these translations +# \n will apply a linebreak +# Everything surrounded like this: %value% will be replaced # The bot will load the translations in memory on startup. To apply changes, restart the bot # @@ -122,11 +124,15 @@ notice_of_departure: modal_second_placeholder: "Why are you going to be away [exclude details]" ticket_title: "Notice of departure - #%number%" + # If you remove the ```ansi ``` then the color rendering will be messed up, so be careful ticket_body: " - __**Timespan**__ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ - ```%day%.%month%.%year%``` + ```If accepted this user and the date will be added to the database and you will be notified when it runs out```\n + __**Timespan**__\n + ```ansi\n + %day%.%month%.%year% + ```\n - __**Reason:**__ + __**Reason:**__\n ```%reason%``` " ticket_footer: "Created on the %date% at %time%h" From 1f162cc50f61af77e9f202b005a2febbd743e56d Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:54:58 +0200 Subject: [PATCH 034/845] Updated NOD embed --- .../vxrp/bot/events/modals/NoticeOfDeparture.java | 12 +++++++++--- src/main/java/dev/vxrp/bot/util/Enums/DCColor.java | 3 ++- .../java/dev/vxrp/bot/util/colors/ColorTool.java | 3 +++ src/main/resources/translations/translations.yml | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index edd22438..f74896d9 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -27,6 +27,9 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { String[] givenDate = Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString().split("\\."); String reason = Objects.requireNonNull(event.getValue("nod_reason")).getAsString(); + String day = new SimpleDateFormat("dd").format(Calendar.getInstance().getTime()); + String month = new SimpleDateFormat("MM").format(Calendar.getInstance().getTime()); + String year = new SimpleDateFormat("yyyy").format(Calendar.getInstance().getTime()); event.reply(translations.ticket_created()).setEphemeral(true).queue(); assert channel != null; @@ -36,9 +39,12 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { .setTitle(translations.ticket_title().replace("%number%", String.valueOf(ThreadLocalRandom.current().nextInt(1938, 9750)))) .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) .setDescription(translations.ticket_body() - .replace("%day%", ColorTool.apply(DCColor.GREEN, givenDate[0])) - .replace("%month%", ColorTool.apply(DCColor.RED, givenDate[1])) - .replace("%year%", ColorTool.apply(DCColor.GOLD, givenDate[2])) + .replace("%current_day%", ColorTool.apply(DCColor.BOLD, day)) + .replace("%current_month%", ColorTool.apply(DCColor.BOLD, month)) + .replace("%current_year%", ColorTool.apply(DCColor.BOLD, year)) + .replace("%day%", ColorTool.apply(DCColor.BOLD, givenDate[0])) + .replace("%month%", ColorTool.apply(DCColor.BOLD, givenDate[1])) + .replace("%year%", ColorTool.apply(DCColor.BOLD, givenDate[2])) .replace("%reason%", reason)) .setFooter(translations.ticket_footer() .replace("%date%", date) diff --git a/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java b/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java index 91fb69b7..aaf80a8f 100644 --- a/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java +++ b/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java @@ -8,5 +8,6 @@ public enum DCColor { LIGHT_BLUE, PINK, TEAL, - WHITE + WHITE, + BOLD } diff --git a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java index 24482066..67285209 100644 --- a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java +++ b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java @@ -33,6 +33,9 @@ public static String apply(DCColor color, String text) { case WHITE -> { return "\u001B[2;37m"+text+"\u001B[0m"; } + case BOLD -> { + return "\u001B[1;2m"+text+"\u001B[0m"; + } } return null; } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index e07e9dc0..1cc9789b 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -129,7 +129,7 @@ notice_of_departure: ```If accepted this user and the date will be added to the database and you will be notified when it runs out```\n __**Timespan**__\n ```ansi\n - %day%.%month%.%year% + %current_day%.%current_month%.%current_year% till %day%.%month%.%year% ```\n __**Reason:**__\n From 45efdaa126f1fd4b733500d8decba45fe260d6ee Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:33:38 +0200 Subject: [PATCH 035/845] Added sqlite database for storing notice of departure data --- .idea/dataSources.xml | 15 +++ .idea/discord.xml | 7 ++ .idea/inspectionProfiles/Project_Default.xml | 13 +++ .idea/sqldialects.xml | 7 ++ build.gradle.kts | 1 + src/main/java/dev/vxrp/bot/ScpTools.java | 20 +++- .../bot/database/sqlite/SqliteManager.java | 106 ++++++++++++++++++ 7 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 .idea/dataSources.xml create mode 100644 .idea/discord.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/sqldialects.xml create mode 100644 src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 00000000..4251c34b --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,15 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:/sqlite/data.db + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 00000000..d8e95616 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..da7dab40 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 00000000..ee778ea4 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 7bec2c99..b945664b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,7 @@ repositories { } dependencies { + implementation("org.xerial:sqlite-jdbc:3.45.1.0") implementation("net.dv8tion:JDA:$jdaVersion") implementation("ch.qos.logback:logback-classic:1.5.6") testImplementation(platform("org.junit:junit-bom:5.10.0")) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index afd40409..3a02bd97 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -1,5 +1,6 @@ package dev.vxrp.bot; +import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.events.ButtonListener; import dev.vxrp.bot.commands.CommandManager; import dev.vxrp.bot.commands.help.HelpCommand; @@ -23,16 +24,19 @@ import java.io.File; import java.nio.file.Paths; +import java.sql.SQLException; import java.util.*; public class ScpTools { static ConfigManager configManager; static TranslationManager translationManager; static ColorConfigManager colorConfigManager; + static SqliteManager sqliteManager; - public final static Logger logger = LoggerFactory.getLogger(ScpTools.class); - public static void main(String[] args) { + private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); + public static void main(String[] args) throws SQLException { initializeConfigs(); + initializeSqlite(); loadConfigs(); Activity.ActivityType activityType = Activity.ActivityType.valueOf(configManager.getString(CONFIG.ACTIVITY_TYPE)); @@ -44,6 +48,14 @@ public static void main(String[] args) { initializeBot(activityType, activityContent); } + private static void initializeSqlite() { + try { + sqliteManager = new SqliteManager(System.getProperty("user.dir")+"\\sqlite\\data.db"); + } catch (SQLException e) { + logger.error("Could not correctly set up Sqlite database {}", e.getMessage()); + } + } + private static void loadConfigs() { try { new TranslationLoader(); @@ -60,11 +72,11 @@ private static void loadConfigs() { } private static void initializeConfigs() { - List folders = Arrays.asList("configs", "translations"); + List folders = Arrays.asList("configs", "translations", "sqlite"); for (String folder : folders) { String folderPath = Paths.get(folder).toString(); new File(folderPath).mkdirs(); - logger.info("Loading configs from {}", folderPath); + logger.info("Created folder {}", folderPath); } try { diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java new file mode 100644 index 00000000..e70dda37 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -0,0 +1,106 @@ +package dev.vxrp.bot.database.sqlite; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.colors.ColorTool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.*; + +public class SqliteManager { + private final Connection connection; + private final Logger logger = LoggerFactory.getLogger(SqliteManager.class); + + public SqliteManager(String path) throws SQLException { + connection = DriverManager.getConnection("jdbc:sqlite:"+path); + try (Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TABLE IF NOT EXISTS notice_of_departure (" + + "id TEXT PRIMARY KEY," + + "start_time TEXT NOT NULL," + + "end_time TEXT NOT NULL" + + ");"); + } + logger.info("Set up Sqlite database correctly"); + } + + public void addNoticeOfDeparture(String id,String start_time, String end_time) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?)")) { + statement.setString(1, id); + statement.setString(2, start_time); + statement.setString(3, end_time); + statement.executeUpdate(); + logger.info("Added notice of departure - id:{} , start_time:{} , end_time:{}", + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, start_time), + ColorTool.apply(DCColor.GOLD, end_time)); + } + } + + public void updateNoticeOfDeparture(String id,String start_time, String end_time) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=?, end_time=? WHERE id=?")) { + statement.setString(1, start_time); + statement.setString(2, end_time); + statement.setString(3, id); + statement.executeUpdate(); + logger.info("Updated notice of departure - id:{} , start_time:{} , end_time:{}", + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, start_time), + ColorTool.apply(DCColor.GOLD, end_time)); + } + } + + public void updateStartTime(String id,String start_time) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { + statement.setString(1, start_time); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("Updated start_time - id:{} , start_time:{}", + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, start_time)); + } + } + + public void updateEndTime(String id,String end_time) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET end_time=? WHERE id=?")) { + statement.setString(1, end_time); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("Updated end_time - id:{} , end_time:{}", + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, end_time)); + } + } + + public String getStartTime(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT start_time FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return resultSet.getString("start_time"); + } + } + } + + public String getEndTime(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT end_time FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return resultSet.getString("end_time"); + } + } + } + + public boolean exists(String id) { + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return true; + } catch (SQLException e) { + return false; + } + } catch (SQLException e) { + return false; + } + } +} From 764b7e4608aa75234e0239594e3495526c4558c6 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:45:50 +0200 Subject: [PATCH 036/845] Improved logger --- src/main/java/dev/vxrp/bot/ScpTools.java | 4 +--- .../java/dev/vxrp/bot/database/sqlite/SqliteManager.java | 3 +-- .../vxrp/bot/util/configuration/configs/ConfigLoader.java | 5 +++++ .../util/configuration/translations/TranslationLoader.java | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 3a02bd97..e9225751 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -32,8 +32,8 @@ public class ScpTools { static TranslationManager translationManager; static ColorConfigManager colorConfigManager; static SqliteManager sqliteManager; - private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); + public static void main(String[] args) throws SQLException { initializeConfigs(); initializeSqlite(); @@ -59,13 +59,11 @@ private static void initializeSqlite() { private static void loadConfigs() { try { new TranslationLoader(); - logger.info("Loaded translations into memory"); } catch (Exception e) { logger.error("Could not load translation to memory {}", e.getMessage()); } try { new ConfigLoader(); - logger.info("Loaded config into memory"); } catch (Exception e) { logger.error("Could not load config to memory {}", e.getMessage()); } diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index e70dda37..ce5690b5 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -1,6 +1,5 @@ package dev.vxrp.bot.database.sqlite; -import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; import org.slf4j.Logger; @@ -103,4 +102,4 @@ public boolean exists(String id) { return false; } } -} +} \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 749dcce0..6c18f1f8 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -5,8 +5,12 @@ import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ConfigLoader { + private final static Logger logger = LoggerFactory.getLogger(ConfigLoader.class); + public ConfigLoader() { ConfigManager configManager = ScpTools.getConfigManager(); @@ -33,5 +37,6 @@ public ConfigLoader() { configManager.getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID)); LoadedConfigurations.setConfigMemoryLoad(configGroup); + logger.info("Loaded config into memory"); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 9899ed7a..e51bc673 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -6,8 +6,12 @@ import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TranslationLoader { + private final static Logger logger = LoggerFactory.getLogger(TranslationLoader.class); + public TranslationLoader() { TranslationManager translationManager = ScpTools.getTranslationManager(); @@ -59,5 +63,6 @@ public TranslationLoader() { LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); + logger.info("Loaded translations into memory"); } } From 7bf0576ae1f4e021c7cb6e77e942c4663086f9ba Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:56:01 +0200 Subject: [PATCH 037/845] Finalized SqliteManager --- src/main/java/dev/vxrp/bot/ScpTools.java | 3 ++ .../bot/database/sqlite/SqliteManager.java | 35 ++++++++++++++++--- .../bot/util/objects/NoticeOfDeparture.java | 4 +++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index e9225751..16495895 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -123,4 +123,7 @@ public static TranslationManager getTranslationManager() { public static ColorConfigManager getColorConfigManager() { return colorConfigManager; } + public static SqliteManager getSqliteManager() { + return sqliteManager; + } } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index ce5690b5..d66b84f7 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.objects.NoticeOfDeparture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,7 +22,8 @@ public SqliteManager(String path) throws SQLException { "end_time TEXT NOT NULL" + ");"); } - logger.info("Set up Sqlite database correctly"); + logger.info("{} - Set up Sqlite database correctly", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite"))); } public void addNoticeOfDeparture(String id,String start_time, String end_time) throws SQLException { @@ -30,7 +32,8 @@ public void addNoticeOfDeparture(String id,String start_time, String end_time) t statement.setString(2, start_time); statement.setString(3, end_time); statement.executeUpdate(); - logger.info("Added notice of departure - id:{} , start_time:{} , end_time:{}", + logger.info("{} - Added notice of departure - id:{} , start_time:{} , end_time:{}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, start_time), ColorTool.apply(DCColor.GOLD, end_time)); @@ -43,7 +46,8 @@ public void updateNoticeOfDeparture(String id,String start_time, String end_time statement.setString(2, end_time); statement.setString(3, id); statement.executeUpdate(); - logger.info("Updated notice of departure - id:{} , start_time:{} , end_time:{}", + logger.info("{} - Updated notice of departure - id: {} , start_time: {} , end_time: {}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, start_time), ColorTool.apply(DCColor.GOLD, end_time)); @@ -55,7 +59,8 @@ public void updateStartTime(String id,String start_time) throws SQLException { statement.setString(1, start_time); statement.setString(2, id); statement.executeUpdate(); - logger.info("Updated start_time - id:{} , start_time:{}", + logger.info("{} - Updated start_time - id: {} , start_time: {}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, start_time)); } @@ -66,12 +71,32 @@ public void updateEndTime(String id,String end_time) throws SQLException { statement.setString(1, end_time); statement.setString(2, id); statement.executeUpdate(); - logger.info("Updated end_time - id:{} , end_time:{}", + logger.info("{} - Updated end_time - id: {} , end_time: {}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, end_time)); } } + public void deleteNoticeOfDeparture(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("DELETE FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + statement.executeUpdate(); + logger.info("{} - Deleted notice of departure - id: {}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + ColorTool.apply(DCColor.RED, id)); + } + } + + public NoticeOfDeparture getNoticeOfDeparture(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return new NoticeOfDeparture(resultSet.getString("start_time"), resultSet.getString("end_time")); + } + } + } + public String getStartTime(String id) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("SELECT start_time FROM notice_of_departure WHERE id=?")) { statement.setString(1, id); diff --git a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java new file mode 100644 index 00000000..c00e71c7 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java @@ -0,0 +1,4 @@ +package dev.vxrp.bot.util.objects; + +public record NoticeOfDeparture(String start_time, String end_time) { +} From b146e55bb4f1731303d565f172f924fc2f36bdac Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:28:00 +0200 Subject: [PATCH 038/845] Forgot to add channel and message ids to the table --- .../bot/database/sqlite/SqliteManager.java | 45 ++++++++++++++++--- .../bot/util/objects/NoticeOfDeparture.java | 2 +- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index d66b84f7..3bd59658 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -18,29 +18,39 @@ public SqliteManager(String path) throws SQLException { statement.execute( "CREATE TABLE IF NOT EXISTS notice_of_departure (" + "id TEXT PRIMARY KEY," + + "channel_message_id TEXT NOT NULL," + "start_time TEXT NOT NULL," + "end_time TEXT NOT NULL" + ");"); + logger.info("{} - Set up table {} with rows: {}, {}, {}, {}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + ColorTool.apply(DCColor.GOLD, "notice_of_departure"), + ColorTool.apply(DCColor.GREEN, "id"), + ColorTool.apply(DCColor.GREEN, "channel_message_id"), + ColorTool.apply(DCColor.GREEN, "start_time"), + ColorTool.apply(DCColor.GREEN, "end_time")); } logger.info("{} - Set up Sqlite database correctly", ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite"))); } - public void addNoticeOfDeparture(String id,String start_time, String end_time) throws SQLException { - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?)")) { + public void addNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?,?)")) { statement.setString(1, id); - statement.setString(2, start_time); - statement.setString(3, end_time); + statement.setString(2, channel_message_id); + statement.setString(3, start_time); + statement.setString(4, end_time); statement.executeUpdate(); - logger.info("{} - Added notice of departure - id:{} , start_time:{} , end_time:{}", + logger.info("{} - Added notice of departure - id: {}, channel_message_id: {} , start_time: {} , end_time: {}", ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GREEN, channel_message_id), ColorTool.apply(DCColor.GOLD, start_time), ColorTool.apply(DCColor.GOLD, end_time)); } } - public void updateNoticeOfDeparture(String id,String start_time, String end_time) throws SQLException { + public void updateNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=?, end_time=? WHERE id=?")) { statement.setString(1, start_time); statement.setString(2, end_time); @@ -54,6 +64,18 @@ public void updateNoticeOfDeparture(String id,String start_time, String end_time } } + public void updateChannelMessageId(String id, String channel_message_id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { + statement.setString(1, channel_message_id); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("{} - Updated start_time - id: {} , channel_message_id: {}", + ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, channel_message_id)); + } + } + public void updateStartTime(String id,String start_time) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { statement.setString(1, start_time); @@ -92,7 +114,7 @@ public NoticeOfDeparture getNoticeOfDeparture(String id) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { statement.setString(1, id); try (ResultSet resultSet = statement.executeQuery()) { - return new NoticeOfDeparture(resultSet.getString("start_time"), resultSet.getString("end_time")); + return new NoticeOfDeparture(resultSet.getString("channel_message_id"), resultSet.getString("start_time"), resultSet.getString("end_time")); } } } @@ -115,6 +137,15 @@ public String getEndTime(String id) throws SQLException { } } + public String getChannelMessageId(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT FROM channel_message_id WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return resultSet.getString("channel_message_id"); + } + } + } + public boolean exists(String id) { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { statement.setString(1, id); diff --git a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java index c00e71c7..601e2e2a 100644 --- a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java @@ -1,4 +1,4 @@ package dev.vxrp.bot.util.objects; -public record NoticeOfDeparture(String start_time, String end_time) { +public record NoticeOfDeparture(String channel_message_id, String start_time, String end_time) { } From 4af60d9c8f220113dbe12b5f39577f7a97ee3852 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:57:34 +0200 Subject: [PATCH 039/845] Fixed the ButtonListener AGAIN!!! --- .../dev/vxrp/bot/events/ButtonListener.java | 15 ++++++++--- .../bot/events/buttons/NoticeOfDeparture.java | 26 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 41ac1360..9bcf58eb 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -27,12 +27,14 @@ public void onButtonInteraction(ButtonInteractionEvent event) { Support.createSupportTicket(event); } if (event.getComponentId().startsWith("close_support_ticket")) { - User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); - Support.closeTicket(event, user); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { + Support.closeTicket(event, user); + }); } if (event.getComponentId().startsWith("claim_support_ticket")) { - User user = event.getJDA().getUserById(event.getComponentId().split(":")[1]); - Support.claimTicket(event, user); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { + Support.claimTicket(event, user); + }); } if (event.getComponentId().equals("settings_support_ticket")) { //WIP @@ -62,5 +64,10 @@ public void onButtonInteraction(ButtonInteractionEvent event) { if (event.getComponentId().equals("file_nod")) { NoticeOfDeparture.createNoticeOfDeparture(event); } + if (event.getComponentId().startsWith("dismiss_ticket_notice_of_departure")) { + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { + NoticeOfDeparture.dismissNoticeOfDeparture(event, user); + }); + } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 976fda31..42216152 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -2,6 +2,8 @@ import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.text.TextInput; @@ -10,14 +12,17 @@ public class NoticeOfDeparture { private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + private static final SupportGroup reason_action = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void createNoticeOfDeparture(ButtonInteractionEvent event) { event.replyModal( Modal.create("notice_of_departure", translations.modal_title()) .addComponents( ActionRow.of(shortModal( + "nod_timeframe", translations.modal_first_title(), - translations.modal_first_placeholder() + translations.modal_first_placeholder(), + 8,10 )), ActionRow.of(paragraphModal( translations.modal_second_title(), @@ -26,12 +31,23 @@ public static void createNoticeOfDeparture(ButtonInteractionEvent event) { .build()).queue(); } - private static TextInput shortModal(String title, String placeholder) { - return TextInput.create("nod_timeframe", title, TextInputStyle.SHORT) + public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User user) { + event.replyModal( + Modal.create("reason_action_dismiss_nod:"+user.getId()+":", reason_action.modal_reason_action_title()) + .addComponents(ActionRow.of(shortModal( + "reason_action_reason", + reason_action.modal_reason_action_first_title(), + reason_action.modal_reason_action_first_placeholder(), + 10, 100 + ))).build()).queue(); + } + + private static TextInput shortModal(String id,String title, String placeholder, int min, int max) { + return TextInput.create(id, title, TextInputStyle.SHORT) .setPlaceholder(placeholder) .setRequired(true) - .setMinLength(8) - .setMaxLength(10) + .setMinLength(min) + .setMaxLength(max) .build(); } private static TextInput paragraphModal(String title, String placeholder) { From 095d2cb08f379e4b8046672ab1cfb3e4e1f203c7 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 18:23:19 +0200 Subject: [PATCH 040/845] Dismiss for NoticeOfDeparture --- .../dev/vxrp/bot/events/ButtonListener.java | 21 +++++-------------- .../dev/vxrp/bot/events/ModalListener.java | 5 ++++- .../bot/events/buttons/NoticeOfDeparture.java | 2 +- .../bot/events/modals/NoticeOfDeparture.java | 19 ++++++++++++++++- .../dev/vxrp/bot/events/modals/Unban.java | 20 ++++++++---------- .../groups/NoticeOfDepartureGroup.java | 3 ++- .../translations/TranslationLoader.java | 5 ++++- .../util/configuration/util/TRANSLATIONS.java | 4 ++++ .../resources/translations/translations.yml | 17 ++++++++++++++- 9 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 9bcf58eb..10c25091 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -4,7 +4,6 @@ import dev.vxrp.bot.events.buttons.Rules; import dev.vxrp.bot.events.buttons.Support; import dev.vxrp.bot.events.buttons.Unban; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.slf4j.Logger; @@ -27,14 +26,10 @@ public void onButtonInteraction(ButtonInteractionEvent event) { Support.createSupportTicket(event); } if (event.getComponentId().startsWith("close_support_ticket")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { - Support.closeTicket(event, user); - }); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> Support.closeTicket(event, user)); } if (event.getComponentId().startsWith("claim_support_ticket")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { - Support.claimTicket(event, user); - }); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> Support.claimTicket(event, user)); } if (event.getComponentId().equals("settings_support_ticket")) { //WIP @@ -45,14 +40,10 @@ public void onButtonInteraction(ButtonInteractionEvent event) { Unban.createUnbanTicket(event); } if (event.getComponentId().startsWith("accept_unban_ticket")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { - Unban.acceptTicket(event, user); - }); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> Unban.acceptTicket(event, user)); } if (event.getComponentId().startsWith("dismiss_unban_ticket")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { - Unban.dismissTicket(event, user); - }); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> Unban.dismissTicket(event, user)); } if (event.getComponentId().equals("settings_unban_ticket")) { //WIP @@ -65,9 +56,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { NoticeOfDeparture.createNoticeOfDeparture(event); } if (event.getComponentId().startsWith("dismiss_ticket_notice_of_departure")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { - NoticeOfDeparture.dismissNoticeOfDeparture(event, user); - }); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); } } } diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index a5c324bd..55879c77 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -30,11 +30,14 @@ public void onModalInteraction(ModalInteractionEvent event) { } } if (event.getModalId().startsWith("reason_action_reason_dismiss")) { - Unban.dismissUnban(event); + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> Unban.dismissUnban(event, user)); } if (event.getModalId().equals("notice_of_departure")) { NoticeOfDeparture.createNewNoticeOfDeparture(event); } + if (event.getModalId().startsWith("reason_action_dismiss_nod")) { + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissUnban(event, user)); + } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 42216152..8f906315 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -33,7 +33,7 @@ public static void createNoticeOfDeparture(ButtonInteractionEvent event) { public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User user) { event.replyModal( - Modal.create("reason_action_dismiss_nod:"+user.getId()+":", reason_action.modal_reason_action_title()) + Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", reason_action.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", reason_action.modal_reason_action_first_title(), diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index f74896d9..41fcd5db 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -7,6 +7,7 @@ import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -52,7 +53,23 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { .build()) .addActionRow( Button.success("accept_ticket_notice_of_departure", "Accept Ticket"), - Button.danger("dismiss_ticket_notice_of_departure", "Dismiss Ticket") + Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":", "Dismiss Ticket") ).queue(); } + + public static void dismissUnban(ModalInteractionEvent event, User user) { + String messageID = event.getModalId().split(":")[2]; + Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); + + String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); + user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( + StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), + new EmbedBuilder() + .setDescription(translations.ticket_dismissed() + .replace("%reason%", reason)) + .build() + )).queue(); + + event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); + } } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 74355837..fe1ec95c 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -104,7 +104,7 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); } - public static void dismissUnban(ModalInteractionEvent event) { + public static void dismissUnban(ModalInteractionEvent event, User user) { String messageID = event.getModalId().split(":")[3]; Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); @@ -112,16 +112,14 @@ public static void dismissUnban(ModalInteractionEvent event) { String steamID = event.getModalId().split(":")[2]; String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); - event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> { - user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( - StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), - new EmbedBuilder() - .setDescription(translations.ticket_unban_message_dismissed() - .replace("%steamID%", steamID) - .replace("%reason%", reason)) - .build() - )).queue(); - }); + user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( + StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), + new EmbedBuilder() + .setDescription(translations.ticket_unban_message_dismissed() + .replace("%steamID%", steamID) + .replace("%reason%", reason)) + .build() + )).queue(); event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java index 700c9f01..26f4f672 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -2,5 +2,6 @@ public record NoticeOfDepartureGroup(String first_title, String first_body, String modal_title, String modal_first_title, String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, - String ticket_title, String ticket_body, String ticket_footer, String ticket_created) { + String ticket_title, String ticket_body, String ticket_footer, String ticket_created, + String ticket_accepted, String ticket_dismissed, String ticket_message_sent) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index e51bc673..ce17ebc6 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -59,7 +59,10 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.TITLE), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.BODY), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.FOOTER), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.CREATED)); + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.CREATED), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_ACCEPTED), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_DISMISSED), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_SENT)); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 0f57ac87..fcff8c9e 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -57,6 +57,10 @@ public static final class TICKET { public static final String BODY = "notice_of_departure.ticket_body"; public static final String FOOTER = "notice_of_departure.ticket_footer"; public static final String CREATED = "notice_of_departure.ticket_created"; + + public static final String MESSAGE_ACCEPTED = "notice_of_departure.ticket_accepted"; + public static final String MESSAGE_DISMISSED = "notice_of_departure.ticket_dismissed"; + public static final String MESSAGE_SENT = "notice_of_departure.ticket_message_sent"; } } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 1cc9789b..889c7f92 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -136,4 +136,19 @@ notice_of_departure: ```%reason%``` " ticket_footer: "Created on the %date% at %time%h" - ticket_created: "Your notice will be reviewed real soon" \ No newline at end of file + ticket_created: "Your notice will be reviewed real soon" + + ticket_accepted: " + Your notice of departure was accepted. You may now take your time off without any consequences. + + __**Acceptance Reason:**__\n + ```%reason%``` + " + ticket_dismissed: " + Your notice of departure was dismissed. You are not allowed to take time off. + If you still need to, please talk with a higher staff member about leaving the team\n + + __**Dismiss Reason:**__\n + ```%reason%``` + " + ticket_message_sent: "Your answer was sent and actions corresponding to it have been taken" \ No newline at end of file From 1ef0d87a53c9b6e89631111dd711011c4081f5de Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:06:22 +0200 Subject: [PATCH 041/845] Improved the NoticeOfDeparture record class --- .../java/dev/vxrp/bot/database/sqlite/SqliteManager.java | 6 +++++- .../java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 3bd59658..8862dfce 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -114,7 +114,11 @@ public NoticeOfDeparture getNoticeOfDeparture(String id) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { statement.setString(1, id); try (ResultSet resultSet = statement.executeQuery()) { - return new NoticeOfDeparture(resultSet.getString("channel_message_id"), resultSet.getString("start_time"), resultSet.getString("end_time")); + return new NoticeOfDeparture( + resultSet.getString("channel_message_id").split(":")[1], + resultSet.getString("channel_message_id").split(":")[2], + resultSet.getString("start_time"), + resultSet.getString("end_time")); } } } diff --git a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java index 601e2e2a..88015198 100644 --- a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java @@ -1,4 +1,4 @@ package dev.vxrp.bot.util.objects; -public record NoticeOfDeparture(String channel_message_id, String start_time, String end_time) { +public record NoticeOfDeparture(String channel_id, String message_id, String start_time, String end_time) { } From f6d40011c554e03a2f5e6e19b3767648b6646ac3 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:20:04 +0200 Subject: [PATCH 042/845] Notice of Departure data os now added to the sqlite database and accepting and dismissing is now usable --- .idea/inspectionProfiles/Project_Default.xml | 2 +- .../dev/vxrp/bot/events/ButtonListener.java | 4 +- .../dev/vxrp/bot/events/ModalListener.java | 5 +- .../bot/events/buttons/NoticeOfDeparture.java | 17 ++++++ .../bot/events/modals/NoticeOfDeparture.java | 56 +++++++++++++++++-- .../groups/NoticeOfDepartureGroup.java | 3 +- .../translations/TranslationLoader.java | 5 +- .../util/configuration/util/TRANSLATIONS.java | 5 ++ .../resources/translations/translations.yml | 25 ++++++++- 9 files changed, 110 insertions(+), 12 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index da7dab40..e3673898 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -6,7 +6,7 @@ - + diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 10c25091..2fff8cfe 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -48,13 +48,15 @@ public void onButtonInteraction(ButtonInteractionEvent event) { if (event.getComponentId().equals("settings_unban_ticket")) { //WIP event.reply("Feature currently under development").queue(); - } //Notice of Departure if (event.getComponentId().equals("file_nod")) { NoticeOfDeparture.createNoticeOfDeparture(event); } + if (event.getComponentId().startsWith("accept_ticket_notice_of_departure")) { + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.acceptedNoticeOfDeparture(event, user)); + } if (event.getComponentId().startsWith("dismiss_ticket_notice_of_departure")) { event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); } diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index 55879c77..4372f81c 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -36,8 +36,11 @@ public void onModalInteraction(ModalInteractionEvent event) { if (event.getModalId().equals("notice_of_departure")) { NoticeOfDeparture.createNewNoticeOfDeparture(event); } + if (event.getModalId().startsWith("reason_action_accepted_nod")) { + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.acceptNoticeOfDeparture(event, user)); + } if (event.getModalId().startsWith("reason_action_dismiss_nod")) { - event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissUnban(event, user)); + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 8f906315..73c82f3e 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -10,6 +10,9 @@ import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; import net.dv8tion.jda.api.interactions.modals.Modal; +import java.text.SimpleDateFormat; +import java.util.Calendar; + public class NoticeOfDeparture { private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); private static final SupportGroup reason_action = LoadedConfigurations.getSupportTranslationMemoryLoad(); @@ -31,6 +34,20 @@ public static void createNoticeOfDeparture(ButtonInteractionEvent event) { .build()).queue(); } + public static void acceptedNoticeOfDeparture(ButtonInteractionEvent event, User user) { + String start_time = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); + String end_time = event.getComponentId().split(":")[2]; + + event.replyModal( + Modal.create("reason_action_accepted_nod:"+user.getId()+":"+event.getMessageId()+":"+end_time+":"+start_time+":", reason_action.modal_reason_action_title()) + .addComponents(ActionRow.of(shortModal( + "reason_action_reason", + reason_action.modal_reason_action_first_title(), + reason_action.modal_reason_action_first_placeholder(), + 10, 100 + ))).build()).queue(); + } + public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User user) { event.replyModal( Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", reason_action.modal_reason_action_title()) diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 41fcd5db..b08def56 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.modals; +import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; @@ -12,6 +13,7 @@ import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Objects; @@ -21,10 +23,11 @@ public class NoticeOfDeparture { private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + private static final String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); + private static final String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); + public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { TextChannel channel = Objects.requireNonNull(event.getGuild()).getTextChannelById(configs.notice_of_departure_decision_channel_id()); - String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); - String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); String[] givenDate = Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString().split("\\."); String reason = Objects.requireNonNull(event.getValue("nod_reason")).getAsString(); @@ -52,12 +55,57 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { .replace("%time%", time)) .build()) .addActionRow( - Button.success("accept_ticket_notice_of_departure", "Accept Ticket"), + Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", "Accept Ticket"), Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":", "Dismiss Ticket") ).queue(); } - public static void dismissUnban(ModalInteractionEvent event, User user) { + public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User user) { + String messageID = event.getModalId().split(":")[2]; + Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); + + String reason = Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString(); + user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( + StatsBuilder.buildAccepted(event.getUser().getGlobalName()).build(), + new EmbedBuilder() + .setDescription(translations.ticket_accepted() + .replace("%timeframe%", event.getModalId().split(":")[3]+" till " +event.getModalId().split(":")[4]) + .replace("%reason%", reason)) + .build() + )).queue(); + + Objects.requireNonNull(event.getGuild().getTextChannelById(LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_notice_channel_id())).sendMessageEmbeds( + StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), + new EmbedBuilder() + .setTitle(translations.notice_title() + .replace("%user%", Objects.requireNonNull(user.getGlobalName()))) + .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) + .setDescription(translations.notice_body() + .replace("%user%", "<@"+event.getUser().getId()+">") + .replace("%timeframe%", event.getModalId().split(":")[3]+" till " +event.getModalId().split(":")[4]) + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) + .setFooter(translations.notice_footer() + .replace("%date%", date) + .replace("%time%", time)) + .build()) + .addActionRow( + Button.danger("revoke_notice_of_departure", "Revoke Notice of Departure") + ).queue(message -> { + try { + ScpTools.getSqliteManager().addNoticeOfDeparture( + user.getId(), + LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_notice_channel_id()+":"+message.getId(), + event.getModalId().split(":")[4], + event.getModalId().split(":")[3] + ); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); + event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); + } + + public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User user) { String messageID = event.getModalId().split(":")[2]; Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java index 26f4f672..8ca07566 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -3,5 +3,6 @@ public record NoticeOfDepartureGroup(String first_title, String first_body, String modal_title, String modal_first_title, String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, String ticket_title, String ticket_body, String ticket_footer, String ticket_created, - String ticket_accepted, String ticket_dismissed, String ticket_message_sent) { + String ticket_accepted, String ticket_dismissed, String ticket_message_sent, String notice_title, + String notice_body, String notice_footer) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index ce17ebc6..caae75a0 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -62,7 +62,10 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.CREATED), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_ACCEPTED), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_DISMISSED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_SENT)); + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_SENT), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.TITLE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.BODY), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.FOOTER)); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index fcff8c9e..3d61f205 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -62,5 +62,10 @@ public static final class TICKET { public static final String MESSAGE_DISMISSED = "notice_of_departure.ticket_dismissed"; public static final String MESSAGE_SENT = "notice_of_departure.ticket_message_sent"; } + public static final class NOTICE { + public static final String TITLE = "notice_of_departure.notice_title"; + public static final String BODY = "notice_of_departure.notice_body"; + public static final String FOOTER = "notice_of_departure.notice_footer"; + } } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 889c7f92..2932180d 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -130,7 +130,7 @@ notice_of_departure: __**Timespan**__\n ```ansi\n %current_day%.%current_month%.%current_year% till %day%.%month%.%year% - ```\n + ``` __**Reason:**__\n ```%reason%``` @@ -139,7 +139,10 @@ notice_of_departure: ticket_created: "Your notice will be reviewed real soon" ticket_accepted: " - Your notice of departure was accepted. You may now take your time off without any consequences. + Your notice of departure was accepted. You may now take your time off without any consequences. \n + + __**Acceptance Timeframe:**__\n + ```%timeframe%``` __**Acceptance Reason:**__\n ```%reason%``` @@ -151,4 +154,20 @@ notice_of_departure: __**Dismiss Reason:**__\n ```%reason%``` " - ticket_message_sent: "Your answer was sent and actions corresponding to it have been taken" \ No newline at end of file + ticket_message_sent: "Your answer was sent and actions corresponding to it have been taken" + + notice_title: "Notice of Departure - %user%" + notice_body: " + This Notice of Departure can always be revoked by pressing the button down below. + This will also be periodically checked if still valid or not\n + + __**Accepted by:**__\n + %user%\n + + __**Acceptance Reason:**__\n + ```%timeframe%``` + + __**Acceptance Reason:**__\n + ```%reason%``` + " + notice_footer: "Created on the %date% at %time%h" \ No newline at end of file From aea8a97a03e25bdd77170fdcb660f15a2d8fd841 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 02:44:56 +0200 Subject: [PATCH 043/845] Changed a lot, I think, hope it doesn't break --- src/main/java/dev/vxrp/bot/ScpTools.java | 6 +- .../bot/database/sqlite/SqliteManager.java | 22 +++++- .../dev/vxrp/bot/events/ButtonListener.java | 3 + .../bot/events/modals/NoticeOfDeparture.java | 4 +- .../bot/runnables/CheckNoticeOfDeparture.java | 73 +++++++++++++++++++ .../java/dev/vxrp/bot/util/Enums/DCColor.java | 3 +- .../vxrp/bot/util/builder/StatsBuilder.java | 20 +++++ .../dev/vxrp/bot/util/colors/ColorTool.java | 60 ++++++++++++++- .../configuration/configs/ConfigLoader.java | 4 + .../configuration/groups/ConfigGroup.java | 8 +- .../groups/NoticeOfDepartureGroup.java | 3 +- .../translations/TranslationLoader.java | 5 +- .../bot/util/configuration/util/CONFIG.java | 12 ++- .../util/configuration/util/TRANSLATIONS.java | 3 + .../dev/vxrp/bot/util/general/RepeatTask.java | 12 +++ .../bot/util/objects/NoticeOfDeparture.java | 2 +- src/main/resources/configs/config.yml | 8 ++ .../resources/translations/translations.yml | 32 +++++++- 18 files changed, 260 insertions(+), 20 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java create mode 100644 src/main/java/dev/vxrp/bot/util/general/RepeatTask.java diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 16495895..46b9ce6f 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -28,13 +28,13 @@ import java.util.*; public class ScpTools { + private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); static ConfigManager configManager; static TranslationManager translationManager; static ColorConfigManager colorConfigManager; static SqliteManager sqliteManager; - private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); - public static void main(String[] args) throws SQLException { + public static void main(String[] args) { initializeConfigs(); initializeSqlite(); loadConfigs(); @@ -74,7 +74,7 @@ private static void initializeConfigs() { for (String folder : folders) { String folderPath = Paths.get(folder).toString(); new File(folderPath).mkdirs(); - logger.info("Created folder {}", folderPath); + logger.info("Initializing folder {}", folderPath); } try { diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 8862dfce..853373a7 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -7,6 +7,8 @@ import org.slf4j.LoggerFactory; import java.sql.*; +import java.util.ArrayList; +import java.util.List; public class SqliteManager { private final Connection connection; @@ -110,13 +112,31 @@ public void deleteNoticeOfDeparture(String id) throws SQLException { } } + public List getEveryNoticeOfDeparture() throws SQLException { + List noticeOfDepartureList = new ArrayList<>(); + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure")) { + try (ResultSet resultSet = statement.executeQuery()) { + while (resultSet.next()) { + noticeOfDepartureList.add(new NoticeOfDeparture( + resultSet.getString("id"), + resultSet.getString("channel_message_id").split(":")[0], + resultSet.getString("channel_message_id").split(":")[1], + resultSet.getString("start_time"), + resultSet.getString("end_time"))); + } + } + } + return noticeOfDepartureList; + } + public NoticeOfDeparture getNoticeOfDeparture(String id) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { statement.setString(1, id); try (ResultSet resultSet = statement.executeQuery()) { return new NoticeOfDeparture( + resultSet.getString("id"), + resultSet.getString("channel_message_id").split(":")[0], resultSet.getString("channel_message_id").split(":")[1], - resultSet.getString("channel_message_id").split(":")[2], resultSet.getString("start_time"), resultSet.getString("end_time")); } diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 2fff8cfe..49fc80d1 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -60,5 +60,8 @@ public void onButtonInteraction(ButtonInteractionEvent event) { if (event.getComponentId().startsWith("dismiss_ticket_notice_of_departure")) { event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); } + if (event.getComponentId().equals("delete_notice_of_departure")) { + event.getMessage().delete().queue(); + } } } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index b08def56..49fc8a03 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -69,7 +69,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use StatsBuilder.buildAccepted(event.getUser().getGlobalName()).build(), new EmbedBuilder() .setDescription(translations.ticket_accepted() - .replace("%timeframe%", event.getModalId().split(":")[3]+" till " +event.getModalId().split(":")[4]) + .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) .replace("%reason%", reason)) .build() )).queue(); @@ -82,7 +82,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) .setDescription(translations.notice_body() .replace("%user%", "<@"+event.getUser().getId()+">") - .replace("%timeframe%", event.getModalId().split(":")[3]+" till " +event.getModalId().split(":")[4]) + .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) .setFooter(translations.notice_footer() .replace("%date%", date) diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java new file mode 100644 index 00000000..8902500d --- /dev/null +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -0,0 +1,73 @@ +package dev.vxrp.bot.runnables; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.database.sqlite.SqliteManager; +import dev.vxrp.bot.util.builder.StatsBuilder; +import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.objects.NoticeOfDeparture; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.interactions.components.buttons.Button; + +import java.sql.SQLException; +import java.time.LocalDate; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class CheckNoticeOfDeparture { + private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + + public static Runnable runNoticeOfDepartureCheck(JDA api) { + return () -> { + SqliteManager sqliteManager = ScpTools.getSqliteManager(); + try { + for (NoticeOfDeparture notice : sqliteManager.getEveryNoticeOfDeparture()) { + String[] startTimes = notice.end_time().split("\\."); + + LocalDate end_date = LocalDate.of(Integer.parseInt(startTimes[2]), Integer.parseInt(startTimes[1]), Integer.parseInt(startTimes[0])); + LocalDate now = LocalDate.now(); + + if (now.isEqual(end_date) || now.isAfter(end_date)) { + api.awaitReady().retrieveUserById(notice.id()).queue(user -> { + MessageChannel channel = api.getTextChannelById(notice.channel_id()); + + + Objects.requireNonNull(channel).retrieveMessageById(notice.message_id()).queue(message -> { + List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() + .stream() + .map(id -> "<@&" + id + ">") + .collect(Collectors.toList()); + + message.editMessage(String.join("", pingRoles)).queue(); + channel.sendMessage(String.join("", pingRoles)).queue(ping -> ping.delete().queue()); + message.editMessageEmbeds(new EmbedBuilder() + .setDescription(ColorTool.useCustomColorCodes(translations.notice_ended_replace() + .replace("%user%", Objects.requireNonNull(user.getGlobalName())) + .replace("%date%", now.toString()) + .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT"))) + .build()) + .setActionRow( + Button.danger("delete_notice_of_departure", "Delete Processed Notice of Departure") + ).queue(); + }); + + Objects.requireNonNull(user).openPrivateChannel().queue(privateChannel -> privateChannel.sendMessageEmbeds( + StatsBuilder.buildEnded(user.getGlobalName()).build(), + new EmbedBuilder().setDescription( + translations.notice_ended() + .replace("%timeframe%", notice.start_time()+" till "+notice.end_time())) + .build() + ).queue()); + }); + } + } + } catch (SQLException | InterruptedException e) { + throw new RuntimeException(e); + } + }; + } +} diff --git a/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java b/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java index aaf80a8f..bf789c1c 100644 --- a/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java +++ b/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java @@ -9,5 +9,6 @@ public enum DCColor { PINK, TEAL, WHITE, - BOLD + BOLD, + UNDERLINE } diff --git a/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java b/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java index 3c603056..37ebc079 100644 --- a/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java +++ b/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java @@ -33,4 +33,24 @@ public static EmbedBuilder buildAccepted(String username) { ``` """); } + public static EmbedBuilder buildEnded(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Notice of Departure: Ended ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" +  + ``` + """); + } + public static EmbedBuilder buildRevoked(String username) { + return new EmbedBuilder() + .setDescription(""" + ```ansi + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Notice of Departure: Revoked ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎\s + ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Creator: You | Handler: """ +username+""" +  + ``` + """); + } } diff --git a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java index 67285209..aafd5ba4 100644 --- a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java +++ b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java @@ -36,7 +36,65 @@ public static String apply(DCColor color, String text) { case BOLD -> { return "\u001B[1;2m"+text+"\u001B[0m"; } + case UNDERLINE -> { + return "\u001B[4;2m"+text+"\u001B[0m"; + } + } + return text; + } + @NotNull + public static String useCustomColorCodes(String text) { + return text + .replace("&dark_gray&", "\u001B[2;30m") + .replace("&red&", "\u001B[2;31m") + .replace("&green&", "\u001B[2;32m") + .replace("&gold&", "\u001B[2;33m") + .replace("&light_blue&", "\u001B[2;34m") + .replace("&pink&", "\u001B[2;35m") + .replace("&teal&", "\u001B[2;36m") + .replace("&white&", "\u001B[2;37m") + .replace("&bold&", "\u001B[1;2m") + .replace("&reset&", "\u001B[0m") + .replace("&underline&", "\u001B[4;2m"); + + } + @NotNull + public static String replaceCustomColorCode(String colorCode) { + switch (colorCode) { + case "&dark_gray&" -> { + return "\u001B[2;30m"; + } + case "&red&" -> { + return "\u001B[2;31m"; + } + case "&green&" -> { + return "\u001B[2;32m"; + } + case "&gold&" -> { + return "\u001B[2;33m"; + } + case "&light_blue&" -> { + return "\u001B[2;34m"; + } + case "&pink&" -> { + return "\u001B[2;35m"; + } + case "&teal&" -> { + return "\u001B[2;36m"; + } + case "&white&" -> { + return "\u001B[2;37m"; + } + case "&bold&" -> { + return "\u001B[1;2m"; + } + case "&reset&" -> { + return "\u001B[0m"; + } + case "&underline&" -> { + return "\u001B[4;2m"; + } } - return null; + return colorCode; } } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 6c18f1f8..14d3b310 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -31,6 +31,10 @@ public ConfigLoader() { configManager.getString(CONFIG.SUPPORT_SETTINGS.UNBAN_CHANNEL_ID), configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.DESCISION_CHANNEL_ID), configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.NOTICE_CHANNEL_ID), + configManager.getStringList(CONFIG.NOTICE_OF_DEPARTURE.ROLES_ACCESS_NOTICES), + configManager.getBoolean(CONFIG.NOTICE_OF_DEPARTURE.CHECK_ON_STARTUP), + configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.CHECK_TYPE), + configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.CHECK_RATE), configManager.getBoolean(CONFIG.CEDMOD.ACTIVE), configManager.getString(CONFIG.CEDMOD.INSTANCE_URL), configManager.getString(CONFIG.CEDMOD.API_KEY), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java index 813e4a42..af6f0972 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java @@ -4,9 +4,9 @@ public record ConfigGroup(String token, String guild_id, String activity_type, String activity_content, String rules_pastebin, String rules_embed_footer, List commands, List command_setting_help_default_permissions, - String command_settings_help_description, List command_settings_template_default_permissions, - String command_settings_template_descriptions, List support_settings_roles_access_support_tickets, - List support_settings_roles_access_unban_tickets, String support_settings_unban_channel_id, - String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, boolean cedmod_active, + String command_settings_help_description, List command_settings_template_default_permissions, String command_settings_template_descriptions, + List support_settings_roles_access_support_tickets, List support_settings_roles_access_unban_tickets, String support_settings_unban_channel_id, + String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, List notice_of_departure_roles_access_notices, + boolean notice_of_departure_check_on_startup, String notice_of_departure_check_type, String notice_of_departure_check_rate, boolean cedmod_active, String cedmod_instance_url, String cedmod_api_key, String cedmod_master_banlist_id) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java index 8ca07566..b4e6b397 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -4,5 +4,6 @@ public record NoticeOfDepartureGroup(String first_title, String first_body, Stri String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, String ticket_title, String ticket_body, String ticket_footer, String ticket_created, String ticket_accepted, String ticket_dismissed, String ticket_message_sent, String notice_title, - String notice_body, String notice_footer) { + String notice_body, String notice_footer, String notice_ended, String notice_revoked, + String notice_ended_replace) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index caae75a0..15a99155 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -65,7 +65,10 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_SENT), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.TITLE), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.BODY), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.FOOTER)); + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.FOOTER), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE)); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java index f7fa956e..f382bc8d 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java @@ -25,14 +25,18 @@ public static final class SUPPORT_SETTINGS { public static final String ROLES_ACCESS_UNBAN_TICKETS = "support_settings.roles_access_unban_tickets"; public static final String UNBAN_CHANNEL_ID = "support_settings.unban_channel_id"; } + public static final class NOTICE_OF_DEPARTURE { + public static final String DESCISION_CHANNEL_ID = "notice_of_departure.decision_channel_id"; + public static final String NOTICE_CHANNEL_ID = "notice_of_departure.notice_channel_id"; + public static final String ROLES_ACCESS_NOTICES = "notice_of_departure.roles_access_notices"; + public static final String CHECK_ON_STARTUP = "notice_of_departure.check_on_startup"; + public static final String CHECK_TYPE = "notice_of_departure.check_type"; + public static final String CHECK_RATE = "notice_of_departure.check_rate"; + } public static final class CEDMOD { public static final String ACTIVE = "cedmod.active"; public static final String INSTANCE_URL = "cedmod.instance_url"; public static final String API_KEY = "cedmod.api_key"; public static final String MASTER_BAN_LIST_ID = "cedmod.master_ban_list_id"; } - public static final class NOTICE_OF_DEPARTURE { - public static final String DESCISION_CHANNEL_ID = "notice_of_departure.decision_channel_id"; - public static final String NOTICE_CHANNEL_ID = "notice_of_departure.notice_channel_id"; - } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 3d61f205..5a4e21ad 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -67,5 +67,8 @@ public static final class NOTICE { public static final String BODY = "notice_of_departure.notice_body"; public static final String FOOTER = "notice_of_departure.notice_footer"; } + public static final String ENDED = "notice_of_departure.notice_ended"; + public static final String REVOKED = "notice_of_departure.notice_revoked"; + public static final String ENDED_REPLACE = "notice_of_departure.notice_ended_replace"; } } diff --git a/src/main/java/dev/vxrp/bot/util/general/RepeatTask.java b/src/main/java/dev/vxrp/bot/util/general/RepeatTask.java new file mode 100644 index 00000000..5673aba4 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/general/RepeatTask.java @@ -0,0 +1,12 @@ +package dev.vxrp.bot.util.general; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class RepeatTask { + public static void repeatWithScheduledExecutorService(Runnable runnable, int delay, TimeUnit unit) { + ScheduledExecutorService threadPool = Executors.newSingleThreadScheduledExecutor(); + threadPool.scheduleWithFixedDelay(runnable, 0, delay, unit); + } +} diff --git a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java index 88015198..2757c942 100644 --- a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java @@ -1,4 +1,4 @@ package dev.vxrp.bot.util.objects; -public record NoticeOfDeparture(String channel_id, String message_id, String start_time, String end_time) { +public record NoticeOfDeparture(String id,String channel_id, String message_id, String start_time, String end_time) { } diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index 083ed17b..abf35856 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -39,6 +39,14 @@ notice_of_departure: decision_channel_id: "" # Which channel should the departures be sent to? notice_channel_id: "" + # List of role's that are able to accept/dismiss/revoke notices (INPUT ID'S ONLY) + roles_access_notices: [] + # ONLY CHANGE THIS IF YOU KNOW WHAT YOU'RE DOING + check_on_startup: true + # Put the following in the type: [NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS] + check_type: "HOURS" + # The rate at that the notices are checked. + check_rate: "1" cedmod: # Should Cedmod integration features be established or deactivated? diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 2932180d..9e7f52e1 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -170,4 +170,34 @@ notice_of_departure: __**Acceptance Reason:**__\n ```%reason%``` " - notice_footer: "Created on the %date% at %time%h" \ No newline at end of file + notice_footer: "Created on the %date% at %time%h" + + notice_ended: " + Your Notice of Departure has ended and all your benefits going with it have been revoked \n + + __**Timeframe:**__\n + ```%timeframe%``` + " + notice_revoked: " + Your Notice of Departure has been revoked and all benefits going with at do not apply anymore \n + + __**Timeframe:**__\n + ```%timeframe%``` + " + notice_ended_replace: " + ```ansi + + &reset&&teal&&bold&&underline&Original Data&reset& + + Original issuer: &gold&&bold&%user%&reset& + + Original Message Type: &gold&&bold&Notice of Departure&reset& + + + &teal&&bold&&underline&Change Data&reset& + + Dealt with on: &gold&&bold&%date%&reset& + + Dealt with by: &gold&&bold&%actionTaker% + ``` + " \ No newline at end of file From 22e9c889d906573ee9f52c197787ce5ec0ec618f Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 03:13:37 +0200 Subject: [PATCH 044/845] Notices of Departures now automatically being detected if invalid --- src/main/java/dev/vxrp/bot/ScpTools.java | 30 +++++++++++++------ .../bot/config/managers/ConfigManager.java | 3 ++ .../bot/runnables/CheckNoticeOfDeparture.java | 15 +++++++++- .../configuration/configs/ConfigLoader.java | 2 +- .../configuration/groups/ConfigGroup.java | 2 +- src/main/resources/configs/config.yml | 2 +- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 46b9ce6f..06e43836 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -7,13 +7,17 @@ import dev.vxrp.bot.commands.templates.TemplateCommand; import dev.vxrp.bot.config.managers.ColorConfigManager; import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.runnables.CheckNoticeOfDeparture; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.configs.ConfigLoader; +import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.config.managers.ConfigManager; import dev.vxrp.bot.events.ModalListener; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.configuration.translations.TranslationLoader; +import dev.vxrp.bot.util.general.RepeatTask; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; @@ -26,6 +30,7 @@ import java.nio.file.Paths; import java.sql.SQLException; import java.util.*; +import java.util.concurrent.TimeUnit; public class ScpTools { private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); @@ -45,7 +50,16 @@ public static void main(String[] args) { logger.info("ActivityContent set to {}", ColorTool.apply(DCColor.RED, activityContent)); checkGuildID(); - initializeBot(activityType, activityContent); + JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT) + .setActivity(Activity.of(activityType, activityContent)) + .disableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOJI, CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS) + .build(); + + new CommandManager().Initialize(api); + api.addEventListener(new TemplateCommand(), new HelpCommand(),new ButtonListener(), new ModalListener()); + logger.info("Initialized Listeners"); + + noticeOfDepartureCheckups(api); } private static void initializeSqlite() { @@ -103,15 +117,13 @@ private static void checkGuildID() { } } - private static void initializeBot(Activity.ActivityType activityType, String activityContent) { - JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT) - .setActivity(Activity.of(activityType, activityContent)) - .disableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOJI, CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS) - .build(); + private static void noticeOfDepartureCheckups(JDA api) { + ConfigGroup config = LoadedConfigurations.getConfigMemoryLoad(); - new CommandManager().Initialize(api); - api.addEventListener(new TemplateCommand(), new HelpCommand(),new ButtonListener(), new ModalListener()); - logger.info("Initialized Listeners"); + RepeatTask.repeatWithScheduledExecutorService( + CheckNoticeOfDeparture.runNoticeOfDepartureCheck(api), + config.notice_of_departure_check_rate(), + TimeUnit.valueOf(config.notice_of_departure_check_type())); } public static ConfigManager getConfigManager() { diff --git a/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java b/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java index 1b508331..5d2720b5 100644 --- a/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java +++ b/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java @@ -34,6 +34,9 @@ private YamlConfiguration getYamlConfig() { public String getString(String key) { return getYamlConfig().getString(key); } + public int getInt(String key) { + return getYamlConfig().getInt(key); + } public boolean getBoolean(String key) { return getYamlConfig().getBoolean(key); } diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 8902500d..745f6f77 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.database.sqlite.SqliteManager; +import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; @@ -11,6 +12,8 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.sql.SQLException; import java.time.LocalDate; @@ -19,6 +22,7 @@ import java.util.stream.Collectors; public class CheckNoticeOfDeparture { + private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); public static Runnable runNoticeOfDepartureCheck(JDA api) { @@ -33,9 +37,10 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { if (now.isEqual(end_date) || now.isAfter(end_date)) { api.awaitReady().retrieveUserById(notice.id()).queue(user -> { + logger.info(ColorTool.useCustomColorCodes("&reset&&gold&----------------------- &reset&&red&AUTOMATIC DETECTION UNIT&reset&&gold& ----------------------&reset&")); + logger.info("Found invalid notice of departure"); MessageChannel channel = api.getTextChannelById(notice.channel_id()); - Objects.requireNonNull(channel).retrieveMessageById(notice.message_id()).queue(message -> { List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() .stream() @@ -53,6 +58,7 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { .setActionRow( Button.danger("delete_notice_of_departure", "Delete Processed Notice of Departure") ).queue(); + logger.info("Updated official notice of departure message in {}", channel.getName()); }); Objects.requireNonNull(user).openPrivateChannel().queue(privateChannel -> privateChannel.sendMessageEmbeds( @@ -62,6 +68,13 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { .replace("%timeframe%", notice.start_time()+" till "+notice.end_time())) .build() ).queue()); + logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); + try { + sqliteManager.deleteNoticeOfDeparture(notice.id()); + } catch (SQLException e) { + throw new RuntimeException(e); + } + logger.info(ColorTool.apply(DCColor.GOLD, "------------------------------------------------------------------------")); }); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 14d3b310..1d75feed 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -34,7 +34,7 @@ public ConfigLoader() { configManager.getStringList(CONFIG.NOTICE_OF_DEPARTURE.ROLES_ACCESS_NOTICES), configManager.getBoolean(CONFIG.NOTICE_OF_DEPARTURE.CHECK_ON_STARTUP), configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.CHECK_TYPE), - configManager.getString(CONFIG.NOTICE_OF_DEPARTURE.CHECK_RATE), + configManager.getInt(CONFIG.NOTICE_OF_DEPARTURE.CHECK_RATE), configManager.getBoolean(CONFIG.CEDMOD.ACTIVE), configManager.getString(CONFIG.CEDMOD.INSTANCE_URL), configManager.getString(CONFIG.CEDMOD.API_KEY), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java index af6f0972..d6750e1c 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java @@ -7,6 +7,6 @@ public record ConfigGroup(String token, String guild_id, String activity_type, S String command_settings_help_description, List command_settings_template_default_permissions, String command_settings_template_descriptions, List support_settings_roles_access_support_tickets, List support_settings_roles_access_unban_tickets, String support_settings_unban_channel_id, String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, List notice_of_departure_roles_access_notices, - boolean notice_of_departure_check_on_startup, String notice_of_departure_check_type, String notice_of_departure_check_rate, boolean cedmod_active, + boolean notice_of_departure_check_on_startup, String notice_of_departure_check_type, int notice_of_departure_check_rate, boolean cedmod_active, String cedmod_instance_url, String cedmod_api_key, String cedmod_master_banlist_id) { } diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index abf35856..5fdb76a1 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -46,7 +46,7 @@ notice_of_departure: # Put the following in the type: [NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS] check_type: "HOURS" # The rate at that the notices are checked. - check_rate: "1" + check_rate: 1 cedmod: # Should Cedmod integration features be established or deactivated? From 4daf14f988d4320d2af20be072d5f591c781fd3a Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 03:35:27 +0200 Subject: [PATCH 045/845] Added functions for the revoke button, finishing the notice of departure feature --- src/main/java/dev/vxrp/bot/ScpTools.java | 1 - .../java/dev/vxrp/bot/events/ButtonListener.java | 3 +++ .../vxrp/bot/events/buttons/NoticeOfDeparture.java | 13 +++++++++++++ .../vxrp/bot/events/modals/NoticeOfDeparture.java | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 06e43836..5e07b569 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -119,7 +119,6 @@ private static void checkGuildID() { private static void noticeOfDepartureCheckups(JDA api) { ConfigGroup config = LoadedConfigurations.getConfigMemoryLoad(); - RepeatTask.repeatWithScheduledExecutorService( CheckNoticeOfDeparture.runNoticeOfDepartureCheck(api), config.notice_of_departure_check_rate(), diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 49fc80d1..8681f701 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -60,6 +60,9 @@ public void onButtonInteraction(ButtonInteractionEvent event) { if (event.getComponentId().startsWith("dismiss_ticket_notice_of_departure")) { event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); } + if (event.getComponentId().startsWith("revoke_notice_of_departure")) { + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.revokeNoticeOfDeparture(event, user)); + } if (event.getComponentId().equals("delete_notice_of_departure")) { event.getMessage().delete().queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 73c82f3e..33450bfe 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -1,8 +1,10 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; @@ -59,6 +61,17 @@ public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User u ))).build()).queue(); } + public static void revokeNoticeOfDeparture(ButtonInteractionEvent event, User user) { + user.openPrivateChannel().queue(privateChannel -> + privateChannel.sendMessageEmbeds( + StatsBuilder.buildRevoked(user.getGlobalName()).build(), + new EmbedBuilder() + .setDescription(translations.notice_revoked() + .replace("%timeframe%", event.getComponentId().split(":")[3]+" till "+event.getComponentId().split(":")[2])) + .build() + ).queue()); + } + private static TextInput shortModal(String id,String title, String placeholder, int min, int max) { return TextInput.create(id, title, TextInputStyle.SHORT) .setPlaceholder(placeholder) diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 49fc8a03..f1308ca7 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -89,7 +89,8 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use .replace("%time%", time)) .build()) .addActionRow( - Button.danger("revoke_notice_of_departure", "Revoke Notice of Departure") + Button.danger("revoke_notice_of_departure"+":"+ + user.getId()+":"+event.getModalId().split(":")[4]+":"+event.getModalId().split(":")[4]+":", "Revoke Notice of Departure") ).queue(message -> { try { ScpTools.getSqliteManager().addNoticeOfDeparture( From 8c31cab9e5d47d894351f796cec33d2f404c4da2 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 04:40:07 +0200 Subject: [PATCH 046/845] Changes --- build.gradle.kts | 6 +++--- src/main/java/dev/vxrp/bot/ScpTools.java | 4 ++-- src/main/resources/configs/config.yml | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b945664b..50471c98 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + plugins { application - id("com.gradleup.shadow") version("8.3.0") + id("com.gradleup.shadow") version("8.3.3") id("java") } @@ -18,8 +20,6 @@ dependencies { implementation("org.xerial:sqlite-jdbc:3.45.1.0") implementation("net.dv8tion:JDA:$jdaVersion") implementation("ch.qos.logback:logback-classic:1.5.6") - testImplementation(platform("org.junit:junit-bom:5.10.0")) - testImplementation("org.junit.jupiter:junit-jupiter") implementation("org.bspfsystems:yamlconfiguration:2.0.2") implementation("org.apache.commons:commons-lang3:3.4") implementation("com.google.code.gson:gson:2.11.0") diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 5e07b569..9478f9ff 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import java.io.File; +import java.io.IOException; import java.nio.file.Paths; import java.sql.SQLException; import java.util.*; @@ -110,8 +111,7 @@ private static void initializeConfigs() { private static void checkGuildID() { if (configManager.getString("guild_id") == null || Objects.equals(configManager.getString("guild_id"), "")) { - logger.error("Guild id is {}. Process shutting down", ColorTool.apply(DCColor.RED, "null")); - return; + logger.error("Guild id is {}. Invalid but moving on", ColorTool.apply(DCColor.RED, "null")); } else { logger.info("Launching under guild id {}", ColorTool.apply(DCColor.GREEN, configManager.getString("guild_id"))); } diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index 5fdb76a1..442b40eb 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -9,11 +9,16 @@ activity_type: "PLAYING" # The text being displayed activity_content: "/help" -# Rules Settings rules: + # Pastebin id of the SCP:SL ruleset pastebin: "" + # The text that is going to be displayed on the rule footer embed_footer: "Official Server Ruleset" +logging: + # Channel id of the ticket logging channel + ticket_logging_channel_id: "" + # Commands that are activated by default remove to deactivate, default ["help", "template"]] commands: ["help", "template"] # Command settings From 1db16878bd28fa45252a9561799073f248b24ef7 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:01:51 +0200 Subject: [PATCH 047/845] Changed to the current version --- build.gradle.kts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 50471c98..03a710cf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,13 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - plugins { application id("com.gradleup.shadow") version("8.3.3") id("java") } + application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version = "1.0-SNAPSHOT" +version= "0.2.0" val jdaVersion = "5.0.0-beta.24" // From 289b5f257184096eca035403e213afc2e8f67504 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:36:44 +0200 Subject: [PATCH 048/845] Update Checker --- build.gradle.kts | 12 ++++- src/main/java/dev/vxrp/bot/ScpTools.java | 5 +- .../dev/vxrp/bot/events/modals/Unban.java | 2 +- .../bot/util/{ => api}/cedmod/CedModApi.java | 2 +- .../vxrp/bot/util/api/github/GitHubApi.java | 53 +++++++++++++++++++ 5 files changed, 69 insertions(+), 5 deletions(-) rename src/main/java/dev/vxrp/bot/util/{ => api}/cedmod/CedModApi.java (98%) create mode 100644 src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java diff --git a/build.gradle.kts b/build.gradle.kts index 03a710cf..746662b6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,6 +24,14 @@ dependencies { implementation("com.google.code.gson:gson:2.11.0") } -tasks.test { - useJUnitPlatform() +val createVersionProperties by tasks.registering(WriteProperties::class) { + val filePath = sourceSets.main.map { + it.output.resourcesDir!!.resolve("vxrp/dev/version.properties") + } + destinationFile = filePath + + property("version", project.version.toString()) +} +tasks.classes { + dependsOn(createVersionProperties) } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 9478f9ff..37cc18eb 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -8,6 +8,7 @@ import dev.vxrp.bot.config.managers.ColorConfigManager; import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.runnables.CheckNoticeOfDeparture; +import dev.vxrp.bot.util.api.github.GitHubApi; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.configs.ConfigLoader; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; @@ -40,7 +41,9 @@ public class ScpTools { static ColorConfigManager colorConfigManager; static SqliteManager sqliteManager; - public static void main(String[] args) { + public static void main(String[] args) throws IOException { + GitHubApi.CheckForUpdatesByTags("https://api.github.com/repos/Vxrpenter/SCPToolsBot/git/refs/tags"); + initializeConfigs(); initializeSqlite(); loadConfigs(); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index fe1ec95c..54150186 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -3,7 +3,7 @@ import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; -import dev.vxrp.bot.util.cedmod.CedModApi; +import dev.vxrp.bot.util.api.cedmod.CedModApi; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; diff --git a/src/main/java/dev/vxrp/bot/util/cedmod/CedModApi.java b/src/main/java/dev/vxrp/bot/util/api/cedmod/CedModApi.java similarity index 98% rename from src/main/java/dev/vxrp/bot/util/cedmod/CedModApi.java rename to src/main/java/dev/vxrp/bot/util/api/cedmod/CedModApi.java index 6f681c42..8b70c2ec 100644 --- a/src/main/java/dev/vxrp/bot/util/cedmod/CedModApi.java +++ b/src/main/java/dev/vxrp/bot/util/api/cedmod/CedModApi.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.cedmod; +package dev.vxrp.bot.util.api.cedmod; import com.google.gson.JsonArray; import com.google.gson.JsonParser; diff --git a/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java b/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java new file mode 100644 index 00000000..104bc03e --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java @@ -0,0 +1,53 @@ +package dev.vxrp.bot.util.api.github; + +import com.google.gson.JsonArray; +import com.google.gson.JsonParser; +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.colors.ColorTool; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.Properties; + + +public class GitHubApi { + private static final Logger logger = LoggerFactory.getLogger(GitHubApi.class); + private static final OkHttpClient client = new OkHttpClient(); + + public static void CheckForUpdatesByTags(String url) throws IOException { + Request request = new Request.Builder() + .url(url) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assert response.body() != null; + JsonArray tagArray = JsonParser.parseString(response.body().string()).getAsJsonArray(); + + String tag = tagArray.get(tagArray.size() -1).getAsJsonObject().get("ref").getAsString() + .replace("refs/tags/v.", ""); + + Properties properties = new Properties(); + + try (InputStream versionPropertiesStream = GitHubApi.class.getResourceAsStream("/vxrp/dev/version.properties")) { + if (versionPropertiesStream == null) { + throw new IllegalStateException("Version properties file does not exist"); + } + properties.load(new InputStreamReader(versionPropertiesStream, StandardCharsets.UTF_8)); + } + + if (!Objects.equals(properties.getProperty("version"), tag)) { + logger.warn("A new version has been found, you can download it from {}", ColorTool.apply(DCColor.LIGHT_BLUE, "https://github.com/Vxrpenter/SCPToolsBot/releases/tag/v."+tag)); + } + } +} From 4ded01ed00f3aff99c874ff9100f81abd8ab2e48 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:44:18 +0200 Subject: [PATCH 049/845] Version change --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 746662b6..64faf27a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version= "0.2.0" +version= "0.2.1" val jdaVersion = "5.0.0-beta.24" // From f9a8630a9fa8dcd286c1aafaa2067db38ca76516 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:10:40 +0200 Subject: [PATCH 050/845] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d982512d..5938ffb6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ | Languages | Api's | |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| - | Java yaml  | jda apachecommons  | + | Java yaml  | jda apachecommons sqlite  |
## What is ScpToolsBot From e84949120b31f97a613e7376e5741e0bec537574 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:17:56 +0200 Subject: [PATCH 051/845] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5938ffb6..c00e1bee 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ Currently the bot comes with: - SL ruleparsing - Text translation for features - Configurable commands +- Notice of Departure for staff +- Automatic notice of departure runout detection More coming soon, look [here](https://github.com/Vxrpenter/SCPToolsBot/wiki/Feature-Overview) for more complete overview From 9c37b79f23b2e7a5416bed1c3fd3108969f0bd80 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:36:34 +0200 Subject: [PATCH 052/845] Ping for new notice of departure --- .idea/sqldialects.xml | 1 - src/main/java/dev/vxrp/bot/ScpTools.java | 4 +++- .../vxrp/bot/events/modals/NoticeOfDeparture.java | 14 +++++++++++++- src/main/resources/translations/translations.yml | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index ee778ea4..e78ce6d8 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 37cc18eb..cd1b4c43 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -67,9 +67,11 @@ public static void main(String[] args) throws IOException { } private static void initializeSqlite() { + File file = new File(System.getProperty("user.dir")+"\\sqlite\\data.db"); try { + file.createNewFile(); sqliteManager = new SqliteManager(System.getProperty("user.dir")+"\\sqlite\\data.db"); - } catch (SQLException e) { + } catch (SQLException | IOException e) { logger.error("Could not correctly set up Sqlite database {}", e.getMessage()); } } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index f1308ca7..517def6f 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -16,8 +16,10 @@ import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.List; import java.util.Objects; import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; public class NoticeOfDeparture { private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); @@ -37,6 +39,11 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { event.reply(translations.ticket_created()).setEphemeral(true).queue(); assert channel != null; + List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() + .stream() + .map(id -> "<@&" + id + ">") + .collect(Collectors.toList()); + channel.sendMessageEmbeds( StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), new EmbedBuilder() @@ -57,7 +64,12 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { .addActionRow( Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", "Accept Ticket"), Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":", "Dismiss Ticket") - ).queue(); + ).queue(message -> { + message.editMessage(String.join("", pingRoles)).queue(); + }); + channel.sendMessage(String.join("", pingRoles)).queue(message -> { + message.delete().queue(); + }); } public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User user) { diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 9e7f52e1..5472bb1f 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -119,7 +119,7 @@ notice_of_departure: modal_title: "File Notice of Departure" modal_first_title: "Away time?" - modal_first_placeholder: "How long will you be away **[dd.MM.yyyy]**" + modal_first_placeholder: "How long will you be away [dd.MM.yyyy]" modal_second_title: "Explanation" modal_second_placeholder: "Why are you going to be away [exclude details]" From b304ff9a9e47af44a89f516e20f2692f6a20ff5d Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:24:30 +0200 Subject: [PATCH 053/845] Fixed stupid exists method (IDK what happened there but yeah) --- .idea/sqldialects.xml | 1 + .../vxrp/bot/database/sqlite/SqliteManager.java | 14 ++++++++------ .../vxrp/bot/events/modals/NoticeOfDeparture.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index e78ce6d8..ff225d7a 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 853373a7..8ba864dd 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -37,6 +37,10 @@ public SqliteManager(String path) throws SQLException { } public void addNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { + if (exists(id)) { + logger.warn("Notice of Departure already exists in Sqlite database... opting for deletion"); + deleteNoticeOfDeparture(id); + } try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?,?)")) { statement.setString(1, id); statement.setString(2, channel_message_id); @@ -171,14 +175,12 @@ public String getChannelMessageId(String id) throws SQLException { } public boolean exists(String id) { - try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { + try (PreparedStatement statement = connection.prepareStatement("SELECT EXISTS(SELECT 1 FROM notice_of_departure WHERE id=?);")) { statement.setString(1, id); - try (ResultSet resultSet = statement.executeQuery()) { - return true; - } catch (SQLException e) { - return false; - } + ResultSet resultSet = statement.executeQuery(); + return resultSet.getInt(1) == 1; } catch (SQLException e) { + System.out.println(e.getMessage()); return false; } } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 517def6f..1c4c870f 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -91,7 +91,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use new EmbedBuilder() .setTitle(translations.notice_title() .replace("%user%", Objects.requireNonNull(user.getGlobalName()))) - .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) + .setThumbnail(user.getAvatarUrl()) .setDescription(translations.notice_body() .replace("%user%", "<@"+event.getUser().getId()+">") .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) From edc9bfe6f87d156648dbe6787989ca0fade78f7d Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:13:30 +0200 Subject: [PATCH 054/845] Version 0.2.2 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 64faf27a..85281fc2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version= "0.2.1" +version= "0.2.2" val jdaVersion = "5.0.0-beta.24" // From ec0dde22cd29abee5da48dfbb138d6b5cea25669 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:46:41 +0200 Subject: [PATCH 055/845] Fixed error where the checker couldn't find the message --- .../bot/runnables/CheckNoticeOfDeparture.java | 71 +++++++++++-------- .../resources/translations/translations.yml | 2 +- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 745f6f77..86ff3889 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -19,6 +19,7 @@ import java.time.LocalDate; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; public class CheckNoticeOfDeparture { @@ -41,40 +42,48 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { logger.info("Found invalid notice of departure"); MessageChannel channel = api.getTextChannelById(notice.channel_id()); - Objects.requireNonNull(channel).retrieveMessageById(notice.message_id()).queue(message -> { - List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() - .stream() - .map(id -> "<@&" + id + ">") - .collect(Collectors.toList()); + assert channel != null; - message.editMessage(String.join("", pingRoles)).queue(); - channel.sendMessage(String.join("", pingRoles)).queue(ping -> ping.delete().queue()); - message.editMessageEmbeds(new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.notice_ended_replace() - .replace("%user%", Objects.requireNonNull(user.getGlobalName())) - .replace("%date%", now.toString()) - .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT"))) - .build()) - .setActionRow( - Button.danger("delete_notice_of_departure", "Delete Processed Notice of Departure") - ).queue(); - logger.info("Updated official notice of departure message in {}", channel.getName()); + channel.retrieveMessageById(notice.message_id()).onErrorMap(e -> null).queue(message -> { + if (message == null) { + logger.info("Found that message of notice does not exist... opting for deletion of database entry"); + } else { + List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() + .stream() + .map(id -> "<@&" + id + ">") + .collect(Collectors.toList()); + + message.editMessage(String.join("", pingRoles)).queue(); + channel.sendMessage(String.join("", pingRoles)).queue(ping -> ping.delete().queue()); + message.editMessageEmbeds(new EmbedBuilder() + .setDescription(ColorTool.useCustomColorCodes(translations.notice_ended_replace() + .replace("%user%", Objects.requireNonNull(user.getGlobalName())) + .replace("%date%", now.toString()) + .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT"))) + .build()) + .setActionRow( + Button.danger("delete_notice_of_departure", "Delete Processed Notice of Departure") + ).queue(); + logger.info("Updated official notice of departure message in {}", channel.getName()); + } }); - Objects.requireNonNull(user).openPrivateChannel().queue(privateChannel -> privateChannel.sendMessageEmbeds( - StatsBuilder.buildEnded(user.getGlobalName()).build(), - new EmbedBuilder().setDescription( - translations.notice_ended() - .replace("%timeframe%", notice.start_time()+" till "+notice.end_time())) - .build() - ).queue()); - logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); - try { - sqliteManager.deleteNoticeOfDeparture(notice.id()); - } catch (SQLException e) { - throw new RuntimeException(e); - } - logger.info(ColorTool.apply(DCColor.GOLD, "------------------------------------------------------------------------")); + Objects.requireNonNull(user).openPrivateChannel().queue(privateChannel -> { + privateChannel.sendMessageEmbeds( + StatsBuilder.buildEnded(user.getGlobalName()).build(), + new EmbedBuilder().setDescription( + translations.notice_ended() + .replace("%timeframe%", notice.start_time()+" till "+notice.end_time())) + .build() + ).queue(); + logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); + try { + sqliteManager.deleteNoticeOfDeparture(notice.id()); + } catch (SQLException e) { + throw new RuntimeException(e); + } + logger.info(ColorTool.apply(DCColor.GOLD, "------------------------------------------------------------------------")); + }); }); } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 5472bb1f..0d35dd1c 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -179,7 +179,7 @@ notice_of_departure: ```%timeframe%``` " notice_revoked: " - Your Notice of Departure has been revoked and all benefits going with at do not apply anymore \n + Your Notice of Departure has been revoked and all benefits going with that do not apply anymore \n __**Timeframe:**__\n ```%timeframe%``` From b21dcb4af3d09a10bb64bc7190fc796c36d64114 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:47:25 +0200 Subject: [PATCH 056/845] version changed to 0.2.3 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 85281fc2..196f3a3a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version= "0.2.2" +version= "0.2.3" val jdaVersion = "5.0.0-beta.24" // From 081c6bf926db3dc4ed8bd6fa6de4e19383933b90 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:14:26 +0200 Subject: [PATCH 057/845] Updated SqliteManager --- .../bot/database/sqlite/SqliteManager.java | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 8ba864dd..9862c49e 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -13,6 +13,7 @@ public class SqliteManager { private final Connection connection; private final Logger logger = LoggerFactory.getLogger(SqliteManager.class); + private final String prefix = ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")); public SqliteManager(String path) throws SQLException { connection = DriverManager.getConnection("jdbc:sqlite:"+path); @@ -24,8 +25,7 @@ public SqliteManager(String path) throws SQLException { "start_time TEXT NOT NULL," + "end_time TEXT NOT NULL" + ");"); - logger.info("{} - Set up table {} with rows: {}, {}, {}, {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Set up table {} with rows: {}, {}, {}, {}", prefix, ColorTool.apply(DCColor.GOLD, "notice_of_departure"), ColorTool.apply(DCColor.GREEN, "id"), ColorTool.apply(DCColor.GREEN, "channel_message_id"), @@ -47,8 +47,7 @@ public void addNoticeOfDeparture(String id, String channel_message_id, String st statement.setString(3, start_time); statement.setString(4, end_time); statement.executeUpdate(); - logger.info("{} - Added notice of departure - id: {}, channel_message_id: {} , start_time: {} , end_time: {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Added notice of departure - id: {}, channel_message_id: {} , start_time: {} , end_time: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GREEN, channel_message_id), ColorTool.apply(DCColor.GOLD, start_time), @@ -57,13 +56,17 @@ public void addNoticeOfDeparture(String id, String channel_message_id, String st } public void updateNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=?, end_time=? WHERE id=?")) { statement.setString(1, start_time); statement.setString(2, end_time); statement.setString(3, id); statement.executeUpdate(); - logger.info("{} - Updated notice of departure - id: {} , start_time: {} , end_time: {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Updated notice of departure - id: {} , start_time: {} , end_time: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, start_time), ColorTool.apply(DCColor.GOLD, end_time)); @@ -71,47 +74,63 @@ public void updateNoticeOfDeparture(String id, String channel_message_id, String } public void updateChannelMessageId(String id, String channel_message_id) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure channel and message id with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { statement.setString(1, channel_message_id); statement.setString(2, id); statement.executeUpdate(); - logger.info("{} - Updated start_time - id: {} , channel_message_id: {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Updated start_time - id: {} , channel_message_id: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, channel_message_id)); } } public void updateStartTime(String id,String start_time) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure start time with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { statement.setString(1, start_time); statement.setString(2, id); statement.executeUpdate(); - logger.info("{} - Updated start_time - id: {} , start_time: {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Updated start_time - id: {} , start_time: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, start_time)); } } public void updateEndTime(String id,String end_time) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure end time with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET end_time=? WHERE id=?")) { statement.setString(1, end_time); statement.setString(2, id); statement.executeUpdate(); - logger.info("{} - Updated end_time - id: {} , end_time: {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Updated end_time - id: {} , end_time: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, end_time)); } } public void deleteNoticeOfDeparture(String id) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to delete notice of departure with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } try (PreparedStatement statement = connection.prepareStatement("DELETE FROM notice_of_departure WHERE id=?")) { statement.setString(1, id); statement.executeUpdate(); - logger.info("{} - Deleted notice of departure - id: {}", - ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")), + logger.info("{} - Deleted notice of departure - id: {}", prefix, ColorTool.apply(DCColor.RED, id)); } } From 0cffc19c710d1d78417495930d24b3de37f0130e Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:05:11 +0200 Subject: [PATCH 058/845] This fixes the not functioning of the revoking and deleting button on the notice of departures --- .../dev/vxrp/bot/events/ButtonListener.java | 2 +- .../dev/vxrp/bot/events/ModalListener.java | 10 +++++++ .../bot/events/buttons/NoticeOfDeparture.java | 26 ++++++++++++------- .../bot/events/modals/NoticeOfDeparture.java | 14 ++++++++++ .../groups/NoticeOfDepartureGroup.java | 4 +-- .../translations/TranslationLoader.java | 4 ++- .../util/configuration/util/TRANSLATIONS.java | 2 ++ .../resources/translations/translations.yml | 9 ++++++- 8 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 8681f701..ed3c668d 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -64,7 +64,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> NoticeOfDeparture.revokeNoticeOfDeparture(event, user)); } if (event.getComponentId().equals("delete_notice_of_departure")) { - event.getMessage().delete().queue(); + NoticeOfDeparture.deleteNoticeOfDeparture(event); } } } diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index 4372f81c..22ebba4d 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.sql.SQLException; public class ModalListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ModalListener.class); @@ -42,5 +43,14 @@ public void onModalInteraction(ModalInteractionEvent event) { if (event.getModalId().startsWith("reason_action_dismiss_nod")) { event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); } + if (event.getModalId().startsWith("reason_action_revoke_nod")) { + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> { + try { + NoticeOfDeparture.revokeNoticeOfDeparture(event, user); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); + } } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 33450bfe..15c836e7 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -1,10 +1,8 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; @@ -61,15 +59,23 @@ public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User u ))).build()).queue(); } + // Fires when notice of departure is revoked by button press. Opens up a modal to put in a reason for the user public static void revokeNoticeOfDeparture(ButtonInteractionEvent event, User user) { - user.openPrivateChannel().queue(privateChannel -> - privateChannel.sendMessageEmbeds( - StatsBuilder.buildRevoked(user.getGlobalName()).build(), - new EmbedBuilder() - .setDescription(translations.notice_revoked() - .replace("%timeframe%", event.getComponentId().split(":")[3]+" till "+event.getComponentId().split(":")[2])) - .build() - ).queue()); + event.getMessage().delete().queue(); + event.reply(translations.notice_revoked()).setEphemeral(true).queue(); + event.replyModal( + Modal.create("reason_action_revoke_nod:"+user.getId()+":"+event.getComponentId().split(":")[3]+":"+event.getComponentId().split(":")[2]+":", reason_action.modal_reason_action_title()) + .addComponents(ActionRow.of(shortModal( + "reason_action_reason", + reason_action.modal_reason_action_first_title(), + reason_action.modal_reason_action_first_placeholder(), + 10, 100 + ))).build()).queue(); + } + + public static void deleteNoticeOfDeparture(ButtonInteractionEvent event) { + event.getMessage().delete().queue(); + event.reply(translations.notice_revoked()).setEphemeral(true).queue(); } private static TextInput shortModal(String id,String title, String placeholder, int min, int max) { diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 1c4c870f..a4c3489d 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -133,4 +133,18 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); } + + public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException { + user.openPrivateChannel().queue(privateChannel -> + privateChannel.sendMessageEmbeds( + StatsBuilder.buildRevoked(user.getGlobalName()).build(), + new EmbedBuilder() + .setDescription(translations.notice_revoked() + .replace("%timeframe%", event.getModalId().split(":")[3]+" till "+event.getModalId().split(":")[2]) + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) + .build() + ).queue()); + Objects.requireNonNull(event.getMessage()).delete().queue(); + ScpTools.getSqliteManager().deleteNoticeOfDeparture(user.getId()); + } } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java index b4e6b397..d61c2cb3 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java @@ -4,6 +4,6 @@ public record NoticeOfDepartureGroup(String first_title, String first_body, Stri String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, String ticket_title, String ticket_body, String ticket_footer, String ticket_created, String ticket_accepted, String ticket_dismissed, String ticket_message_sent, String notice_title, - String notice_body, String notice_footer, String notice_ended, String notice_revoked, - String notice_ended_replace) { + String notice_body, String notice_footer, String notice_ended, String notice_revoked, String notice_revoked_message, + String notice_ended_replace, String notice_deleted_ended_replace) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 15a99155..e5558a81 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -68,7 +68,9 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.FOOTER), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE)); + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED_MESSAGE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE), + translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.DELETED_ENDED_REPLACE_MESSAGE)); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 5a4e21ad..7ef1e3e2 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -69,6 +69,8 @@ public static final class NOTICE { } public static final String ENDED = "notice_of_departure.notice_ended"; public static final String REVOKED = "notice_of_departure.notice_revoked"; + public static final String REVOKED_MESSAGE = "notice_of_departure.notice_revoked_message"; public static final String ENDED_REPLACE = "notice_of_departure.notice_ended_replace"; + public static final String DELETED_ENDED_REPLACE_MESSAGE = "notice_of_departure.notice_deleted_ended_replace_message"; } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 0d35dd1c..8a4d5719 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -183,7 +183,12 @@ notice_of_departure: __**Timeframe:**__\n ```%timeframe%``` + + __**Acceptance Reason:**__\n + ```%reason%``` " + notice_revoked_message: "The notice was correctly revoked" + notice_ended_replace: " ```ansi @@ -200,4 +205,6 @@ notice_of_departure: Dealt with by: &gold&&bold&%actionTaker% ``` - " \ No newline at end of file + " + + notice_deleted_ended_replace_message: "The notice was deleted" \ No newline at end of file From 59c69016c8d63d05fcdf02b7537c22d449d40e73 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:14:31 +0200 Subject: [PATCH 059/845] Fixed everything from the last commit --- .../java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java | 4 +--- .../java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 15c836e7..665d9dfb 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -61,8 +61,6 @@ public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User u // Fires when notice of departure is revoked by button press. Opens up a modal to put in a reason for the user public static void revokeNoticeOfDeparture(ButtonInteractionEvent event, User user) { - event.getMessage().delete().queue(); - event.reply(translations.notice_revoked()).setEphemeral(true).queue(); event.replyModal( Modal.create("reason_action_revoke_nod:"+user.getId()+":"+event.getComponentId().split(":")[3]+":"+event.getComponentId().split(":")[2]+":", reason_action.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( @@ -75,7 +73,7 @@ public static void revokeNoticeOfDeparture(ButtonInteractionEvent event, User us public static void deleteNoticeOfDeparture(ButtonInteractionEvent event) { event.getMessage().delete().queue(); - event.reply(translations.notice_revoked()).setEphemeral(true).queue(); + event.reply(translations.notice_deleted_ended_replace()).setEphemeral(true).queue(); } private static TextInput shortModal(String id,String title, String placeholder, int min, int max) { diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index a4c3489d..20626003 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -135,6 +135,9 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us } public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException { + ScpTools.getSqliteManager().deleteNoticeOfDeparture(user.getId()); + Objects.requireNonNull(event.getMessage()).delete().queue(); + event.reply(translations.notice_revoked_message()).setEphemeral(true).queue(); user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildRevoked(user.getGlobalName()).build(), @@ -144,7 +147,5 @@ public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User use .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) .build() ).queue()); - Objects.requireNonNull(event.getMessage()).delete().queue(); - ScpTools.getSqliteManager().deleteNoticeOfDeparture(user.getId()); } } \ No newline at end of file From c834ae854166b895d37cf62eebec58e1c0099a7c Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:15:15 +0200 Subject: [PATCH 060/845] version 0.2.4 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 196f3a3a..d7f5541f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version= "0.2.3" +version= "0.2.4" val jdaVersion = "5.0.0-beta.24" // From 542ba743f1093bead49a77542b9c6bf90c8fcba7 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:21:23 +0200 Subject: [PATCH 061/845] Every translation now uses the colorcode parser --- src/main/java/dev/vxrp/bot/ScpTools.java | 6 ++- .../noticeOfDeparture/NoticeOfDeparture.java | 5 ++- .../commands/templates/support/Support.java | 9 ++-- .../bot/events/buttons/NoticeOfDeparture.java | 31 +++++++------- .../dev/vxrp/bot/events/buttons/Support.java | 11 ++--- .../dev/vxrp/bot/events/buttons/Unban.java | 27 ++++++------ .../bot/events/modals/NoticeOfDeparture.java | 42 +++++++++---------- .../dev/vxrp/bot/events/modals/Support.java | 14 +++---- .../dev/vxrp/bot/events/modals/Unban.java | 26 ++++++------ .../bot/runnables/CheckNoticeOfDeparture.java | 10 ++--- 10 files changed, 93 insertions(+), 88 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index cd1b4c43..190ad5ab 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.nio.file.Paths; import java.sql.SQLException; import java.util.*; @@ -67,10 +68,11 @@ public static void main(String[] args) throws IOException { } private static void initializeSqlite() { - File file = new File(System.getProperty("user.dir")+"\\sqlite\\data.db"); + Path path = Paths.get(".").toAbsolutePath().normalize(); + File file = new File(path+"\\sqlite\\data.db"); try { file.createNewFile(); - sqliteManager = new SqliteManager(System.getProperty("user.dir")+"\\sqlite\\data.db"); + sqliteManager = new SqliteManager(path+"\\sqlite\\data.db"); } catch (SQLException | IOException e) { logger.error("Could not correctly set up Sqlite database {}", e.getMessage()); } diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index be2970de..b3acc393 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.commands.templates.noticeOfDeparture; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -14,8 +15,8 @@ public class NoticeOfDeparture { public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translations.first_title()) - .setDescription(translations.first_body()) + .setTitle(ColorTool.useCustomColorCodes(translations.first_title())) + .setDescription(ColorTool.useCustomColorCodes(translations.first_body())) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index cfdcfcc1..88ea89b7 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.commands.templates.support; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -15,15 +16,15 @@ public class Support { public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translations.first_title()) - .setDescription(translations.first_body()) + .setTitle(ColorTool.useCustomColorCodes(translations.first_title())) + .setDescription(ColorTool.useCustomColorCodes(translations.first_body())) .setColor(Color.DARK_GRAY) .build()) .queue(); event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(translations.second_title()) - .setDescription(translations.second_body()) + .setTitle(ColorTool.useCustomColorCodes(translations.second_title())) + .setDescription(ColorTool.useCustomColorCodes(translations.second_body())) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 665d9dfb..b93f95c6 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; @@ -19,17 +20,17 @@ public class NoticeOfDeparture { public static void createNoticeOfDeparture(ButtonInteractionEvent event) { event.replyModal( - Modal.create("notice_of_departure", translations.modal_title()) + Modal.create("notice_of_departure", ColorTool.useCustomColorCodes(translations.modal_title())) .addComponents( ActionRow.of(shortModal( "nod_timeframe", - translations.modal_first_title(), - translations.modal_first_placeholder(), + ColorTool.useCustomColorCodes(translations.modal_first_title()), + ColorTool.useCustomColorCodes(translations.modal_first_placeholder()), 8,10 )), ActionRow.of(paragraphModal( - translations.modal_second_title(), - translations.modal_second_placeholder() + ColorTool.useCustomColorCodes(translations.modal_second_title()), + ColorTool.useCustomColorCodes(translations.modal_second_placeholder()) ))) .build()).queue(); } @@ -39,22 +40,22 @@ public static void acceptedNoticeOfDeparture(ButtonInteractionEvent event, User String end_time = event.getComponentId().split(":")[2]; event.replyModal( - Modal.create("reason_action_accepted_nod:"+user.getId()+":"+event.getMessageId()+":"+end_time+":"+start_time+":", reason_action.modal_reason_action_title()) + Modal.create("reason_action_accepted_nod:"+user.getId()+":"+event.getMessageId()+":"+end_time+":"+start_time+":", ColorTool.useCustomColorCodes(reason_action.modal_reason_action_title())) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - reason_action.modal_reason_action_first_title(), - reason_action.modal_reason_action_first_placeholder(), + ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_title()), + ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_placeholder()), 10, 100 ))).build()).queue(); } public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User user) { event.replyModal( - Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", reason_action.modal_reason_action_title()) + Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", ColorTool.useCustomColorCodes(reason_action.modal_reason_action_title())) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - reason_action.modal_reason_action_first_title(), - reason_action.modal_reason_action_first_placeholder(), + ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_title()), + ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_placeholder()), 10, 100 ))).build()).queue(); } @@ -62,18 +63,18 @@ public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User u // Fires when notice of departure is revoked by button press. Opens up a modal to put in a reason for the user public static void revokeNoticeOfDeparture(ButtonInteractionEvent event, User user) { event.replyModal( - Modal.create("reason_action_revoke_nod:"+user.getId()+":"+event.getComponentId().split(":")[3]+":"+event.getComponentId().split(":")[2]+":", reason_action.modal_reason_action_title()) + Modal.create("reason_action_revoke_nod:"+user.getId()+":"+event.getComponentId().split(":")[3]+":"+event.getComponentId().split(":")[2]+":", ColorTool.useCustomColorCodes( reason_action.modal_reason_action_title())) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - reason_action.modal_reason_action_first_title(), - reason_action.modal_reason_action_first_placeholder(), + ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_title()), + ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_placeholder()), 10, 100 ))).build()).queue(); } public static void deleteNoticeOfDeparture(ButtonInteractionEvent event) { event.getMessage().delete().queue(); - event.reply(translations.notice_deleted_ended_replace()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.notice_deleted_ended_replace())).setEphemeral(true).queue(); } private static TextInput shortModal(String id,String title, String placeholder, int min, int max) { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index b30bad65..2d984f20 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -20,15 +21,15 @@ public class Support { public static void createSupportTicket(ButtonInteractionEvent event) { if (event.getComponentId().equals("createNewTicket")) { event.replyModal( - Modal.create("supportTicket", translations.modal_support_title()) + Modal.create("supportTicket", ColorTool.useCustomColorCodes(translations.modal_support_title())) .addComponents( ActionRow.of(shortModal( - translations.modal_support_first_title(), - translations.modal_support_first_placeholder() + ColorTool.useCustomColorCodes(translations.modal_support_first_title()), + ColorTool.useCustomColorCodes(translations.modal_support_first_placeholder()) )), ActionRow.of(paragraphModal( - translations.modal_support_second_title(), - translations.modal_support_second_placeholder()))) + ColorTool.useCustomColorCodes(translations.modal_support_second_title()), + ColorTool.useCustomColorCodes(translations.modal_support_second_placeholder())))) .build()).queue(); } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 45dde301..7f877f8d 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.entities.User; @@ -16,32 +17,32 @@ public class Unban { public static void createUnbanTicket(ButtonInteractionEvent event) { event.replyModal( - Modal.create("unbanTicket", translations.modal_unban_title()) + Modal.create("unbanTicket", ColorTool.useCustomColorCodes(translations.modal_unban_title())) .addComponents( ActionRow.of(shortModal( "unban_steamID", - translations.modal_unban_first_title(), - translations.modal_unban_first_placeholder(), + ColorTool.useCustomColorCodes(translations.modal_unban_first_title()), + ColorTool.useCustomColorCodes(translations.modal_unban_first_placeholder()), 17, 17)), ActionRow.of(shortModal( "unban_ban_reason", - translations.modal_unban_second_title(), - translations.modal_unban_second_placeholder(), + ColorTool.useCustomColorCodes(translations.modal_unban_second_title()), + ColorTool.useCustomColorCodes(translations.modal_unban_second_placeholder()), 5, 100)), ActionRow.of(paragraphModal( - translations.modal_unban_third_title(), - translations.modal_unban_third_placeholder()))) + ColorTool.useCustomColorCodes(translations.modal_unban_third_title()), + ColorTool.useCustomColorCodes(translations.modal_unban_third_placeholder())))) .build()).queue(); } public static void dismissTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.modal_reason_action_title()) + Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", ColorTool.useCustomColorCodes(translations.modal_reason_action_title())) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - translations.modal_reason_action_first_title(), - translations.modal_reason_action_first_placeholder(), + ColorTool.useCustomColorCodes(translations.modal_reason_action_first_title()), + ColorTool.useCustomColorCodes(translations.modal_reason_action_first_placeholder()), 10, 100 ))).build()).queue(); } @@ -49,11 +50,11 @@ public static void dismissTicket(ButtonInteractionEvent event, User user) { public static void acceptTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.modal_reason_action_title()) + Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", ColorTool.useCustomColorCodes(translations.modal_reason_action_title())) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - translations.modal_reason_action_first_title(), - translations.modal_reason_action_first_placeholder(), + ColorTool.useCustomColorCodes(translations.modal_reason_action_first_title()), + ColorTool.useCustomColorCodes(translations.modal_reason_action_first_placeholder()), 10, 100 ))).build()).queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 20626003..d698b9fb 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -36,7 +36,7 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { String day = new SimpleDateFormat("dd").format(Calendar.getInstance().getTime()); String month = new SimpleDateFormat("MM").format(Calendar.getInstance().getTime()); String year = new SimpleDateFormat("yyyy").format(Calendar.getInstance().getTime()); - event.reply(translations.ticket_created()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_created())).setEphemeral(true).queue(); assert channel != null; List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() @@ -47,19 +47,19 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { channel.sendMessageEmbeds( StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), new EmbedBuilder() - .setTitle(translations.ticket_title().replace("%number%", String.valueOf(ThreadLocalRandom.current().nextInt(1938, 9750)))) + .setTitle(ColorTool.useCustomColorCodes(translations.ticket_title().replace("%number%", String.valueOf(ThreadLocalRandom.current().nextInt(1938, 9750))))) .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) - .setDescription(translations.ticket_body() + .setDescription(ColorTool.useCustomColorCodes(translations.ticket_body() .replace("%current_day%", ColorTool.apply(DCColor.BOLD, day)) .replace("%current_month%", ColorTool.apply(DCColor.BOLD, month)) .replace("%current_year%", ColorTool.apply(DCColor.BOLD, year)) .replace("%day%", ColorTool.apply(DCColor.BOLD, givenDate[0])) .replace("%month%", ColorTool.apply(DCColor.BOLD, givenDate[1])) .replace("%year%", ColorTool.apply(DCColor.BOLD, givenDate[2])) - .replace("%reason%", reason)) - .setFooter(translations.ticket_footer() + .replace("%reason%", reason))) + .setFooter(ColorTool.useCustomColorCodes(translations.ticket_footer() .replace("%date%", date) - .replace("%time%", time)) + .replace("%time%", time))) .build()) .addActionRow( Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", "Accept Ticket"), @@ -80,25 +80,25 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildAccepted(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.ticket_accepted() + .setDescription(ColorTool.useCustomColorCodes(translations.ticket_accepted() .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) - .replace("%reason%", reason)) + .replace("%reason%", reason))) .build() )).queue(); Objects.requireNonNull(event.getGuild().getTextChannelById(LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_notice_channel_id())).sendMessageEmbeds( StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), new EmbedBuilder() - .setTitle(translations.notice_title() - .replace("%user%", Objects.requireNonNull(user.getGlobalName()))) + .setTitle(ColorTool.useCustomColorCodes(translations.notice_title() + .replace("%user%", Objects.requireNonNull(user.getGlobalName())))) .setThumbnail(user.getAvatarUrl()) - .setDescription(translations.notice_body() + .setDescription(ColorTool.useCustomColorCodes(translations.notice_body() .replace("%user%", "<@"+event.getUser().getId()+">") .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) - .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) - .setFooter(translations.notice_footer() + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString()))) + .setFooter(ColorTool.useCustomColorCodes(translations.notice_footer() .replace("%date%", date) - .replace("%time%", time)) + .replace("%time%", time))) .build()) .addActionRow( Button.danger("revoke_notice_of_departure"+":"+ @@ -115,7 +115,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use throw new RuntimeException(e); } }); - event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_message_sent())).setEphemeral(true).queue(); } public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User user) { @@ -126,25 +126,25 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.ticket_dismissed() - .replace("%reason%", reason)) + .setDescription(ColorTool.useCustomColorCodes(translations.ticket_dismissed() + .replace("%reason%", reason))) .build() )).queue(); - event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_message_sent())).setEphemeral(true).queue(); } public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException { ScpTools.getSqliteManager().deleteNoticeOfDeparture(user.getId()); Objects.requireNonNull(event.getMessage()).delete().queue(); - event.reply(translations.notice_revoked_message()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.notice_revoked_message())).setEphemeral(true).queue(); user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildRevoked(user.getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.notice_revoked() + .setDescription(ColorTool.useCustomColorCodes(translations.notice_revoked() .replace("%timeframe%", event.getModalId().split(":")[3]+" till "+event.getModalId().split(":")[2]) - .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString()))) .build() ).queue()); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 004cfb6a..5e64238f 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -44,8 +44,8 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .addPermissionOverride(guild.getPublicRole(), null, EnumSet.of(Permission.VIEW_CHANNEL)) .setSlowmode(1) .queue(textChannel -> { - event.reply(translations.ticket_support_created() - .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_support_created() + .replace("%channel%", "<#"+textChannel.getId()+">"))).setEphemeral(true).queue(); List roleIDs = configs.support_settings_roles_access_support_tickets(); for (String id : roleIDs) { @@ -55,13 +55,13 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .queue(); } textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); - textChannel.sendMessageEmbeds(builder(translations.ticket_support_title().replace("%name%", name), - translations.ticket_support_body() + textChannel.sendMessageEmbeds(builder(ColorTool.useCustomColorCodes(translations.ticket_support_title().replace("%name%", name)), + ColorTool.useCustomColorCodes(translations.ticket_support_body() .replace("%subject%", subject) - .replace("%body%", body), - translations.ticket_support_footer() + .replace("%body%", body)), + ColorTool.useCustomColorCodes(translations.ticket_support_footer() .replace("%date%", date) - .replace("%time%", time), + .replace("%time%", time)), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( Button.danger("close_support_ticket:"+userID+":", "Close Ticket"), diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 54150186..c5d9b835 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -47,8 +47,8 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) TextChannel textChannel = event.getGuild().getTextChannelById(configs.support_settings_unban_channel_id()); assert textChannel != null; - event.reply(translations.ticket_unban_created() - .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_unban_created() + .replace("%channel%", "<#"+textChannel.getId()+">"))).setEphemeral(true).queue(); List roleIDs = configs.support_settings_roles_access_unban_tickets(); for (String id : roleIDs) { @@ -59,14 +59,14 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) } textChannel.sendMessageEmbeds( StatsBuilder.buildStatus(userName).build(), - builder(translations.ticket_unban_title().replace("%name%", name), - translations.ticket_unban_body() + builder(ColorTool.useCustomColorCodes(translations.ticket_unban_title().replace("%name%", name)), + ColorTool.useCustomColorCodes(translations.ticket_unban_body() .replace("%steamID%", steamID) .replace("%reason%", reason) - .replace("%reasoning%", reasoning), - translations.ticket_unban_footer() + .replace("%reasoning%", reasoning)), + ColorTool.useCustomColorCodes(translations.ticket_unban_footer() .replace("%date%", date) - .replace("%time%", time), + .replace("%time%", time)), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( Button.success("accept_unban_ticket:"+userID+":"+steamID+":", "Accept Ticket"), @@ -94,15 +94,15 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildAccepted(bannedUser.getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.ticket_unban_message_accepted() + .setDescription(ColorTool.useCustomColorCodes(translations.ticket_unban_message_accepted() .replace("%steamID%", steamID) - .replace("%reason%", reason)) + .replace("%reason%", reason))) .build() )).queue(); CedModApi.executeUnban(instanceUrl, apiKey, banID, reason); - event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_unban_message_sent())).setEphemeral(true).queue(); } public static void dismissUnban(ModalInteractionEvent event, User user) { String messageID = event.getModalId().split(":")[3]; @@ -115,14 +115,14 @@ public static void dismissUnban(ModalInteractionEvent event, User user) { user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(translations.ticket_unban_message_dismissed() + .setDescription(ColorTool.useCustomColorCodes(translations.ticket_unban_message_dismissed() .replace("%steamID%", steamID) - .replace("%reason%", reason)) + .replace("%reason%", reason))) .build() )).queue(); - event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); + event.reply(ColorTool.useCustomColorCodes(translations.ticket_unban_message_sent())).setEphemeral(true).queue(); } private static EmbedBuilder builder(String title, String body, String footerText, String IconURL, User user) { diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 86ff3889..45015aa5 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -19,7 +19,6 @@ import java.time.LocalDate; import java.util.List; import java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; public class CheckNoticeOfDeparture { @@ -56,10 +55,10 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { message.editMessage(String.join("", pingRoles)).queue(); channel.sendMessage(String.join("", pingRoles)).queue(ping -> ping.delete().queue()); message.editMessageEmbeds(new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.notice_ended_replace() + .setDescription(ColorTool.useCustomColorCodes(ColorTool.useCustomColorCodes(translations.notice_ended_replace() .replace("%user%", Objects.requireNonNull(user.getGlobalName())) .replace("%date%", now.toString()) - .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT"))) + .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT")))) .build()) .setActionRow( Button.danger("delete_notice_of_departure", "Delete Processed Notice of Departure") @@ -71,9 +70,8 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { Objects.requireNonNull(user).openPrivateChannel().queue(privateChannel -> { privateChannel.sendMessageEmbeds( StatsBuilder.buildEnded(user.getGlobalName()).build(), - new EmbedBuilder().setDescription( - translations.notice_ended() - .replace("%timeframe%", notice.start_time()+" till "+notice.end_time())) + new EmbedBuilder().setDescription(ColorTool.useCustomColorCodes(translations.notice_ended() + .replace("%timeframe%", notice.start_time()+" till "+notice.end_time()))) .build() ).queue(); logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); From 9b2a18d1d860465f51b32ee65e490af2568d7698 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:27:49 +0200 Subject: [PATCH 062/845] Added some buttons translation features for later usage --- .../util/configuration/LoadedConfigurations.java | 16 ++++++++++++++++ .../util/configuration/groups/ButtonsGroup.java | 4 ++++ .../util/configuration/util/TRANSLATIONS.java | 3 +++ src/main/resources/translations/translations.yml | 4 +++- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java index cca7d105..29b8937a 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java @@ -1,9 +1,11 @@ package dev.vxrp.bot.util.configuration; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import javax.swing.*; import java.util.HashSet; import java.util.Iterator; @@ -11,6 +13,7 @@ public class LoadedConfigurations { public static HashSet configMemoryLoad = new HashSet<>(); public static HashSet supportTranslationMemoryLoad = new HashSet<>(); public static HashSet noticeOfDepartureMemoryLoad = new HashSet<>(); + public static HashSet buttonsMemoryLoad = new HashSet<>(); public static ConfigGroup getConfigMemoryLoad() { Iterator iterator = configMemoryLoad.iterator(); @@ -50,4 +53,17 @@ public static NoticeOfDepartureGroup getNoticeOfDepartureMemoryLoad() { public static void setNoticeOfDepartureMemoryLoad(NoticeOfDepartureGroup noticeOfDepartureMemoryLoad) { LoadedConfigurations.noticeOfDepartureMemoryLoad.add(noticeOfDepartureMemoryLoad); } + + public static ButtonsGroup getButtonsMemoryLoad() { + Iterator iterator = buttonsMemoryLoad.iterator(); + ButtonsGroup buttonsGroup = null; + while (iterator.hasNext()) { + buttonsGroup = iterator.next(); + } + return buttonsGroup; + } + + public static void setButtonsMemoryLoad(ButtonsGroup buttonsMemoryLoad) { + LoadedConfigurations.buttonsMemoryLoad.add(buttonsMemoryLoad); + } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java new file mode 100644 index 00000000..d6ee4fed --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java @@ -0,0 +1,4 @@ +package dev.vxrp.bot.util.configuration.groups; + +public record ButtonsGroup() { +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 7ef1e3e2..123304b4 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -73,4 +73,7 @@ public static final class NOTICE { public static final String ENDED_REPLACE = "notice_of_departure.notice_ended_replace"; public static final String DELETED_ENDED_REPLACE_MESSAGE = "notice_of_departure.notice_deleted_ended_replace_message"; } + public static final class BUTTONS { + + } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 8a4d5719..3ff69b84 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -207,4 +207,6 @@ notice_of_departure: ``` " - notice_deleted_ended_replace_message: "The notice was deleted" \ No newline at end of file + notice_deleted_ended_replace_message: "The notice was deleted" + +buttons: From cd4ed8f1af1a37cce446d68f4ef534e818e391b3 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 26 Oct 2024 17:06:24 +0200 Subject: [PATCH 063/845] Made every button translatable --- build.gradle.kts | 2 +- .../commands/templates/TemplateCommand.java | 10 +++++--- .../commands/templates/support/Support.java | 6 +++-- .../bot/events/modals/NoticeOfDeparture.java | 8 ++++--- .../dev/vxrp/bot/events/modals/Support.java | 8 ++++--- .../dev/vxrp/bot/events/modals/Unban.java | 8 ++++--- .../bot/runnables/CheckNoticeOfDeparture.java | 6 +++-- .../configuration/configs/ConfigLoader.java | 3 ++- .../configuration/groups/ButtonsGroup.java | 6 ++++- .../translations/TranslationLoader.java | 23 ++++++++++++++++++- .../util/configuration/util/TRANSLATIONS.java | 16 +++++++++++++ .../resources/translations/translations.yml | 18 +++++++++++++++ 12 files changed, 94 insertions(+), 20 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d7f5541f..88c2ca0b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version= "0.2.4" +version= "0.2.5" val jdaVersion = "5.0.0-beta.24" // diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index 4167f1f6..950e90db 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -4,6 +4,8 @@ import dev.vxrp.bot.commands.templates.support.Support; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -13,7 +15,9 @@ import java.util.Objects; public class TemplateCommand extends ListenerAdapter { - public final static Logger logger = LoggerFactory.getLogger(TemplateCommand.class); + private final Logger logger = LoggerFactory.getLogger(TemplateCommand.class); + private final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + @Override public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { if (!event.getFullCommandName().equals("template")) return; @@ -23,8 +27,8 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { if (template.equals("rules")) { event.reply("Choose the rule pasting option") .addActionRow( - Button.success("paste_rules", "Paste Rules"), - Button.danger("update_rules", "Update Rules") + Button.success("paste_rules", buttons.paste_rules()), + Button.danger("update_rules", buttons.update_rules()) ) .setEphemeral(true).queue(); } diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index 88ea89b7..df673b18 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; @@ -12,6 +13,7 @@ public class Support { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); + private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() @@ -28,8 +30,8 @@ public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { .setColor(Color.DARK_GRAY) .build()) .addActionRow( - Button.success("createNewTicket", "Create Support Ticket").withEmoji(Emoji.fromUnicode("📩")), - Button.danger("createNewUnban", "File Unban Request").withEmoji(Emoji.fromUnicode("📩")) + Button.success("createNewTicket", buttons.create_new_support_ticket()).withEmoji(Emoji.fromUnicode("📩")), + Button.danger("createNewUnban", buttons.create_new_unban_ticket()).withEmoji(Emoji.fromUnicode("📩")) ).queue(); } } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index d698b9fb..ab9fa824 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -5,6 +5,7 @@ import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -24,6 +25,7 @@ public class NoticeOfDeparture { private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); private static final String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); private static final String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); @@ -62,8 +64,8 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { .replace("%time%", time))) .build()) .addActionRow( - Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", "Accept Ticket"), - Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":", "Dismiss Ticket") + Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", buttons.accept_notice_of_departure_ticket()), + Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":", buttons.dismiss_notice_of_departure_ticket()) ).queue(message -> { message.editMessage(String.join("", pingRoles)).queue(); }); @@ -102,7 +104,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use .build()) .addActionRow( Button.danger("revoke_notice_of_departure"+":"+ - user.getId()+":"+event.getModalId().split(":")[4]+":"+event.getModalId().split(":")[4]+":", "Revoke Notice of Departure") + user.getId()+":"+event.getModalId().split(":")[4]+":"+event.getModalId().split(":")[4]+":", buttons.revoke_notice_of_departure()) ).queue(message -> { try { ScpTools.getSqliteManager().addNoticeOfDeparture( diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 5e64238f..93ed1a45 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,6 +1,7 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.Enums.DCColor; @@ -24,6 +25,7 @@ public class Support { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); + private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); public static void createSupportTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); @@ -64,9 +66,9 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .replace("%time%", time)), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( - Button.danger("close_support_ticket:"+userID+":", "Close Ticket"), - Button.primary("claim_support_ticket:"+userID+":", "Claim Ticket"), - Button.secondary("settings_support_ticket", "Settings") + Button.danger("close_support_ticket:"+userID+":", buttons.close_support_ticket()), + Button.primary("claim_support_ticket:"+userID+":", buttons.claim_support_ticket()), + Button.secondary("settings_support_ticket", buttons.settings_support_ticket()) ).queue(); }); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index c5d9b835..bc861931 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events.modals; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; @@ -28,6 +29,7 @@ public class Unban { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); + private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); @@ -69,9 +71,9 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) .replace("%time%", time)), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( - Button.success("accept_unban_ticket:"+userID+":"+steamID+":", "Accept Ticket"), - Button.danger("dismiss_unban_ticket:"+userID+":"+steamID+":", "Dismiss Ticket"), - Button.secondary("settings_unban_ticket", "Settings") + Button.success("accept_unban_ticket:"+userID+":"+steamID+":", buttons.accept_unban_ticket()), + Button.danger("dismiss_unban_ticket:"+userID+":"+steamID+":", buttons.dismiss_unban_ticket()), + Button.secondary("settings_unban_ticket", buttons.settings_unban_ticket()) ).queue(); logger.info("Created new unban request by user {} - under name {}", ColorTool.apply(DCColor.GREEN, userName), ColorTool.apply(DCColor.RED, name)); diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 45015aa5..ceb1a727 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -6,6 +6,7 @@ import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.objects.NoticeOfDeparture; import net.dv8tion.jda.api.EmbedBuilder; @@ -22,8 +23,9 @@ import java.util.stream.Collectors; public class CheckNoticeOfDeparture { - private final static Logger logger = LoggerFactory.getLogger(ScpTools.class); + private final static Logger logger = LoggerFactory.getLogger(CheckNoticeOfDeparture.class); private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); public static Runnable runNoticeOfDepartureCheck(JDA api) { return () -> { @@ -61,7 +63,7 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT")))) .build()) .setActionRow( - Button.danger("delete_notice_of_departure", "Delete Processed Notice of Departure") + Button.danger("delete_notice_of_departure", buttons.delete_notice_of_departure()) ).queue(); logger.info("Updated official notice of departure message in {}", channel.getName()); } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 1d75feed..ca7b5285 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -40,7 +40,8 @@ public ConfigLoader() { configManager.getString(CONFIG.CEDMOD.API_KEY), configManager.getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID)); + logger.warn("Loading configurations, this could take some time..."); LoadedConfigurations.setConfigMemoryLoad(configGroup); - logger.info("Loaded config into memory"); + logger.info("Loaded configurations"); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java index d6ee4fed..22b1c5b7 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java @@ -1,4 +1,8 @@ package dev.vxrp.bot.util.configuration.groups; -public record ButtonsGroup() { +public record ButtonsGroup(String paste_rules, String update_rules, String create_new_support_ticket, + String close_support_ticket, String claim_support_ticket, String settings_support_ticket, + String create_new_unban_ticket, String accept_unban_ticket, String dismiss_unban_ticket, + String settings_unban_ticket, String accept_notice_of_departure_ticket, String dismiss_notice_of_departure_ticket, + String revoke_notice_of_departure, String delete_notice_of_departure) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index e5558a81..ef9cb486 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; @@ -72,8 +73,28 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.DELETED_ENDED_REPLACE_MESSAGE)); + ButtonsGroup buttonsGroup = new ButtonsGroup( + translationManager.getString(TRANSLATIONS.BUTTONS.PASTE_RULES), + translationManager.getString(TRANSLATIONS.BUTTONS.UPDATE_RULES), + translationManager.getString(TRANSLATIONS.BUTTONS.CREATE_NEW_SUPPORT_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.CLOSE_SUPPORT_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.CLAIM_SUPPORT_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.SETTINGS_SUPPORT_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.CREATE_NEW_UNBAN_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.ACCEPT_UNBAN_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.DISMISS_UNBAN_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.SETTINGS_UNBAN_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.ACCEPT_NOTICE_OF_DEPARTURE_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.DISMISS_NOTICE_OF_DEPARTURE_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.REVOKE_NOTICE_OF_DEPARTURE), + translationManager.getString(TRANSLATIONS.BUTTONS.DELETE_NOTICE_OF_DEPARTURE)); + + logger.warn("Loading translations, this could take some time..."); + LoadedConfigurations.setButtonsMemoryLoad(buttonsGroup); + logger.info("Loaded button translations"); LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); + logger.info("Loaded support translations"); LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); - logger.info("Loaded translations into memory"); + logger.info("Loaded notice of departure translations"); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 123304b4..b88339f2 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -74,6 +74,22 @@ public static final class NOTICE { public static final String DELETED_ENDED_REPLACE_MESSAGE = "notice_of_departure.notice_deleted_ended_replace_message"; } public static final class BUTTONS { + public static final String PASTE_RULES = "buttons.paste_rules"; + public static final String UPDATE_RULES = "buttons.update_rules"; + public static final String CREATE_NEW_SUPPORT_TICKET = "buttons.create_new_support_ticket"; + public static final String CLOSE_SUPPORT_TICKET = "buttons.close_support_ticket"; + public static final String CLAIM_SUPPORT_TICKET = "buttons.claim_support_ticket"; + public static final String SETTINGS_SUPPORT_TICKET = "buttons.settings_support_ticket"; + + public static final String CREATE_NEW_UNBAN_TICKET = "buttons.create_new_unban_ticket"; + public static final String ACCEPT_UNBAN_TICKET = "buttons.accept_unban_ticket"; + public static final String DISMISS_UNBAN_TICKET = "buttons.dismiss_unban_ticket"; + public static final String SETTINGS_UNBAN_TICKET = "buttons.settings_unban_ticket"; + + public static final String ACCEPT_NOTICE_OF_DEPARTURE_TICKET = "buttons.accept_notice_of_departure_ticket"; + public static final String DISMISS_NOTICE_OF_DEPARTURE_TICKET = "buttons.dismiss_notice_of_departure_ticket"; + public static final String REVOKE_NOTICE_OF_DEPARTURE = "buttons.revoke_notice_of_departure"; + public static final String DELETE_NOTICE_OF_DEPARTURE = "buttons.delete_notice_of_departure"; } } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 3ff69b84..d6e4e5a8 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -209,4 +209,22 @@ notice_of_departure: notice_deleted_ended_replace_message: "The notice was deleted" +# You can't use color codes for the following button translations buttons: + paste_rules: "Paste Rules" + update_rules: "Update Rules" + + create_new_support_ticket: "Create Support Ticket" + close_support_ticket: "Close Ticket" + claim_support_ticket: "Claim Ticket" + settings_support_ticket: "Settings" + + create_new_unban_ticket: "File Unban Request" + accept_unban_ticket: "Accept Ticket" + dismiss_unban_ticket: "Dismiss Ticket" + settings_unban_ticket: "Settings" + + accept_notice_of_departure_ticket: "Accept Ticket" + dismiss_notice_of_departure_ticket: "Dismiss Ticket" + revoke_notice_of_departure: "Revoke Notice of Departure" + delete_notice_of_departure: "Delete Processed Notice of Departure" \ No newline at end of file From 79353f52dc013002db2583c8711433b3f80835f6 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 26 Oct 2024 17:17:00 +0200 Subject: [PATCH 064/845] Added robust logging to the CheckNoticeOfDeparture class --- .../java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java | 5 +++++ src/main/resources/logback.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index ceb1a727..f4a80af6 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -29,14 +29,19 @@ public class CheckNoticeOfDeparture { public static Runnable runNoticeOfDepartureCheck(JDA api) { return () -> { + logger.info("Checking notice of departures..."); SqliteManager sqliteManager = ScpTools.getSqliteManager(); try { for (NoticeOfDeparture notice : sqliteManager.getEveryNoticeOfDeparture()) { + String status = ColorTool.apply(DCColor.GREEN, "CLEAN"); String[] startTimes = notice.end_time().split("\\."); LocalDate end_date = LocalDate.of(Integer.parseInt(startTimes[2]), Integer.parseInt(startTimes[1]), Integer.parseInt(startTimes[0])); LocalDate now = LocalDate.now(); + if (now.isEqual(end_date) || now.isAfter(end_date)) {status = ColorTool.apply(DCColor.RED, "INVALID");} + logger.info("Checking notice of departure with Id: {} Status: {}", ColorTool.apply(DCColor.GREEN, notice.id()), status); + if (now.isEqual(end_date) || now.isAfter(end_date)) { api.awaitReady().retrieveUserById(notice.id()).queue(user -> { logger.info(ColorTool.useCustomColorCodes("&reset&&gold&----------------------- &reset&&red&AUTOMATIC DETECTION UNIT&reset&&gold& ----------------------&reset&")); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 8cc54a94..f62ac1f7 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -2,7 +2,7 @@ - %d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n + %d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-25.-25logger{0}) %highlight(%-6level) %msg%n From cf60c4d92507ed6a851a76ad95b59fd08e92195d Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 26 Oct 2024 19:22:44 +0200 Subject: [PATCH 065/845] Fixed issue #3 --- build.gradle.kts | 2 +- .../bot/commands/templates/TemplateCommand.java | 4 ++-- .../noticeOfDeparture/NoticeOfDeparture.java | 4 +++- .../bot/commands/templates/support/Support.java | 4 ++-- .../vxrp/bot/events/modals/NoticeOfDeparture.java | 4 ++-- .../java/dev/vxrp/bot/events/modals/Support.java | 6 ++---- src/main/java/dev/vxrp/bot/events/modals/Unban.java | 4 ++-- .../vxrp/bot/runnables/CheckNoticeOfDeparture.java | 4 ++-- .../util/configuration/LoadedConfigurations.java | 13 ++++++------- .../bot/util/configuration/groups/ButtonGroup.java | 8 ++++++++ .../bot/util/configuration/groups/ButtonsGroup.java | 8 -------- .../translations/TranslationLoader.java | 5 +++-- .../bot/util/configuration/util/TRANSLATIONS.java | 1 + src/main/resources/translations/translations.yml | 1 + 14 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java delete mode 100644 src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java diff --git a/build.gradle.kts b/build.gradle.kts index 88c2ca0b..867a5c28 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { application.mainClass = "dev.vxrp.bot.ScpTools" // group = "dev.vxrp" -version= "0.2.5" +version= "0.2.6" val jdaVersion = "5.0.0-beta.24" // diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index 950e90db..e7244b6b 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -5,7 +5,7 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -16,7 +16,7 @@ public class TemplateCommand extends ListenerAdapter { private final Logger logger = LoggerFactory.getLogger(TemplateCommand.class); - private final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + private final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); @Override public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index b3acc393..5babfcf7 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -11,6 +12,7 @@ public class NoticeOfDeparture { private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); + private static final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() @@ -20,7 +22,7 @@ public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { .setColor(Color.DARK_GRAY) .build()) .addActionRow( - Button.success("file_nod", "File Notice of Departure") + Button.success("file_nod", buttons.file_notice_of_departure()) ) .queue(); } diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index df673b18..9c0cd347 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -2,7 +2,7 @@ import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; @@ -13,7 +13,7 @@ public class Support { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); - private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + private static final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index ab9fa824..791891bb 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -5,7 +5,7 @@ import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -25,7 +25,7 @@ public class NoticeOfDeparture { private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); - private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + private static final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); private static final String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); private static final String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 93ed1a45..5bb05930 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,9 +1,7 @@ package dev.vxrp.bot.events.modals; -import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; -import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; @@ -25,7 +23,7 @@ public class Support { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); - private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + private static final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); public static void createSupportTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index bc861931..1e2664b3 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,6 +1,6 @@ package dev.vxrp.bot.events.modals; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; @@ -29,7 +29,7 @@ public class Unban { private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); private static final ConfigGroup configs = LoadedConfigurations.getConfigMemoryLoad(); - private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + private static final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) { Member member = event.getMember(); diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index f4a80af6..9c1fdeb9 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -6,7 +6,7 @@ import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.objects.NoticeOfDeparture; import net.dv8tion.jda.api.EmbedBuilder; @@ -25,7 +25,7 @@ public class CheckNoticeOfDeparture { private final static Logger logger = LoggerFactory.getLogger(CheckNoticeOfDeparture.class); private static final NoticeOfDepartureGroup translations = LoadedConfigurations.getNoticeOfDepartureMemoryLoad(); - private static final ButtonsGroup buttons = LoadedConfigurations.getButtonsMemoryLoad(); + private static final ButtonGroup buttons = LoadedConfigurations.getButtonMemoryLoad(); public static Runnable runNoticeOfDepartureCheck(JDA api) { return () -> { diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java index 29b8937a..02b28f57 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java @@ -1,11 +1,10 @@ package dev.vxrp.bot.util.configuration; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; -import javax.swing.*; import java.util.HashSet; import java.util.Iterator; @@ -13,7 +12,7 @@ public class LoadedConfigurations { public static HashSet configMemoryLoad = new HashSet<>(); public static HashSet supportTranslationMemoryLoad = new HashSet<>(); public static HashSet noticeOfDepartureMemoryLoad = new HashSet<>(); - public static HashSet buttonsMemoryLoad = new HashSet<>(); + public static HashSet buttonsMemoryLoad = new HashSet<>(); public static ConfigGroup getConfigMemoryLoad() { Iterator iterator = configMemoryLoad.iterator(); @@ -54,16 +53,16 @@ public static void setNoticeOfDepartureMemoryLoad(NoticeOfDepartureGroup noticeO LoadedConfigurations.noticeOfDepartureMemoryLoad.add(noticeOfDepartureMemoryLoad); } - public static ButtonsGroup getButtonsMemoryLoad() { - Iterator iterator = buttonsMemoryLoad.iterator(); - ButtonsGroup buttonsGroup = null; + public static ButtonGroup getButtonMemoryLoad() { + Iterator iterator = buttonsMemoryLoad.iterator(); + ButtonGroup buttonsGroup = null; while (iterator.hasNext()) { buttonsGroup = iterator.next(); } return buttonsGroup; } - public static void setButtonsMemoryLoad(ButtonsGroup buttonsMemoryLoad) { + public static void setButtonsMemoryLoad(ButtonGroup buttonsMemoryLoad) { LoadedConfigurations.buttonsMemoryLoad.add(buttonsMemoryLoad); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java new file mode 100644 index 00000000..46db52ab --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java @@ -0,0 +1,8 @@ +package dev.vxrp.bot.util.configuration.groups; + +public record ButtonGroup(String paste_rules, String update_rules, String create_new_support_ticket, + String close_support_ticket, String claim_support_ticket, String settings_support_ticket, + String create_new_unban_ticket, String accept_unban_ticket, String dismiss_unban_ticket, + String settings_unban_ticket, String accept_notice_of_departure_ticket, String dismiss_notice_of_departure_ticket, + String revoke_notice_of_departure, String delete_notice_of_departure, String file_notice_of_departure) { +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java deleted file mode 100644 index 22b1c5b7..00000000 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonsGroup.java +++ /dev/null @@ -1,8 +0,0 @@ -package dev.vxrp.bot.util.configuration.groups; - -public record ButtonsGroup(String paste_rules, String update_rules, String create_new_support_ticket, - String close_support_ticket, String claim_support_ticket, String settings_support_ticket, - String create_new_unban_ticket, String accept_unban_ticket, String dismiss_unban_ticket, - String settings_unban_ticket, String accept_notice_of_departure_ticket, String dismiss_notice_of_departure_ticket, - String revoke_notice_of_departure, String delete_notice_of_departure) { -} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index ef9cb486..1c2819a8 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -2,7 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.util.configuration.groups.ButtonsGroup; +import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; @@ -73,7 +73,7 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE), translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.DELETED_ENDED_REPLACE_MESSAGE)); - ButtonsGroup buttonsGroup = new ButtonsGroup( + ButtonGroup buttonsGroup = new ButtonGroup( translationManager.getString(TRANSLATIONS.BUTTONS.PASTE_RULES), translationManager.getString(TRANSLATIONS.BUTTONS.UPDATE_RULES), translationManager.getString(TRANSLATIONS.BUTTONS.CREATE_NEW_SUPPORT_TICKET), @@ -84,6 +84,7 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.BUTTONS.ACCEPT_UNBAN_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.DISMISS_UNBAN_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.SETTINGS_UNBAN_TICKET), + translationManager.getString(TRANSLATIONS.BUTTONS.FILE_NOTICE_OF_DEPARTURE), translationManager.getString(TRANSLATIONS.BUTTONS.ACCEPT_NOTICE_OF_DEPARTURE_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.DISMISS_NOTICE_OF_DEPARTURE_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.REVOKE_NOTICE_OF_DEPARTURE), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index b88339f2..3ba199d2 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -87,6 +87,7 @@ public static final class BUTTONS { public static final String DISMISS_UNBAN_TICKET = "buttons.dismiss_unban_ticket"; public static final String SETTINGS_UNBAN_TICKET = "buttons.settings_unban_ticket"; + public static final String FILE_NOTICE_OF_DEPARTURE = "buttons.file_notice_of_departure"; public static final String ACCEPT_NOTICE_OF_DEPARTURE_TICKET = "buttons.accept_notice_of_departure_ticket"; public static final String DISMISS_NOTICE_OF_DEPARTURE_TICKET = "buttons.dismiss_notice_of_departure_ticket"; public static final String REVOKE_NOTICE_OF_DEPARTURE = "buttons.revoke_notice_of_departure"; diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index d6e4e5a8..fa055459 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -224,6 +224,7 @@ buttons: dismiss_unban_ticket: "Dismiss Ticket" settings_unban_ticket: "Settings" + file_notice_of_departure: "File Notice of Departure" accept_notice_of_departure_ticket: "Accept Ticket" dismiss_notice_of_departure_ticket: "Dismiss Ticket" revoke_notice_of_departure: "Revoke Notice of Departure" From 515483f2b1b45801f63e9f6978284bc88543a995 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sun, 27 Oct 2024 01:39:48 +0200 Subject: [PATCH 066/845] Logs now get saved to a file + added a catch for GitHub rate limit exceeds --- .../vxrp/bot/util/api/github/GitHubApi.java | 8 +++++++- .../dev/vxrp/bot/util/colors/ColorTool.java | 14 ++++++++++++++ .../RollPerSessionTriggeringPolicy.java | 18 ++++++++++++++++++ src/main/resources/logback.xml | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java diff --git a/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java b/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java index 104bc03e..6cda5725 100644 --- a/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java +++ b/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java @@ -32,7 +32,13 @@ public static void CheckForUpdatesByTags(String url) throws IOException { Response response = call.execute(); assert response.body() != null; - JsonArray tagArray = JsonParser.parseString(response.body().string()).getAsJsonArray(); + JsonArray tagArray = null; + try { + tagArray = JsonParser.parseString(response.body().string()).getAsJsonArray(); + } catch (IllegalStateException e) { + logger.error("Not able to get latest version from github, probably exceeded rate limit... skipping"); + return; + } String tag = tagArray.get(tagArray.size() -1).getAsJsonObject().get("ref").getAsString() .replace("refs/tags/v.", ""); diff --git a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java index aafd5ba4..1debf741 100644 --- a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java +++ b/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java @@ -3,8 +3,22 @@ import dev.vxrp.bot.util.Enums.DCColor; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class ColorTool { + public static final String DARK_GRAY = "\u001B[2;30m"; + public static final String RED = "\u001B[31m"; + public static final String GREEN = "\u001B[32m"; + public static final String GOLD = "\u001B[33m"; + public static final String LIGHT_BLUE = "\u001B[34m"; + public static final String PINK = "\u001B[35m"; + public static final String TEAL = "\u001B[36m"; + public static final String WHITE = "\u001B[37m"; + public static final String BOLD = "\u001B[1;2m"; + public static final String UNDERLINE = "\u001B[4;2m"; + public static final String RESET = "\u001B[0m"; + @NotNull public static String apply(DCColor color, String text) { diff --git a/src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java b/src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java new file mode 100644 index 00000000..e2d602cf --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java @@ -0,0 +1,18 @@ +package dev.vxrp.bot.util.logback; + +import ch.qos.logback.core.rolling.TriggeringPolicyBase; + +import java.io.File; + +public class RollPerSessionTriggeringPolicy extends TriggeringPolicyBase { + private static boolean doRolling = true; + + @Override + public boolean isTriggeringEvent(File activeFile, E event) { + if (doRolling) { + doRolling = false; + return true; + } + return false; + } +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f62ac1f7..b06f8a11 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,12 +1,30 @@ + + %d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-25.-25logger{0}) %highlight(%-6level) %msg%n + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} – %msg%n + + + logs/latest.log + + + logs/${time}-%i.log + 1 + 4 + + + + + \ No newline at end of file From 4aaa34add3c7dbf050fe63cfab40ccf1adcdf30a Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:48:05 +0100 Subject: [PATCH 067/845] Fixed #4 --- .../util/configuration/translations/TranslationLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 1c2819a8..68ffd7ac 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -84,11 +84,11 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.BUTTONS.ACCEPT_UNBAN_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.DISMISS_UNBAN_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.SETTINGS_UNBAN_TICKET), - translationManager.getString(TRANSLATIONS.BUTTONS.FILE_NOTICE_OF_DEPARTURE), translationManager.getString(TRANSLATIONS.BUTTONS.ACCEPT_NOTICE_OF_DEPARTURE_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.DISMISS_NOTICE_OF_DEPARTURE_TICKET), translationManager.getString(TRANSLATIONS.BUTTONS.REVOKE_NOTICE_OF_DEPARTURE), - translationManager.getString(TRANSLATIONS.BUTTONS.DELETE_NOTICE_OF_DEPARTURE)); + translationManager.getString(TRANSLATIONS.BUTTONS.DELETE_NOTICE_OF_DEPARTURE), + translationManager.getString(TRANSLATIONS.BUTTONS.FILE_NOTICE_OF_DEPARTURE)); logger.warn("Loading translations, this could take some time..."); LoadedConfigurations.setButtonsMemoryLoad(buttonsGroup); From af5923af71ef68b682de65d6a3355ebb931cd705 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:21:48 +0100 Subject: [PATCH 068/845] New config options for logging --- .../util/configuration/configs/ConfigLoader.java | 5 +++++ .../bot/util/configuration/groups/ConfigGroup.java | 14 +++++++------- .../vxrp/bot/util/configuration/util/CONFIG.java | 7 +++++++ .../dev/vxrp/bot/util/logger/LoggerManager.java | 7 +++++++ src/main/resources/configs/config.yml | 7 +++++++ 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index ca7b5285..428c7274 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -21,6 +21,11 @@ public ConfigLoader() { configManager.getString(CONFIG.ACTIVITY_CONTENT), configManager.getString(CONFIG.RULES.PASTEBIN), configManager.getString(CONFIG.RULES.EMBED_FOOTER), + configManager.getBoolean(CONFIG.LOGGING.DO_LOGGING), + configManager.getString(CONFIG.LOGGING.TICKET_CHANNEL_ID), + configManager.getString(CONFIG.LOGGING.NOTICE_OF_DEPARTURE_CHANNEL_ID), + configManager.getBoolean(CONFIG.LOGGING.DO_DATABASE_LOGGING), + configManager.getString(CONFIG.LOGGING.DATABASE_CHANNEL_ID), configManager.getStringList(CONFIG.COMMANDS), configManager.getStringList(CONFIG.COMMAND_SETTINGS.DEFAULT_PERMISSIONS.HELP), configManager.getString(CONFIG.COMMAND_SETTINGS.DESCRIPTIONS.HELP), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java index d6750e1c..610b05cf 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java @@ -3,10 +3,10 @@ import java.util.List; public record ConfigGroup(String token, String guild_id, String activity_type, String activity_content, - String rules_pastebin, String rules_embed_footer, List commands, List command_setting_help_default_permissions, - String command_settings_help_description, List command_settings_template_default_permissions, String command_settings_template_descriptions, - List support_settings_roles_access_support_tickets, List support_settings_roles_access_unban_tickets, String support_settings_unban_channel_id, - String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, List notice_of_departure_roles_access_notices, - boolean notice_of_departure_check_on_startup, String notice_of_departure_check_type, int notice_of_departure_check_rate, boolean cedmod_active, - String cedmod_instance_url, String cedmod_api_key, String cedmod_master_banlist_id) { -} + String rules_pastebin, String rules_embed_footer, boolean do_logging, String ticket_logging_channel_id, + String notice_of_departures_logging_channel_id, boolean do_database_logging, String database_logging_channel_id, List commands, + List command_setting_help_default_permissions, String command_settings_help_description, List command_settings_template_default_permissions, + String command_settings_template_descriptions, List support_settings_roles_access_support_tickets, List support_settings_roles_access_unban_tickets, + String support_settings_unban_channel_id, String notice_of_departure_decision_channel_id, String notice_of_departure_notice_channel_id, + List notice_of_departure_roles_access_notices, boolean notice_of_departure_check_on_startup, String notice_of_departure_check_type, + int notice_of_departure_check_rate, boolean cedmod_active, String cedmod_instance_url, String cedmod_api_key, String cedmod_master_banlist_id) { } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java index f382bc8d..6573606c 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java @@ -5,6 +5,13 @@ public class CONFIG { public static final String GUILD_ID = "guild_id"; public static final String ACTIVITY_TYPE = "activity_type"; public static final String ACTIVITY_CONTENT = "activity_content"; + public static final class LOGGING { + public static final String DO_LOGGING = "logging."; + public static final String TICKET_CHANNEL_ID = "logging."; + public static final String NOTICE_OF_DEPARTURE_CHANNEL_ID = "logging."; + public static final String DO_DATABASE_LOGGING = "logging."; + public static final String DATABASE_CHANNEL_ID = "logging."; + } public static final String COMMANDS = "commands"; public static final class RULES { public static final String PASTEBIN = "rules.pastebin"; diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java new file mode 100644 index 00000000..cf1f7f8f --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java @@ -0,0 +1,7 @@ +package dev.vxrp.bot.util.logger; + +public class LoggerManager { + public static void logTicket(String title, String message) { + + } +} diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index 442b40eb..44c4a8dc 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -16,8 +16,15 @@ rules: embed_footer: "Official Server Ruleset" logging: + # Should logging actions to channels be performed? + do_logging: true # Channel id of the ticket logging channel ticket_logging_channel_id: "" + # Channel id of notice of departure logging channel + notice_of_departures_logging_channel_id: "" + # Channel id of database logging channel. Will log all database activity to a discord channel + do_database_logging: true + database_logging_channel_id: "" # Commands that are activated by default remove to deactivate, default ["help", "template"]] commands: ["help", "template"] From 3c1e5d3b1c610e58cb666755293f4a0eea5e2683 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:59:50 +0100 Subject: [PATCH 069/845] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c00e1bee..ed3296d1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## What is ScpToolsBot -ScpToolsBot is a discord bot application written in Java for Scp Secret Laboratory discord servers. It includes support functions, cedmod api syncing, community and team management features +ScpToolsBot is a discord bot application written in Java for Scp Secret Laboratory discord servers. It includes support functions, cedmod api syncing including community and team management features If you need any more information check out the [wiki](https://github.com/Vxrpenter/SCPToolsBot/wiki) From 780879b0791037c99ed89fd2318c7ca009e464b1 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:50:27 +0100 Subject: [PATCH 070/845] New debug and tracer mode --- src/main/java/dev/vxrp/bot/ScpTools.java | 28 +++++++++++++------ .../configuration/configs/ConfigLoader.java | 3 +- .../configuration/groups/ConfigGroup.java | 2 +- .../translations/TranslationLoader.java | 3 +- .../bot/util/configuration/util/CONFIG.java | 3 +- src/main/resources/configs/config.yml | 8 ++++-- src/main/resources/logback.xml | 2 +- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 190ad5ab..1a480e93 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -1,5 +1,10 @@ package dev.vxrp.bot; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.classic.spi.LoggingEvent; +import ch.qos.logback.core.Appender; import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.events.ButtonListener; import dev.vxrp.bot.commands.CommandManager; @@ -47,6 +52,7 @@ public static void main(String[] args) throws IOException { initializeConfigs(); initializeSqlite(); + setLoggingLevel(); loadConfigs(); Activity.ActivityType activityType = Activity.ActivityType.valueOf(configManager.getString(CONFIG.ACTIVITY_TYPE)); @@ -54,7 +60,6 @@ public static void main(String[] args) throws IOException { String activityContent = configManager.getString(CONFIG.ACTIVITY_CONTENT); logger.info("ActivityContent set to {}", ColorTool.apply(DCColor.RED, activityContent)); - checkGuildID(); JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT) .setActivity(Activity.of(activityType, activityContent)) .disableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOJI, CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS) @@ -67,6 +72,16 @@ public static void main(String[] args) throws IOException { noticeOfDepartureCheckups(api); } + private static void setLoggingLevel() { + Level level = Level.INFO; + if (configManager.getBoolean(CONFIG.DEBUG)) {level = Level.DEBUG;} + if (configManager.getBoolean(CONFIG.ADVANCED_DEBUG)) {level = Level.TRACE;} + + final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + final ch.qos.logback.classic.Logger log = loggerContext.exists(org.slf4j.Logger.ROOT_LOGGER_NAME); + log.setLevel(level); + } + private static void initializeSqlite() { Path path = Paths.get(".").toAbsolutePath().normalize(); File file = new File(path+"\\sqlite\\data.db"); @@ -103,24 +118,19 @@ private static void initializeConfigs() { configManager = new ConfigManager(); } catch (Exception e) { logger.error("Could not load configs from configManager : {}", e.getMessage()); + System.exit(1); } try { translationManager = new TranslationManager(); } catch (Exception e) { logger.error("Could not load configs from translationManager : {}", e.getMessage()); + System.exit(1); } try { colorConfigManager = new ColorConfigManager(); } catch (Exception e) { logger.error("Could not load configs from colorConfigManager : {}", e.getMessage()); - } - } - - private static void checkGuildID() { - if (configManager.getString("guild_id") == null || Objects.equals(configManager.getString("guild_id"), "")) { - logger.error("Guild id is {}. Invalid but moving on", ColorTool.apply(DCColor.RED, "null")); - } else { - logger.info("Launching under guild id {}", ColorTool.apply(DCColor.GREEN, configManager.getString("guild_id"))); + System.exit(1); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 428c7274..54a28fb9 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -16,7 +16,8 @@ public ConfigLoader() { ConfigGroup configGroup = new ConfigGroup( configManager.getString(CONFIG.TOKEN), - configManager.getString(CONFIG.GUILD_ID), + configManager.getBoolean(CONFIG.DEBUG), + configManager.getBoolean(CONFIG.ADVANCED_DEBUG), configManager.getString(CONFIG.ACTIVITY_TYPE), configManager.getString(CONFIG.ACTIVITY_CONTENT), configManager.getString(CONFIG.RULES.PASTEBIN), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java index 610b05cf..7f8df204 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java @@ -2,7 +2,7 @@ import java.util.List; -public record ConfigGroup(String token, String guild_id, String activity_type, String activity_content, +public record ConfigGroup(String token, boolean debug, boolean advanced_debug, String activity_type, String activity_content, String rules_pastebin, String rules_embed_footer, boolean do_logging, String ticket_logging_channel_id, String notice_of_departures_logging_channel_id, boolean do_database_logging, String database_logging_channel_id, List commands, List command_setting_help_default_permissions, String command_settings_help_description, List command_settings_template_default_permissions, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 68ffd7ac..f737eb59 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; import dev.vxrp.bot.util.configuration.LoadedConfigurations; @@ -17,7 +18,7 @@ public TranslationLoader() { TranslationManager translationManager = ScpTools.getTranslationManager(); SupportGroup supportGroup = new SupportGroup( - translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)), translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY), translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE), translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java index 6573606c..87e6dfc8 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java @@ -2,7 +2,8 @@ public class CONFIG { public static final String TOKEN = "token"; - public static final String GUILD_ID = "guild_id"; + public static final String DEBUG = "debug"; + public static final String ADVANCED_DEBUG = "advanced_debug"; public static final String ACTIVITY_TYPE = "activity_type"; public static final String ACTIVITY_CONTENT = "activity_content"; public static final class LOGGING { diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index 44c4a8dc..c60194e7 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -1,8 +1,10 @@ # The bot token get from here https://discord.com/developers/ token: "" -# The guild id. Get using developer mode in discord and then right-clicking on the server, then copy id -# \__ go to Settings > Advanced > Developer Mode -guild_id: "" + +# Should debug mode be activated? +debug: false +# Should additional debug mode be applied? +advanced_debug: true # The activity type of the bot [COMPETING, CUSTOM_STATUS, LISTENING, PLAYING, WATCHING] activity_type: "PLAYING" diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index b06f8a11..51f66993 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -23,7 +23,7 @@ - + From 12eb1536999ee78e9e311a73d8bf5e573765acad Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:37:58 +0100 Subject: [PATCH 071/845] Reverted #542ba74 commit and simplified the whole thing --- .../noticeOfDeparture/NoticeOfDeparture.java | 5 +- .../commands/templates/support/Support.java | 8 +- .../bot/events/buttons/NoticeOfDeparture.java | 31 +++--- .../dev/vxrp/bot/events/buttons/Support.java | 11 +- .../dev/vxrp/bot/events/buttons/Unban.java | 27 +++-- .../bot/events/modals/NoticeOfDeparture.java | 42 +++---- .../dev/vxrp/bot/events/modals/Support.java | 16 +-- .../dev/vxrp/bot/events/modals/Unban.java | 26 ++--- .../bot/runnables/CheckNoticeOfDeparture.java | 8 +- .../translations/TranslationLoader.java | 103 +++++++++--------- 10 files changed, 136 insertions(+), 141 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index 5babfcf7..de141a78 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,6 +1,5 @@ package dev.vxrp.bot.commands.templates.noticeOfDeparture; -import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; @@ -17,8 +16,8 @@ public class NoticeOfDeparture { public static void pasteDeRegisterTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(ColorTool.useCustomColorCodes(translations.first_title())) - .setDescription(ColorTool.useCustomColorCodes(translations.first_body())) + .setTitle(translations.first_title()) + .setDescription(translations.first_body()) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index 9c0cd347..ec63547b 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -18,15 +18,15 @@ public class Support { public static void pasteSupportTemplate(SlashCommandInteractionEvent event) { event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(ColorTool.useCustomColorCodes(translations.first_title())) - .setDescription(ColorTool.useCustomColorCodes(translations.first_body())) + .setTitle(translations.first_title()) + .setDescription(translations.first_body()) .setColor(Color.DARK_GRAY) .build()) .queue(); event.getChannel().sendMessageEmbeds(new EmbedBuilder() .setColor(Color.decode("#5865F2")) - .setTitle(ColorTool.useCustomColorCodes(translations.second_title())) - .setDescription(ColorTool.useCustomColorCodes(translations.second_body())) + .setTitle(translations.second_title()) + .setDescription(translations.second_body()) .setColor(Color.DARK_GRAY) .build()) .addActionRow( diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index b93f95c6..665d9dfb 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -1,6 +1,5 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; @@ -20,17 +19,17 @@ public class NoticeOfDeparture { public static void createNoticeOfDeparture(ButtonInteractionEvent event) { event.replyModal( - Modal.create("notice_of_departure", ColorTool.useCustomColorCodes(translations.modal_title())) + Modal.create("notice_of_departure", translations.modal_title()) .addComponents( ActionRow.of(shortModal( "nod_timeframe", - ColorTool.useCustomColorCodes(translations.modal_first_title()), - ColorTool.useCustomColorCodes(translations.modal_first_placeholder()), + translations.modal_first_title(), + translations.modal_first_placeholder(), 8,10 )), ActionRow.of(paragraphModal( - ColorTool.useCustomColorCodes(translations.modal_second_title()), - ColorTool.useCustomColorCodes(translations.modal_second_placeholder()) + translations.modal_second_title(), + translations.modal_second_placeholder() ))) .build()).queue(); } @@ -40,22 +39,22 @@ public static void acceptedNoticeOfDeparture(ButtonInteractionEvent event, User String end_time = event.getComponentId().split(":")[2]; event.replyModal( - Modal.create("reason_action_accepted_nod:"+user.getId()+":"+event.getMessageId()+":"+end_time+":"+start_time+":", ColorTool.useCustomColorCodes(reason_action.modal_reason_action_title())) + Modal.create("reason_action_accepted_nod:"+user.getId()+":"+event.getMessageId()+":"+end_time+":"+start_time+":", reason_action.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_title()), - ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_placeholder()), + reason_action.modal_reason_action_first_title(), + reason_action.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User user) { event.replyModal( - Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", ColorTool.useCustomColorCodes(reason_action.modal_reason_action_title())) + Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", reason_action.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_title()), - ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_placeholder()), + reason_action.modal_reason_action_first_title(), + reason_action.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } @@ -63,18 +62,18 @@ public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User u // Fires when notice of departure is revoked by button press. Opens up a modal to put in a reason for the user public static void revokeNoticeOfDeparture(ButtonInteractionEvent event, User user) { event.replyModal( - Modal.create("reason_action_revoke_nod:"+user.getId()+":"+event.getComponentId().split(":")[3]+":"+event.getComponentId().split(":")[2]+":", ColorTool.useCustomColorCodes( reason_action.modal_reason_action_title())) + Modal.create("reason_action_revoke_nod:"+user.getId()+":"+event.getComponentId().split(":")[3]+":"+event.getComponentId().split(":")[2]+":", reason_action.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_title()), - ColorTool.useCustomColorCodes(reason_action.modal_reason_action_first_placeholder()), + reason_action.modal_reason_action_first_title(), + reason_action.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } public static void deleteNoticeOfDeparture(ButtonInteractionEvent event) { event.getMessage().delete().queue(); - event.reply(ColorTool.useCustomColorCodes(translations.notice_deleted_ended_replace())).setEphemeral(true).queue(); + event.reply(translations.notice_deleted_ended_replace()).setEphemeral(true).queue(); } private static TextInput shortModal(String id,String title, String placeholder, int min, int max) { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 2d984f20..2eb23171 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,6 +1,5 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -21,15 +20,15 @@ public class Support { public static void createSupportTicket(ButtonInteractionEvent event) { if (event.getComponentId().equals("createNewTicket")) { event.replyModal( - Modal.create("supportTicket", ColorTool.useCustomColorCodes(translations.modal_support_title())) + Modal.create("supportTicket", translations.modal_support_title()) .addComponents( ActionRow.of(shortModal( - ColorTool.useCustomColorCodes(translations.modal_support_first_title()), - ColorTool.useCustomColorCodes(translations.modal_support_first_placeholder()) + translations.modal_support_first_title(), + translations.modal_support_first_placeholder() )), ActionRow.of(paragraphModal( - ColorTool.useCustomColorCodes(translations.modal_support_second_title()), - ColorTool.useCustomColorCodes(translations.modal_support_second_placeholder())))) + translations.modal_support_second_title(), + translations.modal_support_second_placeholder()))) .build()).queue(); } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 7f877f8d..45dde301 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,6 +1,5 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.entities.User; @@ -17,32 +16,32 @@ public class Unban { public static void createUnbanTicket(ButtonInteractionEvent event) { event.replyModal( - Modal.create("unbanTicket", ColorTool.useCustomColorCodes(translations.modal_unban_title())) + Modal.create("unbanTicket", translations.modal_unban_title()) .addComponents( ActionRow.of(shortModal( "unban_steamID", - ColorTool.useCustomColorCodes(translations.modal_unban_first_title()), - ColorTool.useCustomColorCodes(translations.modal_unban_first_placeholder()), + translations.modal_unban_first_title(), + translations.modal_unban_first_placeholder(), 17, 17)), ActionRow.of(shortModal( "unban_ban_reason", - ColorTool.useCustomColorCodes(translations.modal_unban_second_title()), - ColorTool.useCustomColorCodes(translations.modal_unban_second_placeholder()), + translations.modal_unban_second_title(), + translations.modal_unban_second_placeholder(), 5, 100)), ActionRow.of(paragraphModal( - ColorTool.useCustomColorCodes(translations.modal_unban_third_title()), - ColorTool.useCustomColorCodes(translations.modal_unban_third_placeholder())))) + translations.modal_unban_third_title(), + translations.modal_unban_third_placeholder()))) .build()).queue(); } public static void dismissTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", ColorTool.useCustomColorCodes(translations.modal_reason_action_title())) + Modal.create("reason_action_reason_dismiss:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - ColorTool.useCustomColorCodes(translations.modal_reason_action_first_title()), - ColorTool.useCustomColorCodes(translations.modal_reason_action_first_placeholder()), + translations.modal_reason_action_first_title(), + translations.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } @@ -50,11 +49,11 @@ public static void dismissTicket(ButtonInteractionEvent event, User user) { public static void acceptTicket(ButtonInteractionEvent event, User user) { String steamID = Objects.requireNonNull(event.getButton().getId()).split(":")[2]; event.replyModal( - Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", ColorTool.useCustomColorCodes(translations.modal_reason_action_title())) + Modal.create("reason_action_unban_accept:"+user.getId()+":"+steamID+":"+event.getMessageId()+":", translations.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", - ColorTool.useCustomColorCodes(translations.modal_reason_action_first_title()), - ColorTool.useCustomColorCodes(translations.modal_reason_action_first_placeholder()), + translations.modal_reason_action_first_title(), + translations.modal_reason_action_first_placeholder(), 10, 100 ))).build()).queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 791891bb..b0b04c52 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -38,7 +38,7 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { String day = new SimpleDateFormat("dd").format(Calendar.getInstance().getTime()); String month = new SimpleDateFormat("MM").format(Calendar.getInstance().getTime()); String year = new SimpleDateFormat("yyyy").format(Calendar.getInstance().getTime()); - event.reply(ColorTool.useCustomColorCodes(translations.ticket_created())).setEphemeral(true).queue(); + event.reply(translations.ticket_created()).setEphemeral(true).queue(); assert channel != null; List pingRoles = LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_roles_access_notices() @@ -49,19 +49,19 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { channel.sendMessageEmbeds( StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), new EmbedBuilder() - .setTitle(ColorTool.useCustomColorCodes(translations.ticket_title().replace("%number%", String.valueOf(ThreadLocalRandom.current().nextInt(1938, 9750))))) + .setTitle(translations.ticket_title().replace("%number%", String.valueOf(ThreadLocalRandom.current().nextInt(1938, 9750)))) .setThumbnail(Objects.requireNonNull(event.getMember()).getUser().getAvatarUrl()) - .setDescription(ColorTool.useCustomColorCodes(translations.ticket_body() + .setDescription(translations.ticket_body() .replace("%current_day%", ColorTool.apply(DCColor.BOLD, day)) .replace("%current_month%", ColorTool.apply(DCColor.BOLD, month)) .replace("%current_year%", ColorTool.apply(DCColor.BOLD, year)) .replace("%day%", ColorTool.apply(DCColor.BOLD, givenDate[0])) .replace("%month%", ColorTool.apply(DCColor.BOLD, givenDate[1])) .replace("%year%", ColorTool.apply(DCColor.BOLD, givenDate[2])) - .replace("%reason%", reason))) - .setFooter(ColorTool.useCustomColorCodes(translations.ticket_footer() + .replace("%reason%", reason)) + .setFooter(translations.ticket_footer() .replace("%date%", date) - .replace("%time%", time))) + .replace("%time%", time)) .build()) .addActionRow( Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", buttons.accept_notice_of_departure_ticket()), @@ -82,25 +82,25 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildAccepted(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.ticket_accepted() + .setDescription(translations.ticket_accepted() .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) - .replace("%reason%", reason))) + .replace("%reason%", reason)) .build() )).queue(); Objects.requireNonNull(event.getGuild().getTextChannelById(LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_notice_channel_id())).sendMessageEmbeds( StatsBuilder.buildStatus(Objects.requireNonNull(event.getMember()).getUser().getGlobalName()).build(), new EmbedBuilder() - .setTitle(ColorTool.useCustomColorCodes(translations.notice_title() - .replace("%user%", Objects.requireNonNull(user.getGlobalName())))) + .setTitle(translations.notice_title() + .replace("%user%", Objects.requireNonNull(user.getGlobalName()))) .setThumbnail(user.getAvatarUrl()) - .setDescription(ColorTool.useCustomColorCodes(translations.notice_body() + .setDescription(translations.notice_body() .replace("%user%", "<@"+event.getUser().getId()+">") .replace("%timeframe%", event.getModalId().split(":")[4]+" till " +event.getModalId().split(":")[3]) - .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString()))) - .setFooter(ColorTool.useCustomColorCodes(translations.notice_footer() + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) + .setFooter(translations.notice_footer() .replace("%date%", date) - .replace("%time%", time))) + .replace("%time%", time)) .build()) .addActionRow( Button.danger("revoke_notice_of_departure"+":"+ @@ -117,7 +117,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use throw new RuntimeException(e); } }); - event.reply(ColorTool.useCustomColorCodes(translations.ticket_message_sent())).setEphemeral(true).queue(); + event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); } public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User user) { @@ -128,25 +128,25 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.ticket_dismissed() - .replace("%reason%", reason))) + .setDescription(translations.ticket_dismissed() + .replace("%reason%", reason)) .build() )).queue(); - event.reply(ColorTool.useCustomColorCodes(translations.ticket_message_sent())).setEphemeral(true).queue(); + event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); } public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException { ScpTools.getSqliteManager().deleteNoticeOfDeparture(user.getId()); Objects.requireNonNull(event.getMessage()).delete().queue(); - event.reply(ColorTool.useCustomColorCodes(translations.notice_revoked_message())).setEphemeral(true).queue(); + event.reply(translations.notice_revoked_message()).setEphemeral(true).queue(); user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildRevoked(user.getGlobalName()).build(), new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.notice_revoked() + .setDescription(translations.notice_revoked() .replace("%timeframe%", event.getModalId().split(":")[3]+" till "+event.getModalId().split(":")[2]) - .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString()))) + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) .build() ).queue()); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 5bb05930..5bfe4786 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,10 +1,10 @@ package dev.vxrp.bot.events.modals; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; -import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -44,8 +44,8 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .addPermissionOverride(guild.getPublicRole(), null, EnumSet.of(Permission.VIEW_CHANNEL)) .setSlowmode(1) .queue(textChannel -> { - event.reply(ColorTool.useCustomColorCodes(translations.ticket_support_created() - .replace("%channel%", "<#"+textChannel.getId()+">"))).setEphemeral(true).queue(); + event.reply(translations.ticket_support_created() + .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); List roleIDs = configs.support_settings_roles_access_support_tickets(); for (String id : roleIDs) { @@ -55,13 +55,13 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .queue(); } textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); - textChannel.sendMessageEmbeds(builder(ColorTool.useCustomColorCodes(translations.ticket_support_title().replace("%name%", name)), - ColorTool.useCustomColorCodes(translations.ticket_support_body() + textChannel.sendMessageEmbeds(builder(translations.ticket_support_title().replace("%name%", name), + translations.ticket_support_body() .replace("%subject%", subject) - .replace("%body%", body)), - ColorTool.useCustomColorCodes(translations.ticket_support_footer() + .replace("%body%", body), + translations.ticket_support_footer() .replace("%date%", date) - .replace("%time%", time)), + .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( Button.danger("close_support_ticket:"+userID+":", buttons.close_support_ticket()), diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 1e2664b3..f84f7f8c 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -49,8 +49,8 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) TextChannel textChannel = event.getGuild().getTextChannelById(configs.support_settings_unban_channel_id()); assert textChannel != null; - event.reply(ColorTool.useCustomColorCodes(translations.ticket_unban_created() - .replace("%channel%", "<#"+textChannel.getId()+">"))).setEphemeral(true).queue(); + event.reply(translations.ticket_unban_created() + .replace("%channel%", "<#"+textChannel.getId()+">")).setEphemeral(true).queue(); List roleIDs = configs.support_settings_roles_access_unban_tickets(); for (String id : roleIDs) { @@ -61,14 +61,14 @@ public static void createUnbanTicket(ModalInteractionEvent event, Logger logger) } textChannel.sendMessageEmbeds( StatsBuilder.buildStatus(userName).build(), - builder(ColorTool.useCustomColorCodes(translations.ticket_unban_title().replace("%name%", name)), - ColorTool.useCustomColorCodes(translations.ticket_unban_body() + builder(translations.ticket_unban_title().replace("%name%", name), + translations.ticket_unban_body() .replace("%steamID%", steamID) .replace("%reason%", reason) - .replace("%reasoning%", reasoning)), - ColorTool.useCustomColorCodes(translations.ticket_unban_footer() + .replace("%reasoning%", reasoning), + translations.ticket_unban_footer() .replace("%date%", date) - .replace("%time%", time)), + .replace("%time%", time), event.getGuild().getIconUrl(), event.getUser()).build()) .addActionRow( Button.success("accept_unban_ticket:"+userID+":"+steamID+":", buttons.accept_unban_ticket()), @@ -96,15 +96,15 @@ public static void acceptUnban(ModalInteractionEvent event) throws IOException { bannedUser.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildAccepted(bannedUser.getGlobalName()).build(), new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.ticket_unban_message_accepted() + .setDescription(translations.ticket_unban_message_accepted() .replace("%steamID%", steamID) - .replace("%reason%", reason))) + .replace("%reason%", reason)) .build() )).queue(); CedModApi.executeUnban(instanceUrl, apiKey, banID, reason); - event.reply(ColorTool.useCustomColorCodes(translations.ticket_unban_message_sent())).setEphemeral(true).queue(); + event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); } public static void dismissUnban(ModalInteractionEvent event, User user) { String messageID = event.getModalId().split(":")[3]; @@ -117,14 +117,14 @@ public static void dismissUnban(ModalInteractionEvent event, User user) { user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds( StatsBuilder.buildDismissed(event.getUser().getGlobalName()).build(), new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(translations.ticket_unban_message_dismissed() + .setDescription(translations.ticket_unban_message_dismissed() .replace("%steamID%", steamID) - .replace("%reason%", reason))) + .replace("%reason%", reason)) .build() )).queue(); - event.reply(ColorTool.useCustomColorCodes(translations.ticket_unban_message_sent())).setEphemeral(true).queue(); + event.reply(translations.ticket_unban_message_sent()).setEphemeral(true).queue(); } private static EmbedBuilder builder(String title, String body, String footerText, String IconURL, User user) { diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 9c1fdeb9..9d7400fa 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -62,10 +62,10 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { message.editMessage(String.join("", pingRoles)).queue(); channel.sendMessage(String.join("", pingRoles)).queue(ping -> ping.delete().queue()); message.editMessageEmbeds(new EmbedBuilder() - .setDescription(ColorTool.useCustomColorCodes(ColorTool.useCustomColorCodes(translations.notice_ended_replace() + .setDescription(translations.notice_ended_replace() .replace("%user%", Objects.requireNonNull(user.getGlobalName())) .replace("%date%", now.toString()) - .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT")))) + .replace("%actionTaker%", "AUTOMATIC DETECTION UNIT")) .build()) .setActionRow( Button.danger("delete_notice_of_departure", buttons.delete_notice_of_departure()) @@ -77,8 +77,8 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { Objects.requireNonNull(user).openPrivateChannel().queue(privateChannel -> { privateChannel.sendMessageEmbeds( StatsBuilder.buildEnded(user.getGlobalName()).build(), - new EmbedBuilder().setDescription(ColorTool.useCustomColorCodes(translations.notice_ended() - .replace("%timeframe%", notice.start_time()+" till "+notice.end_time()))) + new EmbedBuilder().setDescription(translations.notice_ended() + .replace("%timeframe%", notice.start_time()+" till "+notice.end_time())) .build() ).queue(); logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index f737eb59..395e2ef1 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -19,60 +19,59 @@ public TranslationLoader() { SupportGroup supportGroup = new SupportGroup( ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_TITLE)), - translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY), - translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_FOOTER), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_CREATED), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_TITLE), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_BODY), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_FOOTER), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_CREATED), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_ACCEPTED), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED), - translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT) - ); + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.FIRST_BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.SECOND_BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_FIRST_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.SUPPORT_SECOND_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_FIRST_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_SECOND_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.UNBAN_THIRD_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.MODAL.REASON_ACTION_FIRST_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_FOOTER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.SUPPORT_CREATED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_FOOTER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_CREATED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_ACCEPTED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_DISMISSED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.SUPPORT.TICKET.UNBAN_MESSAGE_SENT))); NoticeOfDepartureGroup noticeOfDepartureGroup = new NoticeOfDepartureGroup( - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.TILE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_PLACEHOLDER), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.BODY), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.FOOTER), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.CREATED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_ACCEPTED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_DISMISSED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_SENT), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.TITLE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.BODY), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.FOOTER), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED_MESSAGE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE), - translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.DELETED_ENDED_REPLACE_MESSAGE)); + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.FIRST_BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.TILE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.FIRST_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.MODAL.SECOND_PLACEHOLDER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.FOOTER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.CREATED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_ACCEPTED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_DISMISSED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.TICKET.MESSAGE_SENT)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.TITLE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.BODY)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.NOTICE.FOOTER)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.REVOKED_MESSAGE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.DELETED_ENDED_REPLACE_MESSAGE))); ButtonGroup buttonsGroup = new ButtonGroup( translationManager.getString(TRANSLATIONS.BUTTONS.PASTE_RULES), From 471bb118eeb7dbf6d9c43a2900b6244dac138af1 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:58:29 +0100 Subject: [PATCH 072/845] New logger for the loaders --- .../configuration/configs/ConfigLoader.java | 11 ++++++++++ .../translations/TranslationLoader.java | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 54a28fb9..44f871c7 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -2,6 +2,8 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.ConfigManager; +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; @@ -47,7 +49,16 @@ public ConfigLoader() { configManager.getString(CONFIG.CEDMOD.MASTER_BAN_LIST_ID)); logger.warn("Loading configurations, this could take some time..."); + for (var component : configGroup.getClass().getRecordComponents()) { + try { + logger.trace("Added value to button translations - {}", component.getAccessor().invoke(configGroup)); + } catch (Exception e) {debuggerErrorHandler(e);} + } LoadedConfigurations.setConfigMemoryLoad(configGroup); logger.info("Loaded configurations"); } + + private static void debuggerErrorHandler(Exception e) { + logger.debug("{} Could not log the exact configuration value (this error can be ignored) - Stacktrace {}", ColorTool.apply(DCColor.RED, "ERROR") ,e.getMessage()); + } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 395e2ef1..042feec9 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -2,6 +2,7 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; @@ -91,11 +92,32 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.BUTTONS.FILE_NOTICE_OF_DEPARTURE)); logger.warn("Loading translations, this could take some time..."); + for (var component : buttonsGroup.getClass().getRecordComponents()) { + try { + logger.trace("Added value to button translations - {}", component.getAccessor().invoke(buttonsGroup)); + } catch (Exception e) {debuggerErrorHandler(e);} + } LoadedConfigurations.setButtonsMemoryLoad(buttonsGroup); logger.info("Loaded button translations"); + + for (var component : supportGroup.getClass().getRecordComponents()) { + try { + logger.trace("Added value to support translations - {}", component.getAccessor().invoke(supportGroup)); + } catch (Exception e) {debuggerErrorHandler(e);} + } LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); logger.info("Loaded support translations"); + + for (var component : noticeOfDepartureGroup.getClass().getRecordComponents()) { + try { + logger.trace("Added value to notice of departure translations - {}", component.getAccessor().invoke(noticeOfDepartureGroup)); + } catch (Exception e) {debuggerErrorHandler(e);} + } LoadedConfigurations.setNoticeOfDepartureMemoryLoad(noticeOfDepartureGroup); logger.info("Loaded notice of departure translations"); } + + private static void debuggerErrorHandler(Exception e) { + logger.debug("{} Could not log the exact translation value (this error can be ignored) - Stacktrace {}", ColorTool.apply(DCColor.RED, "ERROR") ,e.getMessage()); + } } From 5ed0483c2cc9d388ca2acca37813263d96194f92 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 31 Oct 2024 23:04:13 +0100 Subject: [PATCH 073/845] =?UTF-8?q?Made=20the=20max=20log=20files=20a=20bi?= =?UTF-8?q?t=E2=80=A6=20higher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/logback.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 51f66993..92c17276 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -18,7 +18,7 @@ logs/${time}-%i.log 1 - 4 + 10000000000000000000 From 8b1b1df578688461e38631cd0175a7474eac0e4a Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Thu, 31 Oct 2024 23:18:19 +0100 Subject: [PATCH 074/845] Reverting last joke commit here is the real changes making the logs auto compress and making the maxIndex 21 --- src/main/resources/logback.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 92c17276..a9c0127a 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -16,9 +16,9 @@ logs/latest.log - logs/${time}-%i.log + logs/${time}-%i.log.gz 1 - 10000000000000000000 + 21 From b5c0983fe37eb46fd716ee2f0501679af89c59b3 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:54:04 +0100 Subject: [PATCH 075/845] - Removed stupid error in the claiming feature of support tickets - new SQLiteManager with updated functions - new table for ticket data - ticket data now gets updated by listeners --- .idea/sqldialects.xml | 7 - src/main/java/dev/vxrp/bot/ScpTools.java | 4 +- .../sqlite/NoticeOfDepartureTableManager.java | 189 +++++++++++++++ .../bot/database/sqlite/SqliteManager.java | 221 ++++-------------- .../database/sqlite/TicketsTableManager.java | 97 ++++++++ .../dev/vxrp/bot/events/ButtonListener.java | 22 +- .../dev/vxrp/bot/events/MessageListener.java | 13 ++ .../dev/vxrp/bot/events/buttons/Support.java | 15 +- .../bot/events/modals/NoticeOfDeparture.java | 4 +- .../dev/vxrp/bot/events/modals/Support.java | 9 +- .../bot/runnables/CheckNoticeOfDeparture.java | 5 +- .../vxrp/bot/util/Enums/TicketIdentifier.java | 6 + .../translations/TranslationLoader.java | 2 + .../vxrp/bot/util/logger/LoggerManager.java | 76 +++++- src/main/resources/configs/config.yml | 2 +- .../resources/translations/translations.yml | 3 + 16 files changed, 469 insertions(+), 206 deletions(-) delete mode 100644 .idea/sqldialects.xml create mode 100644 src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java create mode 100644 src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java create mode 100644 src/main/java/dev/vxrp/bot/events/MessageListener.java create mode 100644 src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml deleted file mode 100644 index ff225d7a..00000000 --- a/.idea/sqldialects.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 1a480e93..650410cc 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -2,9 +2,6 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.classic.spi.LoggingEvent; -import ch.qos.logback.core.Appender; import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.events.ButtonListener; import dev.vxrp.bot.commands.CommandManager; @@ -13,6 +10,7 @@ import dev.vxrp.bot.config.managers.ColorConfigManager; import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.runnables.CheckNoticeOfDeparture; +import dev.vxrp.bot.util.Enums.TicketIdentifier; import dev.vxrp.bot.util.api.github.GitHubApi; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.configs.ConfigLoader; diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java new file mode 100644 index 00000000..e60422c1 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java @@ -0,0 +1,189 @@ +package dev.vxrp.bot.database.sqlite; + +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.objects.NoticeOfDeparture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public class NoticeOfDepartureTableManager { + private final Connection connection; + private final Logger logger = LoggerFactory.getLogger(NoticeOfDepartureTableManager.class); + private final String prefix = ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")); + + public NoticeOfDepartureTableManager(Connection connection) { + this.connection = connection; + } + + public void addNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { + if (exists(id)) { + logger.warn("{} - Notice of Departure already exists in Sqlite database... opting for deletion", prefix); + deleteNoticeOfDeparture(id); + } + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?,?)")) { + statement.setString(1, id); + statement.setString(2, channel_message_id); + statement.setString(3, start_time); + statement.setString(4, end_time); + statement.executeUpdate(); + logger.info("{} - Added notice of departure - id: {}, channel_message_id: {} , start_time: {} , end_time: {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GREEN, channel_message_id), + ColorTool.apply(DCColor.GOLD, start_time), + ColorTool.apply(DCColor.GOLD, end_time)); + } + } + + public void updateNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=?, end_time=? WHERE id=?")) { + statement.setString(1, start_time); + statement.setString(2, end_time); + statement.setString(3, id); + statement.executeUpdate(); + logger.info("{} - Updated notice of departure - id: {} , start_time: {} , end_time: {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, start_time), + ColorTool.apply(DCColor.GOLD, end_time)); + } + } + + public void updateChannelMessageId(String id, String channel_message_id) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure channel and message id with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { + statement.setString(1, channel_message_id); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("{} - Updated start_time - id: {} , channel_message_id: {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, channel_message_id)); + } + } + + public void updateStartTime(String id,String start_time) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure start time with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { + statement.setString(1, start_time); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("{} - Updated start_time - id: {} , start_time: {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, start_time)); + } + } + + public void updateEndTime(String id,String end_time) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to update notice of departure end time with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET end_time=? WHERE id=?")) { + statement.setString(1, end_time); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("{} - Updated end_time - id: {} , end_time: {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, end_time)); + } + } + + public void deleteNoticeOfDeparture(String id) throws SQLException { + if (!exists(id)) { + logger.error("{} - Failed to delete notice of departure with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + try (PreparedStatement statement = connection.prepareStatement("DELETE FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + statement.executeUpdate(); + logger.info("{} - Deleted notice of departure - id: {}", prefix, + ColorTool.apply(DCColor.RED, id)); + } + } + + public List getEveryNoticeOfDeparture() throws SQLException { + List noticeOfDepartureList = new ArrayList<>(); + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure")) { + try (ResultSet resultSet = statement.executeQuery()) { + while (resultSet.next()) { + noticeOfDepartureList.add(new NoticeOfDeparture( + resultSet.getString("id"), + resultSet.getString("channel_message_id").split(":")[0], + resultSet.getString("channel_message_id").split(":")[1], + resultSet.getString("start_time"), + resultSet.getString("end_time"))); + } + } + } + return noticeOfDepartureList; + } + + public NoticeOfDeparture getNoticeOfDeparture(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return new NoticeOfDeparture( + resultSet.getString("id"), + resultSet.getString("channel_message_id").split(":")[0], + resultSet.getString("channel_message_id").split(":")[1], + resultSet.getString("start_time"), + resultSet.getString("end_time")); + } + } + } + + public String getStartTime(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT start_time FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return resultSet.getString("start_time"); + } + } + } + + public String getEndTime(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT end_time FROM notice_of_departure WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return resultSet.getString("end_time"); + } + } + } + + public String getChannelMessageId(String id) throws SQLException { + try (PreparedStatement statement = connection.prepareStatement("SELECT FROM channel_message_id WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return resultSet.getString("channel_message_id"); + } + } + } + + public boolean exists(String id) { + try (PreparedStatement statement = connection.prepareStatement("SELECT EXISTS(SELECT 1 FROM notice_of_departure WHERE id=?);")) { + statement.setString(1, id); + ResultSet resultSet = statement.executeQuery(); + return resultSet.getInt(1) == 1; + } catch (SQLException e) { + logger.error(e.getMessage()); + return false; + } + } +} \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 9862c49e..645e3511 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -2,205 +2,66 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.objects.NoticeOfDeparture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.*; -import java.util.ArrayList; -import java.util.List; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; public class SqliteManager { - private final Connection connection; - private final Logger logger = LoggerFactory.getLogger(SqliteManager.class); - private final String prefix = ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")); + private final TicketsTableManager ticketsTableManager; + private final NoticeOfDepartureTableManager noticeOfDepartureTableManager; public SqliteManager(String path) throws SQLException { - connection = DriverManager.getConnection("jdbc:sqlite:"+path); + Connection connection = DriverManager.getConnection("jdbc:sqlite:" + path); + + ticketsTableManager = new TicketsTableManager(connection); + noticeOfDepartureTableManager = new NoticeOfDepartureTableManager(connection); + Logger logger = LoggerFactory.getLogger(SqliteManager.class); + String prefix = ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")); + try (Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TABLE IF NOT EXISTS tickets (" + + "id NOT NULL," + + "identifier TEXT NOT NULL," + + "creation_date TEXT NOT NULL," + + "creatorId TEXT NOT NULL," + + "handlerId TEXT," + + "PRIMARY KEY ( id, identifier ));"); + logger.info("{} - Set up table {} with rows: {}, {}, {}, {}, {}", prefix, + ColorTool.apply(DCColor.GOLD, "tickets"), + ColorTool.apply(DCColor.RED, "id"), + ColorTool.apply(DCColor.RED, "identifier"), + ColorTool.apply(DCColor.GREEN, "creation_data"), + ColorTool.apply(DCColor.GREEN, "creator"), + ColorTool.apply(DCColor.GREEN, "handler")); + } try (Statement statement = connection.createStatement()) { statement.execute( "CREATE TABLE IF NOT EXISTS notice_of_departure (" + - "id TEXT PRIMARY KEY," + - "channel_message_id TEXT NOT NULL," + - "start_time TEXT NOT NULL," + - "end_time TEXT NOT NULL" + - ");"); + "id TEXT PRIMARY KEY," + + "channel_message_id TEXT NOT NULL," + + "start_time TEXT NOT NULL," + + "end_time TEXT NOT NULL" + + ");"); logger.info("{} - Set up table {} with rows: {}, {}, {}, {}", prefix, ColorTool.apply(DCColor.GOLD, "notice_of_departure"), - ColorTool.apply(DCColor.GREEN, "id"), + ColorTool.apply(DCColor.RED, "id"), ColorTool.apply(DCColor.GREEN, "channel_message_id"), ColorTool.apply(DCColor.GREEN, "start_time"), ColorTool.apply(DCColor.GREEN, "end_time")); } + logger.info("{} - Set up Sqlite database correctly", ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite"))); } - public void addNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { - if (exists(id)) { - logger.warn("Notice of Departure already exists in Sqlite database... opting for deletion"); - deleteNoticeOfDeparture(id); - } - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?,?)")) { - statement.setString(1, id); - statement.setString(2, channel_message_id); - statement.setString(3, start_time); - statement.setString(4, end_time); - statement.executeUpdate(); - logger.info("{} - Added notice of departure - id: {}, channel_message_id: {} , start_time: {} , end_time: {}", prefix, - ColorTool.apply(DCColor.GREEN, id), - ColorTool.apply(DCColor.GREEN, channel_message_id), - ColorTool.apply(DCColor.GOLD, start_time), - ColorTool.apply(DCColor.GOLD, end_time)); - } - } - - public void updateNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { - if (!exists(id)) { - logger.error("{} - Failed to update notice of departure with id: {}. Id does not exist", prefix, - ColorTool.apply(DCColor.GREEN, id)); - return; - } - try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=?, end_time=? WHERE id=?")) { - statement.setString(1, start_time); - statement.setString(2, end_time); - statement.setString(3, id); - statement.executeUpdate(); - logger.info("{} - Updated notice of departure - id: {} , start_time: {} , end_time: {}", prefix, - ColorTool.apply(DCColor.GREEN, id), - ColorTool.apply(DCColor.GOLD, start_time), - ColorTool.apply(DCColor.GOLD, end_time)); - } - } - - public void updateChannelMessageId(String id, String channel_message_id) throws SQLException { - if (!exists(id)) { - logger.error("{} - Failed to update notice of departure channel and message id with id: {}. Id does not exist", prefix, - ColorTool.apply(DCColor.GREEN, id)); - return; - } - try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { - statement.setString(1, channel_message_id); - statement.setString(2, id); - statement.executeUpdate(); - logger.info("{} - Updated start_time - id: {} , channel_message_id: {}", prefix, - ColorTool.apply(DCColor.GREEN, id), - ColorTool.apply(DCColor.GOLD, channel_message_id)); - } - } - - public void updateStartTime(String id,String start_time) throws SQLException { - if (!exists(id)) { - logger.error("{} - Failed to update notice of departure start time with id: {}. Id does not exist", prefix, - ColorTool.apply(DCColor.GREEN, id)); - return; - } - try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET start_time=? WHERE id=?")) { - statement.setString(1, start_time); - statement.setString(2, id); - statement.executeUpdate(); - logger.info("{} - Updated start_time - id: {} , start_time: {}", prefix, - ColorTool.apply(DCColor.GREEN, id), - ColorTool.apply(DCColor.GOLD, start_time)); - } - } - - public void updateEndTime(String id,String end_time) throws SQLException { - if (!exists(id)) { - logger.error("{} - Failed to update notice of departure end time with id: {}. Id does not exist", prefix, - ColorTool.apply(DCColor.GREEN, id)); - return; - } - try (PreparedStatement statement = connection.prepareStatement("UPDATE notice_of_departure SET end_time=? WHERE id=?")) { - statement.setString(1, end_time); - statement.setString(2, id); - statement.executeUpdate(); - logger.info("{} - Updated end_time - id: {} , end_time: {}", prefix, - ColorTool.apply(DCColor.GREEN, id), - ColorTool.apply(DCColor.GOLD, end_time)); - } - } - - public void deleteNoticeOfDeparture(String id) throws SQLException { - if (!exists(id)) { - logger.error("{} - Failed to delete notice of departure with id: {}. Id does not exist", prefix, - ColorTool.apply(DCColor.GREEN, id)); - return; - } - try (PreparedStatement statement = connection.prepareStatement("DELETE FROM notice_of_departure WHERE id=?")) { - statement.setString(1, id); - statement.executeUpdate(); - logger.info("{} - Deleted notice of departure - id: {}", prefix, - ColorTool.apply(DCColor.RED, id)); - } - } - - public List getEveryNoticeOfDeparture() throws SQLException { - List noticeOfDepartureList = new ArrayList<>(); - try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure")) { - try (ResultSet resultSet = statement.executeQuery()) { - while (resultSet.next()) { - noticeOfDepartureList.add(new NoticeOfDeparture( - resultSet.getString("id"), - resultSet.getString("channel_message_id").split(":")[0], - resultSet.getString("channel_message_id").split(":")[1], - resultSet.getString("start_time"), - resultSet.getString("end_time"))); - } - } - } - return noticeOfDepartureList; - } - - public NoticeOfDeparture getNoticeOfDeparture(String id) throws SQLException { - try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure WHERE id=?")) { - statement.setString(1, id); - try (ResultSet resultSet = statement.executeQuery()) { - return new NoticeOfDeparture( - resultSet.getString("id"), - resultSet.getString("channel_message_id").split(":")[0], - resultSet.getString("channel_message_id").split(":")[1], - resultSet.getString("start_time"), - resultSet.getString("end_time")); - } - } - } - - public String getStartTime(String id) throws SQLException { - try (PreparedStatement statement = connection.prepareStatement("SELECT start_time FROM notice_of_departure WHERE id=?")) { - statement.setString(1, id); - try (ResultSet resultSet = statement.executeQuery()) { - return resultSet.getString("start_time"); - } - } - } - - public String getEndTime(String id) throws SQLException { - try (PreparedStatement statement = connection.prepareStatement("SELECT end_time FROM notice_of_departure WHERE id=?")) { - statement.setString(1, id); - try (ResultSet resultSet = statement.executeQuery()) { - return resultSet.getString("end_time"); - } - } + public TicketsTableManager getTicketsTableManager() { + return ticketsTableManager; } - - public String getChannelMessageId(String id) throws SQLException { - try (PreparedStatement statement = connection.prepareStatement("SELECT FROM channel_message_id WHERE id=?")) { - statement.setString(1, id); - try (ResultSet resultSet = statement.executeQuery()) { - return resultSet.getString("channel_message_id"); - } - } - } - - public boolean exists(String id) { - try (PreparedStatement statement = connection.prepareStatement("SELECT EXISTS(SELECT 1 FROM notice_of_departure WHERE id=?);")) { - statement.setString(1, id); - ResultSet resultSet = statement.executeQuery(); - return resultSet.getInt(1) == 1; - } catch (SQLException e) { - System.out.println(e.getMessage()); - return false; - } + public NoticeOfDepartureTableManager getNoticeOfDepartureTableManager() { + return noticeOfDepartureTableManager; } -} \ No newline at end of file +} diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java new file mode 100644 index 00000000..6dd0269f --- /dev/null +++ b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java @@ -0,0 +1,97 @@ +package dev.vxrp.bot.database.sqlite; + +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.Enums.TicketIdentifier; +import dev.vxrp.bot.util.colors.ColorTool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class TicketsTableManager { + private final Connection connection; + private final Logger logger = LoggerFactory.getLogger(TicketsTableManager.class); + private final String prefix = ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite")); + + public TicketsTableManager(Connection connection) { + this.connection = connection; + } + + public void addTicket(String id, TicketIdentifier identifier, String creation_date, String creatorId, String handlerId) throws SQLException { + if (existsId(id)) { + logger.warn("{} - Ticket already exists in Sqlite database... opting for deletion", prefix); + deleteTicket(id); + } + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO tickets VALUES (?, ?, ?, ?, ?)")) { + statement.setString(1, id); + statement.setString(2, identifier.toString()); + statement.setString(3, creation_date); + statement.setString(4, creatorId); + statement.setString(5, handlerId); + statement.executeUpdate(); + logger.info("{} - Added ticket - id: {}, identifier: {} , creation_date: {} , creatorId: {} , handlerId {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GREEN, identifier.toString()), + ColorTool.apply(DCColor.GOLD, creation_date), + ColorTool.apply(DCColor.GOLD, creatorId), + ColorTool.apply(DCColor.GOLD, handlerId)); + } + } + + public void updateHandler(String id, String handlerId) throws SQLException { + if (!existsId(id)) { + logger.error("{} - Failed to update ticket with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + + try (PreparedStatement statement = connection.prepareStatement("UPDATE tickets SET handlerId = ? WHERE id = ?")) { + statement.setString(1, handlerId); + statement.setString(2, id); + statement.executeUpdate(); + logger.info("{} - Updated handler of ticket - id: {} , handlerId: {}", prefix, + ColorTool.apply(DCColor.GREEN, id), + ColorTool.apply(DCColor.GOLD, handlerId)); + } + } + + public void deleteTicket(String id) throws SQLException { + if (!existsId(id)) { + logger.error("{} - Failed to delete ticket with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return; + } + + try (PreparedStatement statement = connection.prepareStatement("DELETE FROM ticket WHERE id=?")) { + statement.setString(1, id); + statement.execute(); + logger.info("{} - Deleted ticket - id: {}", prefix, + ColorTool.apply(DCColor.RED, id)); + } + } + + public boolean existsId(String id) { + try (PreparedStatement statement = connection.prepareStatement("SELECT EXISTS(SELECT 1 FROM tickets WHERE id=?);")) { + statement.setString(1, id); + ResultSet resultSet = statement.executeQuery(); + return resultSet.getInt(1) == 1; + } catch (SQLException e) { + logger.error(e.getMessage()); + return false; + } + } + + public boolean existsIdentifier(TicketIdentifier identifier) { + try (PreparedStatement statement = connection.prepareStatement("SELECT EXISTS(SELECT 1 FROM tickets WHERE identifier=?);")) { + statement.setString(1, identifier.toString()); + ResultSet resultSet = statement.executeQuery(); + return resultSet.getInt(1) == 1; + } catch (SQLException e) { + logger.error(e.getMessage()); + return false; + } + } +} diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index ed3c668d..39198c55 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -9,6 +9,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.SQLException; + public class ButtonListener extends ListenerAdapter { public final Logger logger = LoggerFactory.getLogger(ButtonListener.class); @@ -26,14 +28,26 @@ public void onButtonInteraction(ButtonInteractionEvent event) { Support.createSupportTicket(event); } if (event.getComponentId().startsWith("close_support_ticket")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> Support.closeTicket(event, user)); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { + try { + Support.closeTicket(event, user); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); } if (event.getComponentId().startsWith("claim_support_ticket")) { - event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> Support.claimTicket(event, user)); + event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { + try { + Support.claimTicket(event, user); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); } if (event.getComponentId().equals("settings_support_ticket")) { //WIP - event.reply("Feature currently under development").queue(); + event.reply("Feature currently under development").setEphemeral(true).queue(); } if (event.getComponentId().equals("createNewUnban")) { @@ -47,7 +61,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { } if (event.getComponentId().equals("settings_unban_ticket")) { //WIP - event.reply("Feature currently under development").queue(); + event.reply("Feature currently under development").setEphemeral(true).queue(); } //Notice of Departure diff --git a/src/main/java/dev/vxrp/bot/events/MessageListener.java b/src/main/java/dev/vxrp/bot/events/MessageListener.java new file mode 100644 index 00000000..802139f1 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/events/MessageListener.java @@ -0,0 +1,13 @@ +package dev.vxrp.bot.events; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +public class MessageListener extends ListenerAdapter { + @Override + public void onMessageReceived(MessageReceivedEvent event) { + if (event.getAuthor().isBot()) return; + + + } +} diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 2eb23171..5ef4f734 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,5 +1,7 @@ package dev.vxrp.bot.events.buttons; +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; @@ -12,6 +14,7 @@ import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; import net.dv8tion.jda.api.interactions.modals.Modal; +import java.sql.SQLException; import java.util.List; public class Support { @@ -33,7 +36,7 @@ public static void createSupportTicket(ButtonInteractionEvent event) { } } - public static void closeTicket(ButtonInteractionEvent event, User user) { + public static void closeTicket(ButtonInteractionEvent event, User user) throws SQLException { if (event.getUser() == user) { event.reply(""" ```ansi @@ -42,10 +45,11 @@ public static void closeTicket(ButtonInteractionEvent event, User user) { """).setEphemeral(true).queue(); return; } + ScpTools.getSqliteManager().getTicketsTableManager().deleteTicket(event.getChannelId()); event.getMessageChannel().delete().queue(); } - public static void claimTicket(ButtonInteractionEvent event, User user) { + public static void claimTicket(ButtonInteractionEvent event, User user) throws SQLException { if (event.getUser() == user) { event.reply(""" ```ansi @@ -60,10 +64,13 @@ public static void claimTicket(ButtonInteractionEvent event, User user) { actionRow.add(1, Button.primary("claim_support_ticket", "Claim Ticket").asDisabled()); event.getMessage().editMessage(event.getMessage().getContentRaw()).setActionRow(actionRow).queue(); + ScpTools.getSqliteManager().getTicketsTableManager().updateHandler(event.getChannelId(), event.getUser().getId()); event.replyEmbeds(new EmbedBuilder() .setDescription(""" - This Ticket has been claimed by <@808746591829229601> - """) + This Ticket has been claimed by %user% + """ + .replace("%user%", "<@"+event.getUser().getId()+">") + ) .build()).queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index b0b04c52..04c5d6a1 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -107,7 +107,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use user.getId()+":"+event.getModalId().split(":")[4]+":"+event.getModalId().split(":")[4]+":", buttons.revoke_notice_of_departure()) ).queue(message -> { try { - ScpTools.getSqliteManager().addNoticeOfDeparture( + ScpTools.getSqliteManager().getNoticeOfDepartureTableManager().addNoticeOfDeparture( user.getId(), LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_notice_channel_id()+":"+message.getId(), event.getModalId().split(":")[4], @@ -137,7 +137,7 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us } public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException { - ScpTools.getSqliteManager().deleteNoticeOfDeparture(user.getId()); + ScpTools.getSqliteManager().getNoticeOfDepartureTableManager().deleteNoticeOfDeparture(user.getId()); Objects.requireNonNull(event.getMessage()).delete().queue(); event.reply(translations.notice_revoked_message()).setEphemeral(true).queue(); user.openPrivateChannel().queue(privateChannel -> diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 5bfe4786..a915ace9 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,5 +1,7 @@ package dev.vxrp.bot.events.modals; +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.Enums.TicketIdentifier; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.groups.ButtonGroup; import dev.vxrp.bot.util.configuration.groups.ConfigGroup; @@ -16,6 +18,7 @@ import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.slf4j.Logger; +import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ThreadLocalRandom; @@ -68,8 +71,12 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge Button.primary("claim_support_ticket:"+userID+":", buttons.claim_support_ticket()), Button.secondary("settings_support_ticket", buttons.settings_support_ticket()) ).queue(); + try { + ScpTools.getSqliteManager().getTicketsTableManager().addTicket(textChannel.getId(), TicketIdentifier.SUPPORT, date, userName, null); + } catch (SQLException e) { + throw new RuntimeException(e); + } }); - logger.info("Created new support ticket by user {} - under name {}", ColorTool.apply(DCColor.GREEN, userName), ColorTool.apply(DCColor.RED, name)); } diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 9d7400fa..139932f3 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -1,6 +1,7 @@ package dev.vxrp.bot.runnables; import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.database.sqlite.NoticeOfDepartureTableManager; import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; @@ -32,7 +33,7 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { logger.info("Checking notice of departures..."); SqliteManager sqliteManager = ScpTools.getSqliteManager(); try { - for (NoticeOfDeparture notice : sqliteManager.getEveryNoticeOfDeparture()) { + for (NoticeOfDeparture notice : sqliteManager.getNoticeOfDepartureTableManager().getEveryNoticeOfDeparture()) { String status = ColorTool.apply(DCColor.GREEN, "CLEAN"); String[] startTimes = notice.end_time().split("\\."); @@ -83,7 +84,7 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { ).queue(); logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); try { - sqliteManager.deleteNoticeOfDeparture(notice.id()); + sqliteManager.getNoticeOfDepartureTableManager().deleteNoticeOfDeparture(notice.id()); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java b/src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java new file mode 100644 index 00000000..c1727d24 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java @@ -0,0 +1,6 @@ +package dev.vxrp.bot.util.Enums; + +public enum TicketIdentifier { + UNBAN, + SUPPORT +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 042feec9..151355e3 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -9,6 +9,7 @@ import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.logger.LoggerManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -91,6 +92,7 @@ public TranslationLoader() { translationManager.getString(TRANSLATIONS.BUTTONS.DELETE_NOTICE_OF_DEPARTURE), translationManager.getString(TRANSLATIONS.BUTTONS.FILE_NOTICE_OF_DEPARTURE)); + logger.warn("Loading translations, this could take some time..."); for (var component : buttonsGroup.getClass().getRecordComponents()) { try { diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java index cf1f7f8f..dbb0ea7a 100644 --- a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java +++ b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java @@ -1,7 +1,79 @@ package dev.vxrp.bot.util.logger; +import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.bot.util.colors.ColorTool; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.MessageEmbed; +import org.slf4j.event.Level; + +import java.awt.*; +import java.net.URL; +import java.util.Objects; + public class LoggerManager { - public static void logTicket(String title, String message) { - + private final JDA api; + + public LoggerManager(JDA api) { + this.api = api; + } + + public void singleMessageLog(String action, String message, String thumbnailURL, Level level, String channelID, Color color) throws InterruptedException { + MessageEmbed embed = new EmbedBuilder() + .setColor(color) + .setThumbnail(thumbnailURL) + .setDescription(""" + %action% + **Logging Level** + ```ansi + %level% + ``` + **Message** + ```ansi + %message% + ``` + """ + .replace("%action%", action) + .replace("%level%", levelConverter(level)) + .replace("%message%", message)).build(); + + Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(embed).queue(); + } + + public void multiMessageLog(String[] messages, URL ThumbnailURL, Level level, String channelID) { + + } + + public void creationLog() { + + } + + public void deletionLog() { + + } + + public void databaseLog() { + + } + + private String levelConverter(Level level) { + switch (level) { + case TRACE -> { + return ColorTool.apply(DCColor.DARK_GRAY, "TRACE"); + } + case DEBUG -> { + return ColorTool.apply(DCColor.GOLD, "DEBUG"); + } + case INFO -> { + return ColorTool.apply(DCColor.LIGHT_BLUE, "INFO"); + } + case WARN -> { + return ColorTool.apply(DCColor.PINK, "WARN"); + } + case ERROR -> { + return ColorTool.apply(DCColor.RED, "ERROR"); + } + } + return ColorTool.apply(DCColor.TEAL, level.toString()); } } diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index c60194e7..47a72b29 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -4,7 +4,7 @@ token: "" # Should debug mode be activated? debug: false # Should additional debug mode be applied? -advanced_debug: true +advanced_debug: false # The activity type of the bot [COMPETING, CUSTOM_STATUS, LISTENING, PLAYING, WATCHING] activity_type: "PLAYING" diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index fa055459..5fa89ec8 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -209,6 +209,9 @@ notice_of_departure: notice_deleted_ended_replace_message: "The notice was deleted" +logging: + + # You can't use color codes for the following button translations buttons: paste_rules: "Paste Rules" From bc0039a4179ef341098a44fd6eadc55a67dc35eb Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:13:05 +0100 Subject: [PATCH 076/845] Ticket message logging --- src/main/java/dev/vxrp/bot/ScpTools.java | 15 ++++-- .../dev/vxrp/bot/commands/CommandManager.java | 4 +- .../commands/templates/TemplateCommand.java | 2 +- .../noticeOfDeparture/NoticeOfDeparture.java | 4 +- .../templates/rules/RulesTemplateUnit.java | 4 +- .../commands/templates/support/Support.java | 5 +- .../sqlite/NoticeOfDepartureTableManager.java | 2 +- .../database/sqlite/TicketsTableManager.java | 23 ++++++++++ .../dev/vxrp/bot/events/MessageListener.java | 15 ++++++ .../bot/events/buttons/NoticeOfDeparture.java | 4 +- .../dev/vxrp/bot/events/buttons/Support.java | 3 +- .../dev/vxrp/bot/events/buttons/Unban.java | 2 +- .../dev/vxrp/bot/events/messages/Support.java | 36 +++++++++++++++ .../bot/events/modals/NoticeOfDeparture.java | 6 +-- .../dev/vxrp/bot/events/modals/Support.java | 8 ++-- .../dev/vxrp/bot/events/modals/Unban.java | 6 +-- .../bot/runnables/CheckNoticeOfDeparture.java | 7 ++- .../configuration/LoadedConfigurations.java | 19 ++++++-- .../configuration/configs/ConfigLoader.java | 2 +- .../{groups => records}/ButtonGroup.java | 2 +- .../{groups => records}/ConfigGroup.java | 2 +- .../configuration/records/LoggingGroup.java | 4 ++ .../NoticeOfDepartureGroup.java | 2 +- .../{groups => records}/SupportGroup.java | 2 +- .../translations/TranslationLoader.java | 20 ++++++-- .../util/configuration/util/TRANSLATIONS.java | 4 ++ .../vxrp/bot/util/logger/LoggerManager.java | 46 +++++++++++-------- .../NoticeOfDeparture.java | 2 +- .../dev/vxrp/bot/util/records/Ticket.java | 6 +++ .../resources/translations/translations.yml | 25 ++++++++++ 30 files changed, 212 insertions(+), 70 deletions(-) create mode 100644 src/main/java/dev/vxrp/bot/events/messages/Support.java rename src/main/java/dev/vxrp/bot/util/configuration/{groups => records}/ButtonGroup.java (92%) rename src/main/java/dev/vxrp/bot/util/configuration/{groups => records}/ConfigGroup.java (96%) create mode 100644 src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java rename src/main/java/dev/vxrp/bot/util/configuration/{groups => records}/NoticeOfDepartureGroup.java (94%) rename src/main/java/dev/vxrp/bot/util/configuration/{groups => records}/SupportGroup.java (96%) rename src/main/java/dev/vxrp/bot/util/{objects => records}/NoticeOfDeparture.java (77%) create mode 100644 src/main/java/dev/vxrp/bot/util/records/Ticket.java diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 650410cc..882ecfbb 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -9,12 +9,12 @@ import dev.vxrp.bot.commands.templates.TemplateCommand; import dev.vxrp.bot.config.managers.ColorConfigManager; import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.events.MessageListener; import dev.vxrp.bot.runnables.CheckNoticeOfDeparture; -import dev.vxrp.bot.util.Enums.TicketIdentifier; import dev.vxrp.bot.util.api.github.GitHubApi; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.configs.ConfigLoader; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import dev.vxrp.bot.config.managers.ConfigManager; import dev.vxrp.bot.events.ModalListener; @@ -58,14 +58,19 @@ public static void main(String[] args) throws IOException { String activityContent = configManager.getString(CONFIG.ACTIVITY_CONTENT); logger.info("ActivityContent set to {}", ColorTool.apply(DCColor.RED, activityContent)); - JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT) + JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS) .setActivity(Activity.of(activityType, activityContent)) .disableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOJI, CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS) + .addEventListeners( + new TemplateCommand(), + new HelpCommand(), + new ButtonListener(), + new ModalListener(), + new MessageListener()) .build(); + logger.info("Initialized Listeners"); new CommandManager().Initialize(api); - api.addEventListener(new TemplateCommand(), new HelpCommand(),new ButtonListener(), new ModalListener()); - logger.info("Initialized Listeners"); noticeOfDepartureCheckups(api); } diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index 397a3550..a82fc9be 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -1,9 +1,7 @@ package dev.vxrp.bot.commands; -import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; -import dev.vxrp.bot.util.configuration.util.CONFIG; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.converter.PermissionListConverter; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index e7244b6b..adacbe88 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -5,7 +5,7 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.buttons.Button; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index de141a78..394bbcf8 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,8 +1,8 @@ package dev.vxrp.bot.commands.templates.noticeOfDeparture; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index cf2ad61a..78f37bb5 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -1,9 +1,7 @@ package dev.vxrp.bot.commands.templates.rules; -import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; -import dev.vxrp.bot.util.configuration.util.CONFIG; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.pastebin.PastebinUtil; import dev.vxrp.bot.util.parser.CustomColorParser; import net.dv8tion.jda.api.EmbedBuilder; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index ec63547b..f181f7d3 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -1,9 +1,8 @@ package dev.vxrp.bot.commands.templates.support; -import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java index e60422c1..3ba7ee46 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java @@ -2,7 +2,7 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.objects.NoticeOfDeparture; +import dev.vxrp.bot.util.records.NoticeOfDeparture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java index 6dd0269f..d80693ce 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java @@ -3,6 +3,9 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.Enums.TicketIdentifier; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.records.NoticeOfDeparture; +import dev.vxrp.bot.util.records.Ticket; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +44,26 @@ public void addTicket(String id, TicketIdentifier identifier, String creation_da } } + public Ticket getTicket(String id) throws SQLException { + if (!existsId(id)) { + logger.error("{} - Failed to get ticket with id: {}. Id does not exist", prefix, + ColorTool.apply(DCColor.GREEN, id)); + return null; + } + + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM tickets WHERE id=?")) { + statement.setString(1, id); + try (ResultSet resultSet = statement.executeQuery()) { + return new Ticket( + resultSet.getString("id"), + TicketIdentifier.valueOf(resultSet.getString("identifier")), + resultSet.getString("creation_date"), + resultSet.getString("creatorId"), + resultSet.getString("handlerId")); + } + } + } + public void updateHandler(String id, String handlerId) throws SQLException { if (!existsId(id)) { logger.error("{} - Failed to update ticket with id: {}. Id does not exist", prefix, diff --git a/src/main/java/dev/vxrp/bot/events/MessageListener.java b/src/main/java/dev/vxrp/bot/events/MessageListener.java index 802139f1..c347f572 100644 --- a/src/main/java/dev/vxrp/bot/events/MessageListener.java +++ b/src/main/java/dev/vxrp/bot/events/MessageListener.java @@ -1,13 +1,28 @@ package dev.vxrp.bot.events; +import org.slf4j.Logger; +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.events.messages.Support; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.slf4j.LoggerFactory; + +import java.sql.SQLException; public class MessageListener extends ListenerAdapter { + private final Logger logger = LoggerFactory.getLogger(MessageListener.class); @Override public void onMessageReceived(MessageReceivedEvent event) { if (event.getAuthor().isBot()) return; + if (ScpTools.getSqliteManager().getTicketsTableManager().existsId(event.getMessage().getChannelId())) { + try { + Support.supportMessageSent(event); + } catch (SQLException | InterruptedException e) { + logger.error("Could not log messages from ticket channel {} {}", event.getChannel().getId(), e.getMessage()); + } + } + } } diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 665d9dfb..b68cfd97 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -1,8 +1,8 @@ package dev.vxrp.bot.events.buttons; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 5ef4f734..37cdd633 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,9 +1,8 @@ package dev.vxrp.bot.events.buttons; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 45dde301..1e2d4a6c 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.events.buttons; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; diff --git a/src/main/java/dev/vxrp/bot/events/messages/Support.java b/src/main/java/dev/vxrp/bot/events/messages/Support.java new file mode 100644 index 00000000..27110130 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/events/messages/Support.java @@ -0,0 +1,36 @@ +package dev.vxrp.bot.events.messages; + +import dev.vxrp.bot.ScpTools; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.logger.LoggerManager; +import dev.vxrp.bot.util.records.Ticket; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.slf4j.event.Level; + +import java.awt.*; +import java.sql.SQLException; +import java.util.Objects; + +public class Support { + public static void supportMessageSent(MessageReceivedEvent event) throws SQLException, InterruptedException { + if (event.getAuthor().isBot()) return; + if (ScpTools.getSqliteManager().getTicketsTableManager().existsId(event.getMessage().getChannelId())) { + Ticket ticket = ScpTools.getSqliteManager().getTicketsTableManager().getTicket(event.getMessage().getChannelId()); + + new LoggerManager(event.getJDA()).singleMessageLog(Objects.requireNonNull(event.getMember()).getUser(), + LoadedConfigurations.getLoggingMemoryLoad().support_message_logging_action() + .replace("%channel%", "<#"+event.getMessage().getChannelId()+">") + .replace("%user%", "<@"+event.getAuthor().getId()+">") + .replace("%type%", ticket.identifier().toString()) + .replace("%id%", ticket.id()) + .replace("%creator%", "<@"+ticket.creatorId()+">") + .replace("%handler%", "<@"+ticket.handlerId()+">").replace("<@null>", "None") + .replace("%date%", ticket.creation_date()), + event.getMessage().getContentRaw(), + Objects.requireNonNull(event.getAuthor()).getAvatarUrl(), + Level.INFO, + "1301703681414008903", + Color.ORANGE); + } + } +} diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 04c5d6a1..2f49d146 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -5,9 +5,9 @@ import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; -import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; +import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index a915ace9..8c2d902d 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -3,12 +3,12 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.TicketIdentifier; import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; @@ -72,7 +72,7 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge Button.secondary("settings_support_ticket", buttons.settings_support_ticket()) ).queue(); try { - ScpTools.getSqliteManager().getTicketsTableManager().addTicket(textChannel.getId(), TicketIdentifier.SUPPORT, date, userName, null); + ScpTools.getSqliteManager().getTicketsTableManager().addTicket(textChannel.getId(), TicketIdentifier.SUPPORT, date, userID, null); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index f84f7f8c..63666a01 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,13 +1,13 @@ package dev.vxrp.bot.events.modals; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.api.cedmod.CedModApi; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 139932f3..d658483e 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -1,15 +1,14 @@ package dev.vxrp.bot.runnables; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.database.sqlite.NoticeOfDepartureTableManager; import dev.vxrp.bot.database.sqlite.SqliteManager; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.objects.NoticeOfDeparture; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.records.NoticeOfDeparture; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java index 02b28f57..57d7ee58 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java @@ -1,9 +1,6 @@ package dev.vxrp.bot.util.configuration; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; -import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; +import dev.vxrp.bot.util.configuration.records.*; import java.util.HashSet; import java.util.Iterator; @@ -13,6 +10,7 @@ public class LoadedConfigurations { public static HashSet supportTranslationMemoryLoad = new HashSet<>(); public static HashSet noticeOfDepartureMemoryLoad = new HashSet<>(); public static HashSet buttonsMemoryLoad = new HashSet<>(); + public static HashSet loggingButtonMemoryLoad = new HashSet<>(); public static ConfigGroup getConfigMemoryLoad() { Iterator iterator = configMemoryLoad.iterator(); @@ -65,4 +63,17 @@ public static ButtonGroup getButtonMemoryLoad() { public static void setButtonsMemoryLoad(ButtonGroup buttonsMemoryLoad) { LoadedConfigurations.buttonsMemoryLoad.add(buttonsMemoryLoad); } + + public static LoggingGroup getLoggingMemoryLoad() { + Iterator iterator = loggingButtonMemoryLoad.iterator(); + LoggingGroup loggingGroup = null; + while (iterator.hasNext()) { + loggingGroup = iterator.next(); + } + return loggingGroup; + } + + public static void setLoggingMemoryLoad(LoggingGroup loggingMemoryLoad) { + LoadedConfigurations.loggingButtonMemoryLoad.add(loggingMemoryLoad); + } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 44f871c7..93dd242c 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -5,7 +5,7 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.ConfigGroup; +import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/ButtonGroup.java similarity index 92% rename from src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java rename to src/main/java/dev/vxrp/bot/util/configuration/records/ButtonGroup.java index 46db52ab..9241c28c 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ButtonGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/ButtonGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.groups; +package dev.vxrp.bot.util.configuration.records; public record ButtonGroup(String paste_rules, String update_rules, String create_new_support_ticket, String close_support_ticket, String claim_support_ticket, String settings_support_ticket, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java similarity index 96% rename from src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java rename to src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java index 7f8df204..4cfad477 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.groups; +package dev.vxrp.bot.util.configuration.records; import java.util.List; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java new file mode 100644 index 00000000..56e9a0bd --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java @@ -0,0 +1,4 @@ +package dev.vxrp.bot.util.configuration.records; + +public record LoggingGroup(String single_message_log_template, String support_message_logging_action) { +} diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/NoticeOfDepartureGroup.java similarity index 94% rename from src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java rename to src/main/java/dev/vxrp/bot/util/configuration/records/NoticeOfDepartureGroup.java index d61c2cb3..2204d3ba 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/NoticeOfDepartureGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.groups; +package dev.vxrp.bot.util.configuration.records; public record NoticeOfDepartureGroup(String first_title, String first_body, String modal_title, String modal_first_title, String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/SupportGroup.java similarity index 96% rename from src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java rename to src/main/java/dev/vxrp/bot/util/configuration/records/SupportGroup.java index b9cb0bdb..8f5f44b4 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/groups/SupportGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/SupportGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.groups; +package dev.vxrp.bot.util.configuration.records; public record SupportGroup(String first_title, String first_body, String second_title, String second_body, String modal_support_title, String modal_support_first_title, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 151355e3..a978a43e 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -4,12 +4,12 @@ import dev.vxrp.bot.config.managers.TranslationManager; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.groups.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.bot.util.configuration.records.LoggingGroup; import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.groups.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.groups.SupportGroup; -import dev.vxrp.bot.util.logger.LoggerManager; +import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.bot.util.configuration.records.SupportGroup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,6 +75,10 @@ public TranslationLoader() { ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.ENDED_REPLACE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.NOTICE_OF_DEPARTURE.DELETED_ENDED_REPLACE_MESSAGE))); + LoggingGroup loggingGroup = new LoggingGroup( + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SINGLE_MESSAGE_LOG_TEMPLATE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_MESSAGE_LOGGING_ACTION))); + ButtonGroup buttonsGroup = new ButtonGroup( translationManager.getString(TRANSLATIONS.BUTTONS.PASTE_RULES), translationManager.getString(TRANSLATIONS.BUTTONS.UPDATE_RULES), @@ -110,6 +114,14 @@ public TranslationLoader() { LoadedConfigurations.setSupportTranslationMemoryLoad(supportGroup); logger.info("Loaded support translations"); + for (var component : loggingGroup.getClass().getRecordComponents()) { + try { + logger.trace("Added value to logging translations - {}", component.getAccessor().invoke(loggingGroup)); + } catch (Exception e) {debuggerErrorHandler(e);} + } + LoadedConfigurations.setLoggingMemoryLoad(loggingGroup); + logger.info("Loaded logging translations"); + for (var component : noticeOfDepartureGroup.getClass().getRecordComponents()) { try { logger.trace("Added value to notice of departure translations - {}", component.getAccessor().invoke(noticeOfDepartureGroup)); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 3ba199d2..9db7e543 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -73,6 +73,10 @@ public static final class NOTICE { public static final String ENDED_REPLACE = "notice_of_departure.notice_ended_replace"; public static final String DELETED_ENDED_REPLACE_MESSAGE = "notice_of_departure.notice_deleted_ended_replace_message"; } + public static final class LOGGING { + public static final String SINGLE_MESSAGE_LOG_TEMPLATE = "logging.single_message_log_template"; + public static final String SUPPORT_MESSAGE_LOGGING_ACTION = "logging.support_message_logging_action"; + } public static final class BUTTONS { public static final String PASTE_RULES = "buttons.paste_rules"; public static final String UPDATE_RULES = "buttons.update_rules"; diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java index dbb0ea7a..98653b38 100644 --- a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java +++ b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java @@ -2,9 +2,13 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.User; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.slf4j.event.Level; import java.awt.*; @@ -12,32 +16,36 @@ import java.util.Objects; public class LoggerManager { + private final String filler = "\u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E \u200E"; + private final static Logger logger = LoggerFactory.getLogger(LoggerManager.class); private final JDA api; public LoggerManager(JDA api) { this.api = api; } - public void singleMessageLog(String action, String message, String thumbnailURL, Level level, String channelID, Color color) throws InterruptedException { - MessageEmbed embed = new EmbedBuilder() - .setColor(color) - .setThumbnail(thumbnailURL) - .setDescription(""" - %action% - **Logging Level** - ```ansi - %level% - ``` - **Message** - ```ansi - %message% - ``` - """ - .replace("%action%", action) - .replace("%level%", levelConverter(level)) - .replace("%message%", message)).build(); + public void singleMessageLog(User user, String action, String message, String thumbnailURL, Level level, String channelID, Color color) throws InterruptedException { + try { + MessageEmbed info = new EmbedBuilder() + .setColor(color) + .setAuthor(user.getName(), null, thumbnailURL) + .setDescription(LoadedConfigurations.getLoggingMemoryLoad().single_message_log_template() + .replace("%action%", action.replace("%filler%", filler)) + .replace("%level%", levelConverter(level)) + .replace("%message%", message.strip())).build(); - Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(embed).queue(); + Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); + } catch (IllegalArgumentException e) { + MessageEmbed info = new EmbedBuilder() + .setColor(color) + .setAuthor(user.getName(), null, thumbnailURL) + .setDescription(LoadedConfigurations.getLoggingMemoryLoad().single_message_log_template() + .replace("%action%", action.replace("%filler%", filler)) + .replace("%level%", levelConverter(level)) + .replace("%message%", "")).build(); + logger.warn("Could not correctly print out message log because of too many characters opting for empty embed"); + Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info, new EmbedBuilder().setColor(color).setDescription(message).build()).queue(); + } } public void multiMessageLog(String[] messages, URL ThumbnailURL, Level level, String channelID) { diff --git a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/util/records/NoticeOfDeparture.java similarity index 77% rename from src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java rename to src/main/java/dev/vxrp/bot/util/records/NoticeOfDeparture.java index 2757c942..6a1e3c8d 100644 --- a/src/main/java/dev/vxrp/bot/util/objects/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/util/records/NoticeOfDeparture.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.objects; +package dev.vxrp.bot.util.records; public record NoticeOfDeparture(String id,String channel_id, String message_id, String start_time, String end_time) { } diff --git a/src/main/java/dev/vxrp/bot/util/records/Ticket.java b/src/main/java/dev/vxrp/bot/util/records/Ticket.java new file mode 100644 index 00000000..a60adb85 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/util/records/Ticket.java @@ -0,0 +1,6 @@ +package dev.vxrp.bot.util.records; + +import dev.vxrp.bot.util.Enums.TicketIdentifier; + +public record Ticket(String id, TicketIdentifier identifier, String creation_date, String creatorId, String handlerId) { +} diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 5fa89ec8..30e906aa 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -210,7 +210,32 @@ notice_of_departure: notice_deleted_ended_replace_message: "The notice was deleted" logging: + single_message_log_template: " + %action%\n + + **Logging Level**\n + ```ansi + + %level% + ``` + + **Message**\n + ```ansi + + %message% + ``` + " + support_message_logging_action: " + ✏️ Send message in channel %channel% by user %user%\n + %filler% + Ticket Type - **%type%**\n + Ticket Id - **%id%**\n + Creator - **%creator%**\n + Handler - **%handler%**\n + + *Ticket created - **%date%*** + " # You can't use color codes for the following button translations buttons: From ece3057522d361ca5947b5f26e1e479cbaa714da Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:08:52 +0100 Subject: [PATCH 077/845] Ticket closed logging --- .../database/sqlite/TicketsTableManager.java | 2 +- .../dev/vxrp/bot/events/ButtonListener.java | 2 +- .../dev/vxrp/bot/events/MessageListener.java | 2 ++ .../dev/vxrp/bot/events/buttons/Support.java | 26 ++++++++++++++++++- .../dev/vxrp/bot/events/messages/Support.java | 2 +- .../configuration/configs/ConfigLoader.java | 1 + .../configuration/records/ConfigGroup.java | 2 +- .../configuration/records/LoggingGroup.java | 2 +- .../translations/TranslationLoader.java | 4 ++- .../bot/util/configuration/util/CONFIG.java | 11 ++++---- .../util/configuration/util/TRANSLATIONS.java | 2 ++ .../vxrp/bot/util/logger/LoggerManager.java | 26 ++++++++++++++----- src/main/resources/configs/config.yml | 2 ++ .../resources/translations/translations.yml | 21 +++++++++++++++ 14 files changed, 87 insertions(+), 18 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java index d80693ce..d869a58b 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java @@ -88,7 +88,7 @@ public void deleteTicket(String id) throws SQLException { return; } - try (PreparedStatement statement = connection.prepareStatement("DELETE FROM ticket WHERE id=?")) { + try (PreparedStatement statement = connection.prepareStatement("DELETE FROM tickets WHERE id=?")) { statement.setString(1, id); statement.execute(); logger.info("{} - Deleted ticket - id: {}", prefix, diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 39198c55..2bed02e6 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -31,7 +31,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { try { Support.closeTicket(event, user); - } catch (SQLException e) { + } catch (SQLException | InterruptedException e) { throw new RuntimeException(e); } }); diff --git a/src/main/java/dev/vxrp/bot/events/MessageListener.java b/src/main/java/dev/vxrp/bot/events/MessageListener.java index c347f572..c3c4f2a3 100644 --- a/src/main/java/dev/vxrp/bot/events/MessageListener.java +++ b/src/main/java/dev/vxrp/bot/events/MessageListener.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.events; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; import org.slf4j.Logger; import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.events.messages.Support; @@ -14,6 +15,7 @@ public class MessageListener extends ListenerAdapter { @Override public void onMessageReceived(MessageReceivedEvent event) { if (event.getAuthor().isBot()) return; + if (!LoadedConfigurations.getConfigMemoryLoad().do_logging()) return; if (ScpTools.getSqliteManager().getTicketsTableManager().existsId(event.getMessage().getChannelId())) { try { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 37cdd633..4e90f477 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -3,7 +3,11 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.bot.util.logger.LoggerManager; +import dev.vxrp.bot.util.records.Ticket; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; @@ -12,11 +16,17 @@ import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; import net.dv8tion.jda.api.interactions.modals.Modal; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.event.Level; +import java.awt.*; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class Support { + private final static Logger logger = LoggerFactory.getLogger(Support.class); private static final SupportGroup translations = LoadedConfigurations.getSupportTranslationMemoryLoad(); public static void createSupportTicket(ButtonInteractionEvent event) { @@ -35,7 +45,7 @@ public static void createSupportTicket(ButtonInteractionEvent event) { } } - public static void closeTicket(ButtonInteractionEvent event, User user) throws SQLException { + public static void closeTicket(ButtonInteractionEvent event, User user) throws SQLException, InterruptedException { if (event.getUser() == user) { event.reply(""" ```ansi @@ -44,6 +54,20 @@ public static void closeTicket(ButtonInteractionEvent event, User user) throws S """).setEphemeral(true).queue(); return; } + + Ticket ticket = ScpTools.getSqliteManager().getTicketsTableManager().getTicket(event.getMessage().getChannelId()); + new LoggerManager(event.getJDA()).closeLog( + LoadedConfigurations.getLoggingMemoryLoad().support_ticket_close_logging_action() + .replace("%id%", ticket.id()) + .replace("%user%", "<@"+event.getUser().getId()+">") + .replace("%type%", ticket.identifier().toString()) + .replace("%creator%", "<@"+ticket.creatorId()+">") + .replace("%handler%", "<@"+ticket.handlerId()+">").replace("<@null>", "None") + .replace("%state%", "OPEN") + .replace("%date%", ticket.creation_date()), + Level.INFO, + LoadedConfigurations.getConfigMemoryLoad().ticket_logging_channel_id(), Color.RED); + ScpTools.getSqliteManager().getTicketsTableManager().deleteTicket(event.getChannelId()); event.getMessageChannel().delete().queue(); } diff --git a/src/main/java/dev/vxrp/bot/events/messages/Support.java b/src/main/java/dev/vxrp/bot/events/messages/Support.java index 27110130..0edaafe4 100644 --- a/src/main/java/dev/vxrp/bot/events/messages/Support.java +++ b/src/main/java/dev/vxrp/bot/events/messages/Support.java @@ -29,7 +29,7 @@ public static void supportMessageSent(MessageReceivedEvent event) throws SQLExce event.getMessage().getContentRaw(), Objects.requireNonNull(event.getAuthor()).getAvatarUrl(), Level.INFO, - "1301703681414008903", + LoadedConfigurations.getConfigMemoryLoad().ticket_logging_channel_id(), Color.ORANGE); } } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java index 93dd242c..71334a73 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java @@ -26,6 +26,7 @@ public ConfigLoader() { configManager.getString(CONFIG.RULES.EMBED_FOOTER), configManager.getBoolean(CONFIG.LOGGING.DO_LOGGING), configManager.getString(CONFIG.LOGGING.TICKET_CHANNEL_ID), + configManager.getString(CONFIG.LOGGING.TICKET_BACKUP_CHANNEL_ID), configManager.getString(CONFIG.LOGGING.NOTICE_OF_DEPARTURE_CHANNEL_ID), configManager.getBoolean(CONFIG.LOGGING.DO_DATABASE_LOGGING), configManager.getString(CONFIG.LOGGING.DATABASE_CHANNEL_ID), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java index 4cfad477..cbcc3853 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java @@ -3,7 +3,7 @@ import java.util.List; public record ConfigGroup(String token, boolean debug, boolean advanced_debug, String activity_type, String activity_content, - String rules_pastebin, String rules_embed_footer, boolean do_logging, String ticket_logging_channel_id, + String rules_pastebin, String rules_embed_footer, boolean do_logging, String ticket_logging_channel_id, String ticket_backup_logging_channel_id, String notice_of_departures_logging_channel_id, boolean do_database_logging, String database_logging_channel_id, List commands, List command_setting_help_default_permissions, String command_settings_help_description, List command_settings_template_default_permissions, String command_settings_template_descriptions, List support_settings_roles_access_support_tickets, List support_settings_roles_access_unban_tickets, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java index 56e9a0bd..5a8a1e6a 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java @@ -1,4 +1,4 @@ package dev.vxrp.bot.util.configuration.records; -public record LoggingGroup(String single_message_log_template, String support_message_logging_action) { +public record LoggingGroup(String single_message_log_template, String close_log_template, String support_message_logging_action, String support_ticket_close_logging_action) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index a978a43e..142c057f 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -77,7 +77,9 @@ public TranslationLoader() { LoggingGroup loggingGroup = new LoggingGroup( ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SINGLE_MESSAGE_LOG_TEMPLATE)), - ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_MESSAGE_LOGGING_ACTION))); + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.CLOSE_LOG_TEMPLATE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_MESSAGE_LOGGING_ACTION)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CLOSE_ACTION))); ButtonGroup buttonsGroup = new ButtonGroup( translationManager.getString(TRANSLATIONS.BUTTONS.PASTE_RULES), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java index 87e6dfc8..3cf55af6 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java @@ -7,11 +7,12 @@ public class CONFIG { public static final String ACTIVITY_TYPE = "activity_type"; public static final String ACTIVITY_CONTENT = "activity_content"; public static final class LOGGING { - public static final String DO_LOGGING = "logging."; - public static final String TICKET_CHANNEL_ID = "logging."; - public static final String NOTICE_OF_DEPARTURE_CHANNEL_ID = "logging."; - public static final String DO_DATABASE_LOGGING = "logging."; - public static final String DATABASE_CHANNEL_ID = "logging."; + public static final String DO_LOGGING = "logging.do_logging"; + public static final String TICKET_CHANNEL_ID = "logging.ticket_logging_channel_id"; + public static final String TICKET_BACKUP_CHANNEL_ID = "logging.ticket_backup_logging_channel_id"; + public static final String NOTICE_OF_DEPARTURE_CHANNEL_ID = "logging.notice_of_departures_logging_channel_id"; + public static final String DO_DATABASE_LOGGING = "logging.do_database_logging"; + public static final String DATABASE_CHANNEL_ID = "logging.database_logging_channel_id"; } public static final String COMMANDS = "commands"; public static final class RULES { diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 9db7e543..ec61caf9 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -75,7 +75,9 @@ public static final class NOTICE { } public static final class LOGGING { public static final String SINGLE_MESSAGE_LOG_TEMPLATE = "logging.single_message_log_template"; + public static final String CLOSE_LOG_TEMPLATE = "logging.close_log_template"; public static final String SUPPORT_MESSAGE_LOGGING_ACTION = "logging.support_message_logging_action"; + public static final String SUPPORT_TICKET_CLOSE_ACTION = "logging.support_ticket_close_logging_action"; } public static final class BUTTONS { public static final String PASTE_RULES = "buttons.paste_rules"; diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java index 98653b38..22a0530d 100644 --- a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java +++ b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java @@ -5,6 +5,7 @@ import dev.vxrp.bot.util.configuration.LoadedConfigurations; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; import org.slf4j.Logger; @@ -13,6 +14,7 @@ import java.awt.*; import java.net.URL; +import java.util.List; import java.util.Objects; public class LoggerManager { @@ -32,32 +34,44 @@ public void singleMessageLog(User user, String action, String message, String th .setDescription(LoadedConfigurations.getLoggingMemoryLoad().single_message_log_template() .replace("%action%", action.replace("%filler%", filler)) .replace("%level%", levelConverter(level)) - .replace("%message%", message.strip())).build(); + .replace("%message%", message.strip().replace("```", "<@CODEBLOCK>"))).build(); Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); } catch (IllegalArgumentException e) { + logger.warn("Could not correctly print out message log because of too many characters... opting for empty embed"); MessageEmbed info = new EmbedBuilder() .setColor(color) .setAuthor(user.getName(), null, thumbnailURL) .setDescription(LoadedConfigurations.getLoggingMemoryLoad().single_message_log_template() .replace("%action%", action.replace("%filler%", filler)) .replace("%level%", levelConverter(level)) - .replace("%message%", "")).build(); - logger.warn("Could not correctly print out message log because of too many characters opting for empty embed"); + .replace("%message%", ColorTool.useCustomColorCodes("&red&&bold&Too long for Embed...&reset&"))).build(); Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info, new EmbedBuilder().setColor(color).setDescription(message).build()).queue(); } } - public void multiMessageLog(String[] messages, URL ThumbnailURL, Level level, String channelID) { - + public void multiMessageLog(List messages, String action, Level level, String channelID) { + messages.forEach(message -> { + try { + singleMessageLog(message.getAuthor(), action, message.getContentRaw(), message.getAuthor().getAvatarUrl(),level, channelID, Color.CYAN); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }); } public void creationLog() { } - public void deletionLog() { + public void closeLog(String action, Level level, String channelID, Color color) throws InterruptedException { + MessageEmbed info = new EmbedBuilder() + .setColor(color) + .setDescription(LoadedConfigurations.getLoggingMemoryLoad().close_log_template() + .replace("%action%", action.replace("%filler%", filler)) + .replace("%level%", levelConverter(level))).build(); + Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); } public void databaseLog() { diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index 47a72b29..1329a7c9 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -22,6 +22,8 @@ logging: do_logging: true # Channel id of the ticket logging channel ticket_logging_channel_id: "" + # Channel id of the ticket backup logging channel + ticket_backup_logging_channel_id: "" # Channel id of notice of departure logging channel notice_of_departures_logging_channel_id: "" # Channel id of database logging channel. Will log all database activity to a discord channel diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 30e906aa..f584e787 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -225,6 +225,15 @@ logging: %message% ``` " + close_log_template: " + %action%\n + + **Logging Level**\n + ```ansi + + %level% + ``` + " support_message_logging_action: " ✏️ Send message in channel %channel% by user %user%\n @@ -234,6 +243,18 @@ logging: Creator - **%creator%**\n Handler - **%handler%**\n + *Ticket created - **%date%*** + " + support_ticket_close_logging_action: " + ❌ Ticket with id: **%id%** closed by user %user%\n + %filler% + Ticket Type - **%type%**\n + Ticket Id - **%id%**\n + Creator - **%creator%**\n + Handler - **%handler%**\n + + State before closed - **%state%**\n + *Ticket created - **%date%*** " From e34d2f969dce1f1c11472a967da17e81b0cef604 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 1 Nov 2024 19:50:25 +0100 Subject: [PATCH 078/845] Ticket created logging --- .../dev/vxrp/bot/events/buttons/Support.java | 3 +-- .../dev/vxrp/bot/events/messages/Support.java | 2 -- .../dev/vxrp/bot/events/modals/Support.java | 17 ++++++++++++- .../configuration/records/LoggingGroup.java | 3 ++- .../translations/TranslationLoader.java | 2 ++ .../util/configuration/util/TRANSLATIONS.java | 2 ++ .../vxrp/bot/util/logger/LoggerManager.java | 23 +++++++++-------- .../resources/translations/translations.yml | 25 ++++++++++--------- 8 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 4e90f477..49b6213b 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -56,7 +56,7 @@ public static void closeTicket(ButtonInteractionEvent event, User user) throws S } Ticket ticket = ScpTools.getSqliteManager().getTicketsTableManager().getTicket(event.getMessage().getChannelId()); - new LoggerManager(event.getJDA()).closeLog( + new LoggerManager(event.getJDA()).closeLog(event.getUser(), LoadedConfigurations.getLoggingMemoryLoad().support_ticket_close_logging_action() .replace("%id%", ticket.id()) .replace("%user%", "<@"+event.getUser().getId()+">") @@ -65,7 +65,6 @@ public static void closeTicket(ButtonInteractionEvent event, User user) throws S .replace("%handler%", "<@"+ticket.handlerId()+">").replace("<@null>", "None") .replace("%state%", "OPEN") .replace("%date%", ticket.creation_date()), - Level.INFO, LoadedConfigurations.getConfigMemoryLoad().ticket_logging_channel_id(), Color.RED); ScpTools.getSqliteManager().getTicketsTableManager().deleteTicket(event.getChannelId()); diff --git a/src/main/java/dev/vxrp/bot/events/messages/Support.java b/src/main/java/dev/vxrp/bot/events/messages/Support.java index 0edaafe4..9070e0e4 100644 --- a/src/main/java/dev/vxrp/bot/events/messages/Support.java +++ b/src/main/java/dev/vxrp/bot/events/messages/Support.java @@ -5,7 +5,6 @@ import dev.vxrp.bot.util.logger.LoggerManager; import dev.vxrp.bot.util.records.Ticket; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.slf4j.event.Level; import java.awt.*; import java.sql.SQLException; @@ -28,7 +27,6 @@ public static void supportMessageSent(MessageReceivedEvent event) throws SQLExce .replace("%date%", ticket.creation_date()), event.getMessage().getContentRaw(), Objects.requireNonNull(event.getAuthor()).getAvatarUrl(), - Level.INFO, LoadedConfigurations.getConfigMemoryLoad().ticket_logging_channel_id(), Color.ORANGE); } diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 8c2d902d..ee591710 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -9,6 +9,7 @@ import dev.vxrp.bot.util.builder.StatsBuilder; import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.bot.util.logger.LoggerManager; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; @@ -18,9 +19,11 @@ import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.slf4j.Logger; +import java.awt.*; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class Support { @@ -71,9 +74,21 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge Button.primary("claim_support_ticket:"+userID+":", buttons.claim_support_ticket()), Button.secondary("settings_support_ticket", buttons.settings_support_ticket()) ).queue(); + try { + new LoggerManager(event.getJDA()).creationLog(event.getUser(), + LoadedConfigurations.getLoggingMemoryLoad().support_ticket_create_logging_action() + .replace("%id%", textChannel.getId()) + .replace("%channel%", "<#"+textChannel.getId()+">") + .replace("%user%", "<@"+userID+">") + .replace("%type%", TicketIdentifier.SUPPORT.toString()) + .replace("%creator%", "<@"+userID+">") + .replace("%handler%", "None") + .replace("%date%", date), + LoadedConfigurations.getConfigMemoryLoad().ticket_logging_channel_id(), + Color.GREEN); ScpTools.getSqliteManager().getTicketsTableManager().addTicket(textChannel.getId(), TicketIdentifier.SUPPORT, date, userID, null); - } catch (SQLException e) { + } catch (SQLException | InterruptedException e) { throw new RuntimeException(e); } }); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java index 5a8a1e6a..0b087e8d 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java @@ -1,4 +1,5 @@ package dev.vxrp.bot.util.configuration.records; -public record LoggingGroup(String single_message_log_template, String close_log_template, String support_message_logging_action, String support_ticket_close_logging_action) { +public record LoggingGroup(String single_message_log_template, String create_log_template, String close_log_template, String support_message_logging_action, + String support_ticket_create_logging_action, String support_ticket_close_logging_action) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 142c057f..8c52380d 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -77,8 +77,10 @@ public TranslationLoader() { LoggingGroup loggingGroup = new LoggingGroup( ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SINGLE_MESSAGE_LOG_TEMPLATE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.CREATE_LOG_TEMPLATE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.CLOSE_LOG_TEMPLATE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_MESSAGE_LOGGING_ACTION)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CREATE_ACTION)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CLOSE_ACTION))); ButtonGroup buttonsGroup = new ButtonGroup( diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index ec61caf9..913c905e 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -75,8 +75,10 @@ public static final class NOTICE { } public static final class LOGGING { public static final String SINGLE_MESSAGE_LOG_TEMPLATE = "logging.single_message_log_template"; + public static final String CREATE_LOG_TEMPLATE = "logging.create_log_template"; public static final String CLOSE_LOG_TEMPLATE = "logging.close_log_template"; public static final String SUPPORT_MESSAGE_LOGGING_ACTION = "logging.support_message_logging_action"; + public static final String SUPPORT_TICKET_CREATE_ACTION = "logging.support_ticket_create_logging_action"; public static final String SUPPORT_TICKET_CLOSE_ACTION = "logging.support_ticket_close_logging_action"; } public static final class BUTTONS { diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java index 22a0530d..8ec9a2a5 100644 --- a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java +++ b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java @@ -13,7 +13,6 @@ import org.slf4j.event.Level; import java.awt.*; -import java.net.URL; import java.util.List; import java.util.Objects; @@ -26,14 +25,13 @@ public LoggerManager(JDA api) { this.api = api; } - public void singleMessageLog(User user, String action, String message, String thumbnailURL, Level level, String channelID, Color color) throws InterruptedException { + public void singleMessageLog(User user, String action, String message, String thumbnailURL, String channelID, Color color) throws InterruptedException { try { MessageEmbed info = new EmbedBuilder() .setColor(color) .setAuthor(user.getName(), null, thumbnailURL) .setDescription(LoadedConfigurations.getLoggingMemoryLoad().single_message_log_template() .replace("%action%", action.replace("%filler%", filler)) - .replace("%level%", levelConverter(level)) .replace("%message%", message.strip().replace("```", "<@CODEBLOCK>"))).build(); Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); @@ -44,32 +42,37 @@ public void singleMessageLog(User user, String action, String message, String th .setAuthor(user.getName(), null, thumbnailURL) .setDescription(LoadedConfigurations.getLoggingMemoryLoad().single_message_log_template() .replace("%action%", action.replace("%filler%", filler)) - .replace("%level%", levelConverter(level)) .replace("%message%", ColorTool.useCustomColorCodes("&red&&bold&Too long for Embed...&reset&"))).build(); Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info, new EmbedBuilder().setColor(color).setDescription(message).build()).queue(); } } - public void multiMessageLog(List messages, String action, Level level, String channelID) { + public void multiMessageLog(List messages, String action, String channelID) { messages.forEach(message -> { try { - singleMessageLog(message.getAuthor(), action, message.getContentRaw(), message.getAuthor().getAvatarUrl(),level, channelID, Color.CYAN); + singleMessageLog(message.getAuthor(), action, message.getContentRaw(), message.getAuthor().getAvatarUrl(), channelID, Color.CYAN); } catch (InterruptedException e) { throw new RuntimeException(e); } }); } - public void creationLog() { + public void creationLog(User user, String action, String channelID, Color color) throws InterruptedException { + MessageEmbed info = new EmbedBuilder() + .setColor(color) + .setAuthor(user.getGlobalName(), null, user.getAvatarUrl()) + .setDescription(LoadedConfigurations.getLoggingMemoryLoad().close_log_template() + .replace("%action%", action.replace("%filler%", filler))).build(); + Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); } - public void closeLog(String action, Level level, String channelID, Color color) throws InterruptedException { + public void closeLog(User user, String action, String channelID, Color color) throws InterruptedException { MessageEmbed info = new EmbedBuilder() .setColor(color) + .setAuthor(user.getGlobalName(), null, user.getAvatarUrl()) .setDescription(LoadedConfigurations.getLoggingMemoryLoad().close_log_template() - .replace("%action%", action.replace("%filler%", filler)) - .replace("%level%", levelConverter(level))).build(); + .replace("%action%", action.replace("%filler%", filler))).build(); Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); } diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index f584e787..076fd961 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -213,26 +213,17 @@ logging: single_message_log_template: " %action%\n - **Logging Level**\n - ```ansi - - %level% - ``` - **Message**\n ```ansi %message% ``` " + create_log_template: " + %action%\n + " close_log_template: " %action%\n - - **Logging Level**\n - ```ansi - - %level% - ``` " support_message_logging_action: " @@ -243,6 +234,16 @@ logging: Creator - **%creator%**\n Handler - **%handler%**\n + *Ticket created - **%date%*** + " + support_ticket_create_logging_action: " + ✅ Ticket with id: **%id%** created %channel% by user %user%\n + %filler% + Ticket Type - **%type%**\n + Ticket Id - **%id%**\n + Creator - **%creator%**\n + Handler - **%handler%**\n + *Ticket created - **%date%*** " support_ticket_close_logging_action: " From f0ff58bebb4519c6b323a7a261f8e806bfa773f0 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:23:13 +0100 Subject: [PATCH 079/845] Database logging --- src/main/java/dev/vxrp/bot/ScpTools.java | 8 +++- .../sqlite/NoticeOfDepartureTableManager.java | 29 ++++++++++-- .../bot/database/sqlite/SqliteManager.java | 19 +++++++- .../database/sqlite/TicketsTableManager.java | 45 ++++++++++++++++--- .../dev/vxrp/bot/events/ButtonListener.java | 2 +- .../dev/vxrp/bot/events/ModalListener.java | 2 +- .../dev/vxrp/bot/events/buttons/Support.java | 2 +- .../bot/events/modals/NoticeOfDeparture.java | 4 +- .../dev/vxrp/bot/events/modals/Support.java | 4 +- .../bot/runnables/CheckNoticeOfDeparture.java | 2 +- .../configuration/records/LoggingGroup.java | 2 +- .../translations/TranslationLoader.java | 1 + .../util/configuration/util/TRANSLATIONS.java | 1 + .../vxrp/bot/util/logger/LoggerManager.java | 19 +++++++- .../resources/translations/translations.yml | 13 ++++++ 15 files changed, 130 insertions(+), 23 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 882ecfbb..0c43af11 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -22,6 +22,7 @@ import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.configuration.translations.TranslationLoader; import dev.vxrp.bot.util.general.RepeatTask; +import dev.vxrp.bot.util.logger.LoggerManager; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; @@ -44,12 +45,12 @@ public class ScpTools { static TranslationManager translationManager; static ColorConfigManager colorConfigManager; static SqliteManager sqliteManager; + static LoggerManager loggerManager; public static void main(String[] args) throws IOException { GitHubApi.CheckForUpdatesByTags("https://api.github.com/repos/Vxrpenter/SCPToolsBot/git/refs/tags"); initializeConfigs(); - initializeSqlite(); setLoggingLevel(); loadConfigs(); @@ -68,6 +69,8 @@ public static void main(String[] args) throws IOException { new ModalListener(), new MessageListener()) .build(); + loggerManager = new LoggerManager(api); + initializeSqlite(); logger.info("Initialized Listeners"); new CommandManager().Initialize(api); @@ -91,7 +94,7 @@ private static void initializeSqlite() { try { file.createNewFile(); sqliteManager = new SqliteManager(path+"\\sqlite\\data.db"); - } catch (SQLException | IOException e) { + } catch (SQLException | IOException | InterruptedException e) { logger.error("Could not correctly set up Sqlite database {}", e.getMessage()); } } @@ -157,4 +160,5 @@ public static ColorConfigManager getColorConfigManager() { public static SqliteManager getSqliteManager() { return sqliteManager; } + public static LoggerManager getLoggerManager() {return loggerManager;} } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java index 3ba7ee46..2c635e8b 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java @@ -1,11 +1,14 @@ package dev.vxrp.bot.database.sqlite; +import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; import dev.vxrp.bot.util.records.NoticeOfDeparture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.awt.*; import java.sql.*; import java.util.ArrayList; import java.util.List; @@ -19,12 +22,12 @@ public NoticeOfDepartureTableManager(Connection connection) { this.connection = connection; } - public void addNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException { + public void addNoticeOfDeparture(String id, String channel_message_id, String start_time, String end_time) throws SQLException, InterruptedException { if (exists(id)) { logger.warn("{} - Notice of Departure already exists in Sqlite database... opting for deletion", prefix); deleteNoticeOfDeparture(id); } - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?,?,?,?)")) { + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO notice_of_departure VALUES (?, ?, ?, ?)")) { statement.setString(1, id); statement.setString(2, channel_message_id); statement.setString(3, start_time); @@ -35,6 +38,14 @@ public void addNoticeOfDeparture(String id, String channel_message_id, String st ColorTool.apply(DCColor.GREEN, channel_message_id), ColorTool.apply(DCColor.GOLD, start_time), ColorTool.apply(DCColor.GOLD, end_time)); + ScpTools.getLoggerManager().databaseLog( + "INSERT INTO notice_of_departure VALUES (?, ?, ?, ?)", + "Created new notice of departure with value id: "+ColorTool.apply(DCColor.GREEN, id)+ + ", channel_message_id: "+ColorTool.apply(DCColor.GREEN, channel_message_id)+ + ", start_time: "+ColorTool.apply(DCColor.GOLD, start_time)+ + ", end_time: "+ColorTool.apply(DCColor.GOLD, end_time), + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); } } @@ -104,7 +115,7 @@ public void updateEndTime(String id,String end_time) throws SQLException { } } - public void deleteNoticeOfDeparture(String id) throws SQLException { + public void deleteNoticeOfDeparture(String id) throws SQLException, InterruptedException { if (!exists(id)) { logger.error("{} - Failed to delete notice of departure with id: {}. Id does not exist", prefix, ColorTool.apply(DCColor.GREEN, id)); @@ -115,13 +126,23 @@ public void deleteNoticeOfDeparture(String id) throws SQLException { statement.executeUpdate(); logger.info("{} - Deleted notice of departure - id: {}", prefix, ColorTool.apply(DCColor.RED, id)); + ScpTools.getLoggerManager().databaseLog( + "DELETE FROM notice_of_departure WHERE id=?", + "Deleted notice of departure id: "+ColorTool.apply(DCColor.GREEN, id), + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); } } - public List getEveryNoticeOfDeparture() throws SQLException { + public List getEveryNoticeOfDeparture() throws SQLException, InterruptedException { List noticeOfDepartureList = new ArrayList<>(); try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM notice_of_departure")) { try (ResultSet resultSet = statement.executeQuery()) { + ScpTools.getLoggerManager().databaseLog( + "SELECT * FROM notice_of_departure", + "Selected every notice of departure", + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); while (resultSet.next()) { noticeOfDepartureList.add(new NoticeOfDeparture( resultSet.getString("id"), diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 645e3511..553e077f 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -1,10 +1,15 @@ package dev.vxrp.bot.database.sqlite; +import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.logger.LoggerManager; +import net.dv8tion.jda.api.JDA; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.awt.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -14,7 +19,7 @@ public class SqliteManager { private final TicketsTableManager ticketsTableManager; private final NoticeOfDepartureTableManager noticeOfDepartureTableManager; - public SqliteManager(String path) throws SQLException { + public SqliteManager(String path) throws SQLException, InterruptedException { Connection connection = DriverManager.getConnection("jdbc:sqlite:" + path); ticketsTableManager = new TicketsTableManager(connection); @@ -37,6 +42,11 @@ public SqliteManager(String path) throws SQLException { ColorTool.apply(DCColor.GREEN, "creation_data"), ColorTool.apply(DCColor.GREEN, "creator"), ColorTool.apply(DCColor.GREEN, "handler")); + ScpTools.getLoggerManager().databaseLog( + "CREATE TABLE IF NOT EXISTS tickets (id NOT NULL, identifier TEXT NOT NULL, creation_date TEXT NOT NULL, creatorId TEXT NOT NULL, handlerId TEXT, PRIMARY KEY ( id, identifier ));", + "Created Table with all rows", + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); } try (Statement statement = connection.createStatement()) { statement.execute( @@ -52,8 +62,13 @@ public SqliteManager(String path) throws SQLException { ColorTool.apply(DCColor.GREEN, "channel_message_id"), ColorTool.apply(DCColor.GREEN, "start_time"), ColorTool.apply(DCColor.GREEN, "end_time")); - } + ScpTools.getLoggerManager().databaseLog( + "CREATE TABLE IF NOT EXISTS notice_of_departure (id TEXT PRIMARY KEY, channel_message_id TEXT NOT NULL, start_time TEXT NOT NULL, end_time TEXT NOT NULL);", + "Created Table with all rows", + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); + } logger.info("{} - Set up Sqlite database correctly", ColorTool.apply(DCColor.GOLD, ColorTool.apply(DCColor.BOLD, "SQLite"))); } diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java index d869a58b..23241c18 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java @@ -1,14 +1,18 @@ package dev.vxrp.bot.database.sqlite; +import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.util.Enums.DCColor; import dev.vxrp.bot.util.Enums.TicketIdentifier; import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.bot.util.logger.LoggerManager; import dev.vxrp.bot.util.records.NoticeOfDeparture; import dev.vxrp.bot.util.records.Ticket; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.awt.*; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -23,7 +27,7 @@ public TicketsTableManager(Connection connection) { this.connection = connection; } - public void addTicket(String id, TicketIdentifier identifier, String creation_date, String creatorId, String handlerId) throws SQLException { + public void addTicket(String id, TicketIdentifier identifier, String creation_date, String creatorId, String handlerId) throws SQLException, InterruptedException { if (existsId(id)) { logger.warn("{} - Ticket already exists in Sqlite database... opting for deletion", prefix); deleteTicket(id); @@ -35,16 +39,26 @@ public void addTicket(String id, TicketIdentifier identifier, String creation_da statement.setString(4, creatorId); statement.setString(5, handlerId); statement.executeUpdate(); - logger.info("{} - Added ticket - id: {}, identifier: {} , creation_date: {} , creatorId: {} , handlerId {}", prefix, + logger.info("{} - Added ticket - id: {}, identifier: {} , creation_date: {} , creatorId: {} , handlerId: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GREEN, identifier.toString()), ColorTool.apply(DCColor.GOLD, creation_date), ColorTool.apply(DCColor.GOLD, creatorId), ColorTool.apply(DCColor.GOLD, handlerId)); + System.out.println(statement.getResultSet()); + ScpTools.getLoggerManager().databaseLog( + "INSERT INTO tickets VALUES (?, ?, ?, ?, ?)", + "Created new ticket with value id: "+ColorTool.apply(DCColor.GREEN, id)+ + ", identifier: "+ColorTool.apply(DCColor.GREEN, identifier.toString())+ + ", creation_date: "+ColorTool.apply(DCColor.GOLD, creation_date)+ + ", creatorId: "+ColorTool.apply(DCColor.GOLD, creatorId)+ + ", handlerId: "+ColorTool.apply(DCColor.GOLD, handlerId), + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); } } - public Ticket getTicket(String id) throws SQLException { + public Ticket getTicket(String id) throws SQLException, InterruptedException { if (!existsId(id)) { logger.error("{} - Failed to get ticket with id: {}. Id does not exist", prefix, ColorTool.apply(DCColor.GREEN, id)); @@ -53,7 +67,17 @@ public Ticket getTicket(String id) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM tickets WHERE id=?")) { statement.setString(1, id); + + try (ResultSet resultSet = statement.executeQuery()) { + logger.info("{} - Selected ticket with id: {}", prefix, + ColorTool.apply(DCColor.GREEN, id)); + ScpTools.getLoggerManager().databaseLog( + "SELECT * FROM tickets WHERE id=?", + "Selected ticket id: "+ColorTool.apply(DCColor.GREEN, id), + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); + return new Ticket( resultSet.getString("id"), TicketIdentifier.valueOf(resultSet.getString("identifier")), @@ -64,7 +88,7 @@ public Ticket getTicket(String id) throws SQLException { } } - public void updateHandler(String id, String handlerId) throws SQLException { + public void updateHandler(String id, String handlerId) throws SQLException, InterruptedException { if (!existsId(id)) { logger.error("{} - Failed to update ticket with id: {}. Id does not exist", prefix, ColorTool.apply(DCColor.GREEN, id)); @@ -78,10 +102,16 @@ public void updateHandler(String id, String handlerId) throws SQLException { logger.info("{} - Updated handler of ticket - id: {} , handlerId: {}", prefix, ColorTool.apply(DCColor.GREEN, id), ColorTool.apply(DCColor.GOLD, handlerId)); + ScpTools.getLoggerManager().databaseLog( + "UPDATE tickets SET handlerId = ? WHERE id = ?", + "Updated ticket handlerId with id: "+ColorTool.apply(DCColor.GREEN, id)+ + ", handlerId: "+ColorTool.apply(DCColor.GOLD, handlerId), + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); } } - public void deleteTicket(String id) throws SQLException { + public void deleteTicket(String id) throws SQLException, InterruptedException { if (!existsId(id)) { logger.error("{} - Failed to delete ticket with id: {}. Id does not exist", prefix, ColorTool.apply(DCColor.GREEN, id)); @@ -93,6 +123,11 @@ public void deleteTicket(String id) throws SQLException { statement.execute(); logger.info("{} - Deleted ticket - id: {}", prefix, ColorTool.apply(DCColor.RED, id)); + ScpTools.getLoggerManager().databaseLog( + "DELETE FROM tickets WHERE id=?", + "Deleted ticket with id: "+ColorTool.apply(DCColor.GREEN, id), + LoadedConfigurations.getConfigMemoryLoad().database_logging_channel_id(), + Color.ORANGE); } } diff --git a/src/main/java/dev/vxrp/bot/events/ButtonListener.java b/src/main/java/dev/vxrp/bot/events/ButtonListener.java index 2bed02e6..c5b4cf26 100644 --- a/src/main/java/dev/vxrp/bot/events/ButtonListener.java +++ b/src/main/java/dev/vxrp/bot/events/ButtonListener.java @@ -40,7 +40,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { event.getJDA().retrieveUserById(event.getComponentId().split(":")[1]).queue(user -> { try { Support.claimTicket(event, user); - } catch (SQLException e) { + } catch (SQLException | InterruptedException e) { throw new RuntimeException(e); } }); diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index 22ebba4d..26ec1ed8 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -47,7 +47,7 @@ public void onModalInteraction(ModalInteractionEvent event) { event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> { try { NoticeOfDeparture.revokeNoticeOfDeparture(event, user); - } catch (SQLException e) { + } catch (SQLException | InterruptedException e) { throw new RuntimeException(e); } }); diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 49b6213b..7eb5fdfb 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -71,7 +71,7 @@ public static void closeTicket(ButtonInteractionEvent event, User user) throws S event.getMessageChannel().delete().queue(); } - public static void claimTicket(ButtonInteractionEvent event, User user) throws SQLException { + public static void claimTicket(ButtonInteractionEvent event, User user) throws SQLException, InterruptedException { if (event.getUser() == user) { event.reply(""" ```ansi diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index 2f49d146..c6428d82 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -113,7 +113,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use event.getModalId().split(":")[4], event.getModalId().split(":")[3] ); - } catch (SQLException e) { + } catch (SQLException | InterruptedException e) { throw new RuntimeException(e); } }); @@ -136,7 +136,7 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); } - public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException { + public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User user) throws SQLException, InterruptedException { ScpTools.getSqliteManager().getNoticeOfDepartureTableManager().deleteNoticeOfDeparture(user.getId()); Objects.requireNonNull(event.getMessage()).delete().queue(); event.reply(translations.notice_revoked_message()).setEphemeral(true).queue(); diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index ee591710..16ca72bd 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -60,8 +60,8 @@ public static void createSupportTicket(ModalInteractionEvent event, Logger logge .grant(EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND)) .queue(); } - textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build()).queue(); - textChannel.sendMessageEmbeds(builder(translations.ticket_support_title().replace("%name%", name), + textChannel.sendMessageEmbeds(StatsBuilder.buildStatus(userName).build(), + builder(translations.ticket_support_title().replace("%name%", name), translations.ticket_support_body() .replace("%subject%", subject) .replace("%body%", body), diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index d658483e..6a65c9b4 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -84,7 +84,7 @@ public static Runnable runNoticeOfDepartureCheck(JDA api) { logger.info("Send private message about invalid notice of departure to {}", user.getGlobalName()); try { sqliteManager.getNoticeOfDepartureTableManager().deleteNoticeOfDeparture(notice.id()); - } catch (SQLException e) { + } catch (SQLException | InterruptedException e) { throw new RuntimeException(e); } logger.info(ColorTool.apply(DCColor.GOLD, "------------------------------------------------------------------------")); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java index 0b087e8d..638277c2 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java @@ -1,5 +1,5 @@ package dev.vxrp.bot.util.configuration.records; -public record LoggingGroup(String single_message_log_template, String create_log_template, String close_log_template, String support_message_logging_action, +public record LoggingGroup(String single_message_log_template, String create_log_template, String close_log_template, String database_log_template, String support_message_logging_action, String support_ticket_create_logging_action, String support_ticket_close_logging_action) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index 8c52380d..adb91e58 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -79,6 +79,7 @@ public TranslationLoader() { ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SINGLE_MESSAGE_LOG_TEMPLATE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.CREATE_LOG_TEMPLATE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.CLOSE_LOG_TEMPLATE)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.DATABASE_LOG_TEMPLATE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_MESSAGE_LOGGING_ACTION)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CREATE_ACTION)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CLOSE_ACTION))); diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 913c905e..2487e43a 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -77,6 +77,7 @@ public static final class LOGGING { public static final String SINGLE_MESSAGE_LOG_TEMPLATE = "logging.single_message_log_template"; public static final String CREATE_LOG_TEMPLATE = "logging.create_log_template"; public static final String CLOSE_LOG_TEMPLATE = "logging.close_log_template"; + public static final String DATABASE_LOG_TEMPLATE = "logging.database_log_template"; public static final String SUPPORT_MESSAGE_LOGGING_ACTION = "logging.support_message_logging_action"; public static final String SUPPORT_TICKET_CREATE_ACTION = "logging.support_ticket_create_logging_action"; public static final String SUPPORT_TICKET_CLOSE_ACTION = "logging.support_ticket_close_logging_action"; diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java index 8ec9a2a5..c8599e72 100644 --- a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java +++ b/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java @@ -13,6 +13,8 @@ import org.slf4j.event.Level; import java.awt.*; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.List; import java.util.Objects; @@ -77,8 +79,23 @@ public void closeLog(User user, String action, String channelID, Color color) th Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); } - public void databaseLog() { + public void databaseLog(String sqlStatement, String output, String channelID, Color color) throws InterruptedException { + if (!LoadedConfigurations.getConfigMemoryLoad().do_database_logging()) return; + String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime()); + String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); + MessageEmbed info = new EmbedBuilder() + .setColor(color) + .setAuthor("Database Manager", + "https://github.com/Vxrpenter/SCPToolsBot/blob/master/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java", + "https://toppng.com/uploads/preview/database-database-icon-11563207079binxarjjyp.png") + .setDescription(LoadedConfigurations.getLoggingMemoryLoad().database_log_template() + .replace("%statement%", sqlStatement) + .replace("%output%", output)) + .setFooter("Statement sent on the "+date+" at "+time+"h") + .build(); + + Objects.requireNonNull(api.awaitReady().getTextChannelById(channelID)).sendMessageEmbeds(info).queue(); } private String levelConverter(Level level) { diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index 076fd961..dd042af1 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -225,6 +225,19 @@ logging: close_log_template: " %action%\n " + database_log_template: " + **SQL Statement**\n + ```ansi + + %statement% + ``` + + **Output data**\n + ```ansi + + %output% + ``` + " support_message_logging_action: " ✏️ Send message in channel %channel% by user %user%\n From 2b7f521fdf0a1821d5bc69ebe08c6f5ae70a9301 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 2 Nov 2024 00:51:24 +0100 Subject: [PATCH 080/845] Notice of departure logging --- .../dev/vxrp/bot/events/ModalListener.java | 8 ++- .../bot/events/buttons/NoticeOfDeparture.java | 5 +- .../bot/events/modals/NoticeOfDeparture.java | 50 +++++++++++++++---- .../configuration/records/LoggingGroup.java | 3 +- .../translations/TranslationLoader.java | 5 +- .../util/configuration/util/TRANSLATIONS.java | 5 +- .../resources/translations/translations.yml | 49 +++++++++++++++++- 7 files changed, 110 insertions(+), 15 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/events/ModalListener.java b/src/main/java/dev/vxrp/bot/events/ModalListener.java index 26ec1ed8..2422e1ce 100644 --- a/src/main/java/dev/vxrp/bot/events/ModalListener.java +++ b/src/main/java/dev/vxrp/bot/events/ModalListener.java @@ -41,7 +41,13 @@ public void onModalInteraction(ModalInteractionEvent event) { event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.acceptNoticeOfDeparture(event, user)); } if (event.getModalId().startsWith("reason_action_dismiss_nod")) { - event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> NoticeOfDeparture.dismissNoticeOfDeparture(event, user)); + event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> { + try { + NoticeOfDeparture.dismissNoticeOfDeparture(event, user); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }); } if (event.getModalId().startsWith("reason_action_revoke_nod")) { event.getJDA().retrieveUserById(event.getModalId().split(":")[1]).queue(user -> { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index b68cfd97..643779f3 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -49,8 +49,11 @@ public static void acceptedNoticeOfDeparture(ButtonInteractionEvent event, User } public static void dismissNoticeOfDeparture(ButtonInteractionEvent event, User user) { + String start_time = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime()); + String end_time = event.getComponentId().split(":")[2]; + event.replyModal( - Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":", reason_action.modal_reason_action_title()) + Modal.create("reason_action_dismiss_nod:"+user.getId()+":"+event.getMessageId()+":"+end_time+":"+start_time+":", reason_action.modal_reason_action_title()) .addComponents(ActionRow.of(shortModal( "reason_action_reason", reason_action.modal_reason_action_first_title(), diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index c6428d82..a59fa207 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import java.awt.*; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -65,13 +66,9 @@ public static void createNewNoticeOfDeparture(ModalInteractionEvent event) { .build()) .addActionRow( Button.success("accept_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", buttons.accept_notice_of_departure_ticket()), - Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":", buttons.dismiss_notice_of_departure_ticket()) - ).queue(message -> { - message.editMessage(String.join("", pingRoles)).queue(); - }); - channel.sendMessage(String.join("", pingRoles)).queue(message -> { - message.delete().queue(); - }); + Button.danger("dismiss_ticket_notice_of_departure"+":"+event.getUser().getId()+":"+ Objects.requireNonNull(event.getValue("nod_timeframe")).getAsString()+":", buttons.dismiss_notice_of_departure_ticket()) + ).queue(message -> message.editMessage(String.join("", pingRoles)).queue()); + channel.sendMessage(String.join("", pingRoles)).queue(message -> message.delete().queue()); } public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User user) { @@ -104,9 +101,21 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use .build()) .addActionRow( Button.danger("revoke_notice_of_departure"+":"+ - user.getId()+":"+event.getModalId().split(":")[4]+":"+event.getModalId().split(":")[4]+":", buttons.revoke_notice_of_departure()) + user.getId()+":"+event.getModalId().split(":")[4]+":"+event.getModalId().split(":")[3]+":", buttons.revoke_notice_of_departure()) ).queue(message -> { try { + ScpTools.getLoggerManager().creationLog(event.getUser(), + LoadedConfigurations.getLoggingMemoryLoad().notice_of_departure_create_logging_action() + .replace("%id%", user.getId()) + .replace("%message%", message.getJumpUrl()) + .replace("%user%", "<@"+event.getUser().getId()+">") + .replace("%creator%", "<@"+user.getId()+">") + .replace("%expiration%", event.getModalId().split(":")[3]) + .replace("%date%", event.getModalId().split(":")[4]) + .replace("%reason%", reason), + LoadedConfigurations.getConfigMemoryLoad().notice_of_departures_logging_channel_id(), + Color.GREEN); + ScpTools.getSqliteManager().getNoticeOfDepartureTableManager().addNoticeOfDeparture( user.getId(), LoadedConfigurations.getConfigMemoryLoad().notice_of_departure_notice_channel_id()+":"+message.getId(), @@ -120,7 +129,7 @@ public static void acceptNoticeOfDeparture(ModalInteractionEvent event, User use event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); } - public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User user) { + public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User user) throws InterruptedException { String messageID = event.getModalId().split(":")[2]; Objects.requireNonNull(Objects.requireNonNull(event.getGuild()).getTextChannelById(Objects.requireNonNull(event.getChannelId()))).deleteMessageById(messageID).queue(); @@ -133,6 +142,18 @@ public static void dismissNoticeOfDeparture(ModalInteractionEvent event, User us .build() )).queue(); + ScpTools.getLoggerManager().creationLog(event.getUser(), + LoadedConfigurations.getLoggingMemoryLoad().notice_of_departure_dismiss_logging_action() + .replace("%id%", user.getId()) + .replace("%user%", "<@"+event.getUser().getId()+">") + .replace("%creator%", "<@"+user.getId()+">") + .replace("%handler%", "<@"+event.getUser().getId()+">") + .replace("%expiration%", event.getModalId().split(":")[3]) + .replace("%date%", event.getModalId().split(":")[4]) + .replace("%reason%", reason), + LoadedConfigurations.getConfigMemoryLoad().notice_of_departures_logging_channel_id(), + Color.RED); + event.reply(translations.ticket_message_sent()).setEphemeral(true).queue(); } @@ -149,5 +170,16 @@ public static void revokeNoticeOfDeparture(ModalInteractionEvent event, User use .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString())) .build() ).queue()); + ScpTools.getLoggerManager().creationLog(event.getUser(), + LoadedConfigurations.getLoggingMemoryLoad().notice_of_departure_close_logging_action() + .replace("%id%", user.getId()) + .replace("%user%", "<@"+event.getUser().getId()+">") + .replace("%creator%", "<@"+user.getId()+">") + .replace("%handler%", "<@"+event.getUser().getId()+">") + .replace("%expiration%", event.getModalId().split(":")[2]) + .replace("%date%", event.getModalId().split(":")[3]) + .replace("%reason%", Objects.requireNonNull(event.getValue("reason_action_reason")).getAsString()), + LoadedConfigurations.getConfigMemoryLoad().notice_of_departures_logging_channel_id(), + Color.RED); } } \ No newline at end of file diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java index 638277c2..f4b4f1a5 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java @@ -1,5 +1,6 @@ package dev.vxrp.bot.util.configuration.records; public record LoggingGroup(String single_message_log_template, String create_log_template, String close_log_template, String database_log_template, String support_message_logging_action, - String support_ticket_create_logging_action, String support_ticket_close_logging_action) { + String support_ticket_create_logging_action, String support_ticket_close_logging_action, String notice_of_departure_create_logging_action, + String notice_of_departure_dismiss_logging_action, String notice_of_departure_close_logging_action) { } diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java index adb91e58..35516790 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java @@ -82,7 +82,10 @@ public TranslationLoader() { ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.DATABASE_LOG_TEMPLATE)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_MESSAGE_LOGGING_ACTION)), ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CREATE_ACTION)), - ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CLOSE_ACTION))); + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.SUPPORT_TICKET_CLOSE_ACTION)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.NOTICE_OF_DEPARTURE_CREATE_ACTION)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.NOTICE_OF_DEPARTURE_DISMISS_ACTION)), + ColorTool.useCustomColorCodes(translationManager.getString(TRANSLATIONS.LOGGING.NOTICE_OF_DEPARTURE_CLOSE_ACTION))); ButtonGroup buttonsGroup = new ButtonGroup( translationManager.getString(TRANSLATIONS.BUTTONS.PASTE_RULES), diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java index 2487e43a..a0489b9b 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java @@ -81,6 +81,9 @@ public static final class LOGGING { public static final String SUPPORT_MESSAGE_LOGGING_ACTION = "logging.support_message_logging_action"; public static final String SUPPORT_TICKET_CREATE_ACTION = "logging.support_ticket_create_logging_action"; public static final String SUPPORT_TICKET_CLOSE_ACTION = "logging.support_ticket_close_logging_action"; + public static final String NOTICE_OF_DEPARTURE_CREATE_ACTION = "logging.notice_of_departure_create_logging_action"; + public static final String NOTICE_OF_DEPARTURE_DISMISS_ACTION = "logging.notice_of_departure_dismiss_logging_action"; + public static final String NOTICE_OF_DEPARTURE_CLOSE_ACTION = "logging.notice_of_departure_close_logging_action"; } public static final class BUTTONS { public static final String PASTE_RULES = "buttons.paste_rules"; @@ -102,4 +105,4 @@ public static final class BUTTONS { public static final String REVOKE_NOTICE_OF_DEPARTURE = "buttons.revoke_notice_of_departure"; public static final String DELETE_NOTICE_OF_DEPARTURE = "buttons.delete_notice_of_departure"; } -} +} \ No newline at end of file diff --git a/src/main/resources/translations/translations.yml b/src/main/resources/translations/translations.yml index dd042af1..7b227313 100644 --- a/src/main/resources/translations/translations.yml +++ b/src/main/resources/translations/translations.yml @@ -227,7 +227,7 @@ logging: " database_log_template: " **SQL Statement**\n - ```ansi + ```sql %statement% ``` @@ -271,6 +271,53 @@ logging: *Ticket created - **%date%*** " + notice_of_departure_create_logging_action: " + ✅ Notice of Departure with id: **%id%** created %message% by user %user%\n + %filler% + Ticket Id - **%id%**\n + Creator - **%creator%**\n + Expiration Date - **%expiration%**\n + + *Ticket created - **%date%***\n + + **Reason**\n + ```ansi + + %reason% + ``` + " + notice_of_departure_dismiss_logging_action: " + ❌ Notice of Departure with id: **%id%** dismissed by %user%\n + %filler% + Ticket Id - **%id%**\n + Creator - **%creator%**\n + Handler - **%handler%**\n + Expiration Date - **%expiration%**\n + + *Ticket created - **%date%***\n + + **Reason**\n + ```ansi + + %reason% + ``` + " + notice_of_departure_close_logging_action: " + ❌ Notice of Departure with id: **%id%** revoked by %user%\n + %filler% + Ticket Id - **%id%**\n + Creator - **%creator%**\n + Handler - **%handler%**\n + Expiration Date - **%expiration%**\n + + *Ticket created - **%date%***\n + + **Reason**\n + ```ansi + + %reason% + ``` + " # You can't use color codes for the following button translations buttons: From 8d1e26fd4891aaa146a07d8bece8d124ea621667 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:00:07 +0100 Subject: [PATCH 081/845] Changes to the main class --- src/main/java/dev/vxrp/bot/ScpTools.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 0c43af11..787220bf 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -7,8 +7,8 @@ import dev.vxrp.bot.commands.CommandManager; import dev.vxrp.bot.commands.help.HelpCommand; import dev.vxrp.bot.commands.templates.TemplateCommand; -import dev.vxrp.bot.config.managers.ColorConfigManager; -import dev.vxrp.bot.config.managers.TranslationManager; +import dev.vxrp.bot.config.managers.configuration.ColorConfigManager; +import dev.vxrp.bot.config.managers.translations.TranslationManager; import dev.vxrp.bot.events.MessageListener; import dev.vxrp.bot.runnables.CheckNoticeOfDeparture; import dev.vxrp.bot.util.api.github.GitHubApi; @@ -16,7 +16,7 @@ import dev.vxrp.bot.util.configuration.configs.ConfigLoader; import dev.vxrp.bot.util.configuration.records.ConfigGroup; import dev.vxrp.bot.util.configuration.util.CONFIG; -import dev.vxrp.bot.config.managers.ConfigManager; +import dev.vxrp.bot.config.managers.configuration.ConfigManager; import dev.vxrp.bot.events.ModalListener; import dev.vxrp.bot.util.colors.ColorTool; import dev.vxrp.bot.util.Enums.DCColor; @@ -54,10 +54,8 @@ public static void main(String[] args) throws IOException { setLoggingLevel(); loadConfigs(); - Activity.ActivityType activityType = Activity.ActivityType.valueOf(configManager.getString(CONFIG.ACTIVITY_TYPE)); - logger.info("ActivityType set to {}", ColorTool.apply(DCColor.RED, activityType.toString())); - String activityContent = configManager.getString(CONFIG.ACTIVITY_CONTENT); - logger.info("ActivityContent set to {}", ColorTool.apply(DCColor.RED, activityContent)); + Activity.ActivityType activityType = Activity.ActivityType.valueOf(LoadedConfigurations.getConfigMemoryLoad().activity_type()); + String activityContent = LoadedConfigurations.getConfigMemoryLoad().activity_content(); JDA api = JDABuilder.createDefault(configManager.getToken(), GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS) .setActivity(Activity.of(activityType, activityContent)) From bfb8666f7e60810285d330b4ab193fa9949e936c Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:02:04 +0100 Subject: [PATCH 082/845] Moved util folder --- src/main/java/dev/vxrp/bot/ScpTools.java | 18 +++++------ .../dev/vxrp/bot/commands/CommandManager.java | 6 ++-- .../commands/templates/TemplateCommand.java | 8 ++--- .../noticeOfDeparture/NoticeOfDeparture.java | 6 ++-- .../templates/rules/RulesTemplateUnit.java | 8 ++--- .../commands/templates/support/Support.java | 6 ++-- .../ColorConfigManager.java | 2 +- .../{ => configuration}/ConfigManager.java | 2 +- .../managers/regulars/RegularsManager.java | 16 ++++++++++ .../TranslationManager.java | 2 +- .../sqlite/NoticeOfDepartureTableManager.java | 8 ++--- .../bot/database/sqlite/SqliteManager.java | 8 ++--- .../database/sqlite/TicketsTableManager.java | 15 ++++------ .../dev/vxrp/bot/events/MessageListener.java | 2 +- .../bot/events/buttons/NoticeOfDeparture.java | 6 ++-- .../dev/vxrp/bot/events/buttons/Support.java | 12 +++----- .../dev/vxrp/bot/events/buttons/Unban.java | 4 +-- .../dev/vxrp/bot/events/messages/Support.java | 6 ++-- .../bot/events/modals/NoticeOfDeparture.java | 14 ++++----- .../dev/vxrp/bot/events/modals/Support.java | 18 +++++------ .../dev/vxrp/bot/events/modals/Unban.java | 16 +++++----- .../bot/runnables/CheckNoticeOfDeparture.java | 14 ++++----- .../vxrp/{bot => }/util/Enums/DCColor.java | 2 +- .../vxrp/{bot => }/util/Enums/SLColors.java | 2 +- .../util/Enums/TicketIdentifier.java | 2 +- .../{bot => }/util/api/cedmod/CedModApi.java | 6 ++-- .../{bot => }/util/api/github/GitHubApi.java | 6 ++-- .../{bot => }/util/builder/StatsBuilder.java | 2 +- .../vxrp/{bot => }/util/colors/ColorTool.java | 6 ++-- .../configuration/LoadedConfigurations.java | 3 +- .../configuration/configs/ConfigLoader.java | 14 ++++----- .../configuration/records/ButtonGroup.java | 2 +- .../configuration/records/ConfigGroup.java | 2 +- .../configuration/records/LoggingGroup.java | 2 +- .../records/NoticeOfDepartureGroup.java | 2 +- .../configuration/records/SupportGroup.java | 2 +- .../translations/TranslationLoader.java | 20 ++++++------- .../util/configuration/util/CONFIG.java | 2 +- .../util/configuration/util/TRANSLATIONS.java | 2 +- .../converter/PermissionListConverter.java | 2 +- .../{bot => }/util/general/RepeatTask.java | 2 +- .../RollPerSessionTriggeringPolicy.java | 2 +- .../{bot => }/util/logger/LoggerManager.java | 8 ++--- .../util/parser/CustomColorParser.java | 8 ++--- .../{bot => }/util/pastebin/PastebinUtil.java | 2 +- .../util/records/NoticeOfDeparture.java | 2 +- .../vxrp/{bot => }/util/records/Ticket.java | 4 +-- src/main/resources/configs/config.yml | 30 ++++++++++++------- src/main/resources/logback.xml | 2 +- .../resources/regulars/example/config.json | 22 ++++++++++++++ .../resources/regulars/example/manifest.json | 8 +++++ 51 files changed, 203 insertions(+), 163 deletions(-) rename src/main/java/dev/vxrp/bot/config/managers/{ => configuration}/ColorConfigManager.java (95%) rename src/main/java/dev/vxrp/bot/config/managers/{ => configuration}/ConfigManager.java (97%) create mode 100644 src/main/java/dev/vxrp/bot/config/managers/regulars/RegularsManager.java rename src/main/java/dev/vxrp/bot/config/managers/{ => translations}/TranslationManager.java (95%) rename src/main/java/dev/vxrp/{bot => }/util/Enums/DCColor.java (81%) rename src/main/java/dev/vxrp/{bot => }/util/Enums/SLColors.java (89%) rename src/main/java/dev/vxrp/{bot => }/util/Enums/TicketIdentifier.java (63%) rename src/main/java/dev/vxrp/{bot => }/util/api/cedmod/CedModApi.java (95%) rename src/main/java/dev/vxrp/{bot => }/util/api/github/GitHubApi.java (94%) rename src/main/java/dev/vxrp/{bot => }/util/builder/StatsBuilder.java (99%) rename src/main/java/dev/vxrp/{bot => }/util/colors/ColorTool.java (97%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/LoadedConfigurations.java (97%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/configs/ConfigLoader.java (90%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/records/ButtonGroup.java (92%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/records/ConfigGroup.java (96%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/records/LoggingGroup.java (90%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/records/NoticeOfDepartureGroup.java (94%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/records/SupportGroup.java (96%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/translations/TranslationLoader.java (95%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/util/CONFIG.java (98%) rename src/main/java/dev/vxrp/{bot => }/util/configuration/util/TRANSLATIONS.java (99%) rename src/main/java/dev/vxrp/{bot => }/util/converter/PermissionListConverter.java (93%) rename src/main/java/dev/vxrp/{bot => }/util/general/RepeatTask.java (92%) rename src/main/java/dev/vxrp/{bot => }/util/logback/RollPerSessionTriggeringPolicy.java (92%) rename src/main/java/dev/vxrp/{bot => }/util/logger/LoggerManager.java (97%) rename src/main/java/dev/vxrp/{bot => }/util/parser/CustomColorParser.java (98%) rename src/main/java/dev/vxrp/{bot => }/util/pastebin/PastebinUtil.java (93%) rename src/main/java/dev/vxrp/{bot => }/util/records/NoticeOfDeparture.java (77%) rename src/main/java/dev/vxrp/{bot => }/util/records/Ticket.java (59%) create mode 100644 src/main/resources/regulars/example/config.json create mode 100644 src/main/resources/regulars/example/manifest.json diff --git a/src/main/java/dev/vxrp/bot/ScpTools.java b/src/main/java/dev/vxrp/bot/ScpTools.java index 787220bf..7f3ea6da 100644 --- a/src/main/java/dev/vxrp/bot/ScpTools.java +++ b/src/main/java/dev/vxrp/bot/ScpTools.java @@ -11,18 +11,16 @@ import dev.vxrp.bot.config.managers.translations.TranslationManager; import dev.vxrp.bot.events.MessageListener; import dev.vxrp.bot.runnables.CheckNoticeOfDeparture; -import dev.vxrp.bot.util.api.github.GitHubApi; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.configs.ConfigLoader; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.configuration.util.CONFIG; +import dev.vxrp.util.api.github.GitHubApi; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.configs.ConfigLoader; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.configuration.util.CONFIG; import dev.vxrp.bot.config.managers.configuration.ConfigManager; import dev.vxrp.bot.events.ModalListener; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.configuration.translations.TranslationLoader; -import dev.vxrp.bot.util.general.RepeatTask; -import dev.vxrp.bot.util.logger.LoggerManager; +import dev.vxrp.util.configuration.translations.TranslationLoader; +import dev.vxrp.util.general.RepeatTask; +import dev.vxrp.util.logger.LoggerManager; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; diff --git a/src/main/java/dev/vxrp/bot/commands/CommandManager.java b/src/main/java/dev/vxrp/bot/commands/CommandManager.java index a82fc9be..b38776f2 100644 --- a/src/main/java/dev/vxrp/bot/commands/CommandManager.java +++ b/src/main/java/dev/vxrp/bot/commands/CommandManager.java @@ -1,8 +1,8 @@ package dev.vxrp.bot.commands; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.converter.PermissionListConverter; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.converter.PermissionListConverter; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; import net.dv8tion.jda.api.interactions.commands.OptionType; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java index adacbe88..33bef1c5 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/TemplateCommand.java @@ -2,10 +2,10 @@ import dev.vxrp.bot.commands.templates.noticeOfDeparture.NoticeOfDeparture; import dev.vxrp.bot.commands.templates.support.Support; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ButtonGroup; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.buttons.Button; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java index 394bbcf8..07c24033 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/noticeOfDeparture/NoticeOfDeparture.java @@ -1,8 +1,8 @@ package dev.vxrp.bot.commands.templates.noticeOfDeparture; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java index 78f37bb5..0c0bedb6 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/rules/RulesTemplateUnit.java @@ -1,9 +1,9 @@ package dev.vxrp.bot.commands.templates.rules; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.pastebin.PastebinUtil; -import dev.vxrp.bot.util.parser.CustomColorParser; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.pastebin.PastebinUtil; +import dev.vxrp.util.parser.CustomColorParser; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; diff --git a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java index f181f7d3..86ee9bd9 100644 --- a/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java +++ b/src/main/java/dev/vxrp/bot/commands/templates/support/Support.java @@ -1,8 +1,8 @@ package dev.vxrp.bot.commands.templates.support; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; diff --git a/src/main/java/dev/vxrp/bot/config/managers/ColorConfigManager.java b/src/main/java/dev/vxrp/bot/config/managers/configuration/ColorConfigManager.java similarity index 95% rename from src/main/java/dev/vxrp/bot/config/managers/ColorConfigManager.java rename to src/main/java/dev/vxrp/bot/config/managers/configuration/ColorConfigManager.java index 04acfdff..6df891ed 100644 --- a/src/main/java/dev/vxrp/bot/config/managers/ColorConfigManager.java +++ b/src/main/java/dev/vxrp/bot/config/managers/configuration/ColorConfigManager.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.config.managers; +package dev.vxrp.bot.config.managers.configuration; import org.bspfsystems.yamlconfiguration.file.YamlConfiguration; diff --git a/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java b/src/main/java/dev/vxrp/bot/config/managers/configuration/ConfigManager.java similarity index 97% rename from src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java rename to src/main/java/dev/vxrp/bot/config/managers/configuration/ConfigManager.java index 5d2720b5..fa6195ce 100644 --- a/src/main/java/dev/vxrp/bot/config/managers/ConfigManager.java +++ b/src/main/java/dev/vxrp/bot/config/managers/configuration/ConfigManager.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.config.managers; +package dev.vxrp.bot.config.managers.configuration; import org.bspfsystems.yamlconfiguration.file.YamlConfiguration; diff --git a/src/main/java/dev/vxrp/bot/config/managers/regulars/RegularsManager.java b/src/main/java/dev/vxrp/bot/config/managers/regulars/RegularsManager.java new file mode 100644 index 00000000..0979d543 --- /dev/null +++ b/src/main/java/dev/vxrp/bot/config/managers/regulars/RegularsManager.java @@ -0,0 +1,16 @@ +package dev.vxrp.bot.config.managers.regulars; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Path; + +public class RegularsManager { + public RegularsManager(Path path) throws IOException, FileNotFoundException { + //Folder Creation + String folderPath = path+"/regulars/"; + new File(folderPath).mkdir(); + + //Base Folder Creation + } +} diff --git a/src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java b/src/main/java/dev/vxrp/bot/config/managers/translations/TranslationManager.java similarity index 95% rename from src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java rename to src/main/java/dev/vxrp/bot/config/managers/translations/TranslationManager.java index e67a2346..6b711ae5 100644 --- a/src/main/java/dev/vxrp/bot/config/managers/TranslationManager.java +++ b/src/main/java/dev/vxrp/bot/config/managers/translations/TranslationManager.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.config.managers; +package dev.vxrp.bot.config.managers.translations; import org.bspfsystems.yamlconfiguration.file.YamlConfiguration; diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java index 2c635e8b..0529dbe1 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/NoticeOfDepartureTableManager.java @@ -1,10 +1,10 @@ package dev.vxrp.bot.database.sqlite; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.records.NoticeOfDeparture; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.records.NoticeOfDeparture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java index 553e077f..1e339cd0 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/SqliteManager.java @@ -1,11 +1,9 @@ package dev.vxrp.bot.database.sqlite; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.logger.LoggerManager; -import net.dv8tion.jda.api.JDA; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java index 23241c18..8f4f074c 100644 --- a/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java +++ b/src/main/java/dev/vxrp/bot/database/sqlite/TicketsTableManager.java @@ -1,14 +1,11 @@ package dev.vxrp.bot.database.sqlite; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.Enums.TicketIdentifier; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.logger.LoggerManager; -import dev.vxrp.bot.util.records.NoticeOfDeparture; -import dev.vxrp.bot.util.records.Ticket; -import org.jetbrains.annotations.NotNull; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.Enums.TicketIdentifier; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.records.Ticket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,8 +67,6 @@ public Ticket getTicket(String id) throws SQLException, InterruptedException { try (ResultSet resultSet = statement.executeQuery()) { - logger.info("{} - Selected ticket with id: {}", prefix, - ColorTool.apply(DCColor.GREEN, id)); ScpTools.getLoggerManager().databaseLog( "SELECT * FROM tickets WHERE id=?", "Selected ticket id: "+ColorTool.apply(DCColor.GREEN, id), diff --git a/src/main/java/dev/vxrp/bot/events/MessageListener.java b/src/main/java/dev/vxrp/bot/events/MessageListener.java index c3c4f2a3..a24f4e29 100644 --- a/src/main/java/dev/vxrp/bot/events/MessageListener.java +++ b/src/main/java/dev/vxrp/bot/events/MessageListener.java @@ -1,6 +1,6 @@ package dev.vxrp.bot.events; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.LoadedConfigurations; import org.slf4j.Logger; import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.events.messages.Support; diff --git a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java index 643779f3..76741ee1 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/NoticeOfDeparture.java @@ -1,8 +1,8 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Support.java b/src/main/java/dev/vxrp/bot/events/buttons/Support.java index 7eb5fdfb..2e103a5b 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Support.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Support.java @@ -1,13 +1,11 @@ package dev.vxrp.bot.events.buttons; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.SupportGroup; -import dev.vxrp.bot.util.logger.LoggerManager; -import dev.vxrp.bot.util.records.Ticket; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.SupportGroup; +import dev.vxrp.util.logger.LoggerManager; +import dev.vxrp.util.records.Ticket; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; @@ -18,11 +16,9 @@ import net.dv8tion.jda.api.interactions.modals.Modal; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.event.Level; import java.awt.*; import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; public class Support { diff --git a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java index 1e2d4a6c..c6729bcb 100644 --- a/src/main/java/dev/vxrp/bot/events/buttons/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/buttons/Unban.java @@ -1,7 +1,7 @@ package dev.vxrp.bot.events.buttons; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; diff --git a/src/main/java/dev/vxrp/bot/events/messages/Support.java b/src/main/java/dev/vxrp/bot/events/messages/Support.java index 9070e0e4..0c462327 100644 --- a/src/main/java/dev/vxrp/bot/events/messages/Support.java +++ b/src/main/java/dev/vxrp/bot/events/messages/Support.java @@ -1,9 +1,9 @@ package dev.vxrp.bot.events.messages; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.logger.LoggerManager; -import dev.vxrp.bot.util.records.Ticket; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.logger.LoggerManager; +import dev.vxrp.util.records.Ticket; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import java.awt.*; diff --git a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java index a59fa207..8d3a2272 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/events/modals/NoticeOfDeparture.java @@ -1,13 +1,13 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.builder.StatsBuilder; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.builder.StatsBuilder; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.configuration.records.NoticeOfDepartureGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; diff --git a/src/main/java/dev/vxrp/bot/events/modals/Support.java b/src/main/java/dev/vxrp/bot/events/modals/Support.java index 16ca72bd..28826985 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Support.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Support.java @@ -1,15 +1,15 @@ package dev.vxrp.bot.events.modals; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.Enums.TicketIdentifier; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.builder.StatsBuilder; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.SupportGroup; -import dev.vxrp.bot.util.logger.LoggerManager; +import dev.vxrp.util.Enums.TicketIdentifier; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.builder.StatsBuilder; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.SupportGroup; +import dev.vxrp.util.logger.LoggerManager; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; diff --git a/src/main/java/dev/vxrp/bot/events/modals/Unban.java b/src/main/java/dev/vxrp/bot/events/modals/Unban.java index 63666a01..4fb2c60b 100644 --- a/src/main/java/dev/vxrp/bot/events/modals/Unban.java +++ b/src/main/java/dev/vxrp/bot/events/modals/Unban.java @@ -1,13 +1,13 @@ package dev.vxrp.bot.events.modals; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.builder.StatsBuilder; -import dev.vxrp.bot.util.api.cedmod.CedModApi; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.builder.StatsBuilder; +import dev.vxrp.util.api.cedmod.CedModApi; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.SupportGroup; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; diff --git a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java index 6a65c9b4..d6987a3d 100644 --- a/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/bot/runnables/CheckNoticeOfDeparture.java @@ -2,13 +2,13 @@ import dev.vxrp.bot.ScpTools; import dev.vxrp.bot.database.sqlite.SqliteManager; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.builder.StatsBuilder; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.records.NoticeOfDeparture; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.builder.StatsBuilder; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.util.records.NoticeOfDeparture; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; diff --git a/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java b/src/main/java/dev/vxrp/util/Enums/DCColor.java similarity index 81% rename from src/main/java/dev/vxrp/bot/util/Enums/DCColor.java rename to src/main/java/dev/vxrp/util/Enums/DCColor.java index bf789c1c..1f35e23a 100644 --- a/src/main/java/dev/vxrp/bot/util/Enums/DCColor.java +++ b/src/main/java/dev/vxrp/util/Enums/DCColor.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.Enums; +package dev.vxrp.util.Enums; public enum DCColor { DARK_GRAY, diff --git a/src/main/java/dev/vxrp/bot/util/Enums/SLColors.java b/src/main/java/dev/vxrp/util/Enums/SLColors.java similarity index 89% rename from src/main/java/dev/vxrp/bot/util/Enums/SLColors.java rename to src/main/java/dev/vxrp/util/Enums/SLColors.java index ca22ad7e..47a8620a 100644 --- a/src/main/java/dev/vxrp/bot/util/Enums/SLColors.java +++ b/src/main/java/dev/vxrp/util/Enums/SLColors.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.Enums; +package dev.vxrp.util.Enums; public enum SLColors { PINK, diff --git a/src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java b/src/main/java/dev/vxrp/util/Enums/TicketIdentifier.java similarity index 63% rename from src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java rename to src/main/java/dev/vxrp/util/Enums/TicketIdentifier.java index c1727d24..434e3b41 100644 --- a/src/main/java/dev/vxrp/bot/util/Enums/TicketIdentifier.java +++ b/src/main/java/dev/vxrp/util/Enums/TicketIdentifier.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.Enums; +package dev.vxrp.util.Enums; public enum TicketIdentifier { UNBAN, diff --git a/src/main/java/dev/vxrp/bot/util/api/cedmod/CedModApi.java b/src/main/java/dev/vxrp/util/api/cedmod/CedModApi.java similarity index 95% rename from src/main/java/dev/vxrp/bot/util/api/cedmod/CedModApi.java rename to src/main/java/dev/vxrp/util/api/cedmod/CedModApi.java index 8b70c2ec..714bde8e 100644 --- a/src/main/java/dev/vxrp/bot/util/api/cedmod/CedModApi.java +++ b/src/main/java/dev/vxrp/util/api/cedmod/CedModApi.java @@ -1,9 +1,9 @@ -package dev.vxrp.bot.util.api.cedmod; +package dev.vxrp.util.api.cedmod; import com.google.gson.JsonArray; import com.google.gson.JsonParser; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; import okhttp3.*; import java.io.IOException; diff --git a/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java b/src/main/java/dev/vxrp/util/api/github/GitHubApi.java similarity index 94% rename from src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java rename to src/main/java/dev/vxrp/util/api/github/GitHubApi.java index 6cda5725..31b6d79e 100644 --- a/src/main/java/dev/vxrp/bot/util/api/github/GitHubApi.java +++ b/src/main/java/dev/vxrp/util/api/github/GitHubApi.java @@ -1,9 +1,9 @@ -package dev.vxrp.bot.util.api.github; +package dev.vxrp.util.api.github; import com.google.gson.JsonArray; import com.google.gson.JsonParser; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; import okhttp3.Call; import okhttp3.OkHttpClient; import okhttp3.Request; diff --git a/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java b/src/main/java/dev/vxrp/util/builder/StatsBuilder.java similarity index 99% rename from src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java rename to src/main/java/dev/vxrp/util/builder/StatsBuilder.java index 37ebc079..4aa7248e 100644 --- a/src/main/java/dev/vxrp/bot/util/builder/StatsBuilder.java +++ b/src/main/java/dev/vxrp/util/builder/StatsBuilder.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.builder; +package dev.vxrp.util.builder; import net.dv8tion.jda.api.EmbedBuilder; diff --git a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java b/src/main/java/dev/vxrp/util/colors/ColorTool.java similarity index 97% rename from src/main/java/dev/vxrp/bot/util/colors/ColorTool.java rename to src/main/java/dev/vxrp/util/colors/ColorTool.java index 1debf741..dc624b26 100644 --- a/src/main/java/dev/vxrp/bot/util/colors/ColorTool.java +++ b/src/main/java/dev/vxrp/util/colors/ColorTool.java @@ -1,10 +1,8 @@ -package dev.vxrp.bot.util.colors; +package dev.vxrp.util.colors; -import dev.vxrp.bot.util.Enums.DCColor; +import dev.vxrp.util.Enums.DCColor; import org.jetbrains.annotations.NotNull; -import java.util.List; - public class ColorTool { public static final String DARK_GRAY = "\u001B[2;30m"; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java similarity index 97% rename from src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java rename to src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java index 57d7ee58..64e5ddf3 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java @@ -1,6 +1,7 @@ -package dev.vxrp.bot.util.configuration; +package dev.vxrp.util.configuration; import dev.vxrp.bot.util.configuration.records.*; +import dev.vxrp.util.configuration.records.*; import java.util.HashSet; import java.util.Iterator; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java b/src/main/java/dev/vxrp/util/configuration/configs/ConfigLoader.java similarity index 90% rename from src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java rename to src/main/java/dev/vxrp/util/configuration/configs/ConfigLoader.java index 71334a73..af9ac258 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/configs/ConfigLoader.java +++ b/src/main/java/dev/vxrp/util/configuration/configs/ConfigLoader.java @@ -1,12 +1,12 @@ -package dev.vxrp.bot.util.configuration.configs; +package dev.vxrp.util.configuration.configs; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.ConfigManager; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.ConfigGroup; -import dev.vxrp.bot.util.configuration.util.CONFIG; +import dev.vxrp.bot.config.managers.configuration.ConfigManager; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.ConfigGroup; +import dev.vxrp.util.configuration.util.CONFIG; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/ButtonGroup.java b/src/main/java/dev/vxrp/util/configuration/records/ButtonGroup.java similarity index 92% rename from src/main/java/dev/vxrp/bot/util/configuration/records/ButtonGroup.java rename to src/main/java/dev/vxrp/util/configuration/records/ButtonGroup.java index 9241c28c..6124fe0a 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/ButtonGroup.java +++ b/src/main/java/dev/vxrp/util/configuration/records/ButtonGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.records; +package dev.vxrp.util.configuration.records; public record ButtonGroup(String paste_rules, String update_rules, String create_new_support_ticket, String close_support_ticket, String claim_support_ticket, String settings_support_ticket, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java b/src/main/java/dev/vxrp/util/configuration/records/ConfigGroup.java similarity index 96% rename from src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java rename to src/main/java/dev/vxrp/util/configuration/records/ConfigGroup.java index cbcc3853..8c64a978 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/ConfigGroup.java +++ b/src/main/java/dev/vxrp/util/configuration/records/ConfigGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.records; +package dev.vxrp.util.configuration.records; import java.util.List; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java b/src/main/java/dev/vxrp/util/configuration/records/LoggingGroup.java similarity index 90% rename from src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java rename to src/main/java/dev/vxrp/util/configuration/records/LoggingGroup.java index f4b4f1a5..be2706c4 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/LoggingGroup.java +++ b/src/main/java/dev/vxrp/util/configuration/records/LoggingGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.records; +package dev.vxrp.util.configuration.records; public record LoggingGroup(String single_message_log_template, String create_log_template, String close_log_template, String database_log_template, String support_message_logging_action, String support_ticket_create_logging_action, String support_ticket_close_logging_action, String notice_of_departure_create_logging_action, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/NoticeOfDepartureGroup.java b/src/main/java/dev/vxrp/util/configuration/records/NoticeOfDepartureGroup.java similarity index 94% rename from src/main/java/dev/vxrp/bot/util/configuration/records/NoticeOfDepartureGroup.java rename to src/main/java/dev/vxrp/util/configuration/records/NoticeOfDepartureGroup.java index 2204d3ba..f5947310 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/NoticeOfDepartureGroup.java +++ b/src/main/java/dev/vxrp/util/configuration/records/NoticeOfDepartureGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.records; +package dev.vxrp.util.configuration.records; public record NoticeOfDepartureGroup(String first_title, String first_body, String modal_title, String modal_first_title, String modal_first_placeholder, String modal_second_title, String modal_second_placeholder, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/records/SupportGroup.java b/src/main/java/dev/vxrp/util/configuration/records/SupportGroup.java similarity index 96% rename from src/main/java/dev/vxrp/bot/util/configuration/records/SupportGroup.java rename to src/main/java/dev/vxrp/util/configuration/records/SupportGroup.java index 8f5f44b4..31735032 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/records/SupportGroup.java +++ b/src/main/java/dev/vxrp/util/configuration/records/SupportGroup.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.records; +package dev.vxrp.util.configuration.records; public record SupportGroup(String first_title, String first_body, String second_title, String second_body, String modal_support_title, String modal_support_first_title, diff --git a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java b/src/main/java/dev/vxrp/util/configuration/translations/TranslationLoader.java similarity index 95% rename from src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java rename to src/main/java/dev/vxrp/util/configuration/translations/TranslationLoader.java index 35516790..59b44872 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/translations/TranslationLoader.java +++ b/src/main/java/dev/vxrp/util/configuration/translations/TranslationLoader.java @@ -1,15 +1,15 @@ -package dev.vxrp.bot.util.configuration.translations; +package dev.vxrp.util.configuration.translations; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.config.managers.TranslationManager; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.records.ButtonGroup; -import dev.vxrp.bot.util.configuration.records.LoggingGroup; -import dev.vxrp.bot.util.configuration.util.TRANSLATIONS; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; -import dev.vxrp.bot.util.configuration.records.NoticeOfDepartureGroup; -import dev.vxrp.bot.util.configuration.records.SupportGroup; +import dev.vxrp.bot.config.managers.translations.TranslationManager; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.records.ButtonGroup; +import dev.vxrp.util.configuration.records.LoggingGroup; +import dev.vxrp.util.configuration.util.TRANSLATIONS; +import dev.vxrp.util.configuration.LoadedConfigurations; +import dev.vxrp.util.configuration.records.NoticeOfDepartureGroup; +import dev.vxrp.util.configuration.records.SupportGroup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java b/src/main/java/dev/vxrp/util/configuration/util/CONFIG.java similarity index 98% rename from src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java rename to src/main/java/dev/vxrp/util/configuration/util/CONFIG.java index 3cf55af6..310bea13 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/CONFIG.java +++ b/src/main/java/dev/vxrp/util/configuration/util/CONFIG.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.util; +package dev.vxrp.util.configuration.util; public class CONFIG { public static final String TOKEN = "token"; diff --git a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java b/src/main/java/dev/vxrp/util/configuration/util/TRANSLATIONS.java similarity index 99% rename from src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java rename to src/main/java/dev/vxrp/util/configuration/util/TRANSLATIONS.java index a0489b9b..d09e3e96 100644 --- a/src/main/java/dev/vxrp/bot/util/configuration/util/TRANSLATIONS.java +++ b/src/main/java/dev/vxrp/util/configuration/util/TRANSLATIONS.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.configuration.util; +package dev.vxrp.util.configuration.util; public class TRANSLATIONS { public static final class SUPPORT { diff --git a/src/main/java/dev/vxrp/bot/util/converter/PermissionListConverter.java b/src/main/java/dev/vxrp/util/converter/PermissionListConverter.java similarity index 93% rename from src/main/java/dev/vxrp/bot/util/converter/PermissionListConverter.java rename to src/main/java/dev/vxrp/util/converter/PermissionListConverter.java index 7c891f7b..527834ee 100644 --- a/src/main/java/dev/vxrp/bot/util/converter/PermissionListConverter.java +++ b/src/main/java/dev/vxrp/util/converter/PermissionListConverter.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.converter; +package dev.vxrp.util.converter; import net.dv8tion.jda.api.Permission; diff --git a/src/main/java/dev/vxrp/bot/util/general/RepeatTask.java b/src/main/java/dev/vxrp/util/general/RepeatTask.java similarity index 92% rename from src/main/java/dev/vxrp/bot/util/general/RepeatTask.java rename to src/main/java/dev/vxrp/util/general/RepeatTask.java index 5673aba4..2128572d 100644 --- a/src/main/java/dev/vxrp/bot/util/general/RepeatTask.java +++ b/src/main/java/dev/vxrp/util/general/RepeatTask.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.general; +package dev.vxrp.util.general; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; diff --git a/src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java b/src/main/java/dev/vxrp/util/logback/RollPerSessionTriggeringPolicy.java similarity index 92% rename from src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java rename to src/main/java/dev/vxrp/util/logback/RollPerSessionTriggeringPolicy.java index e2d602cf..2bfc2f43 100644 --- a/src/main/java/dev/vxrp/bot/util/logback/RollPerSessionTriggeringPolicy.java +++ b/src/main/java/dev/vxrp/util/logback/RollPerSessionTriggeringPolicy.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.logback; +package dev.vxrp.util.logback; import ch.qos.logback.core.rolling.TriggeringPolicyBase; diff --git a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java b/src/main/java/dev/vxrp/util/logger/LoggerManager.java similarity index 97% rename from src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java rename to src/main/java/dev/vxrp/util/logger/LoggerManager.java index c8599e72..2d55be03 100644 --- a/src/main/java/dev/vxrp/bot/util/logger/LoggerManager.java +++ b/src/main/java/dev/vxrp/util/logger/LoggerManager.java @@ -1,8 +1,8 @@ -package dev.vxrp.bot.util.logger; +package dev.vxrp.util.logger; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.colors.ColorTool; -import dev.vxrp.bot.util.configuration.LoadedConfigurations; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.colors.ColorTool; +import dev.vxrp.util.configuration.LoadedConfigurations; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Message; diff --git a/src/main/java/dev/vxrp/bot/util/parser/CustomColorParser.java b/src/main/java/dev/vxrp/util/parser/CustomColorParser.java similarity index 98% rename from src/main/java/dev/vxrp/bot/util/parser/CustomColorParser.java rename to src/main/java/dev/vxrp/util/parser/CustomColorParser.java index ce9e92c4..7574b79e 100644 --- a/src/main/java/dev/vxrp/bot/util/parser/CustomColorParser.java +++ b/src/main/java/dev/vxrp/util/parser/CustomColorParser.java @@ -1,9 +1,9 @@ -package dev.vxrp.bot.util.parser; +package dev.vxrp.util.parser; import dev.vxrp.bot.ScpTools; -import dev.vxrp.bot.util.Enums.DCColor; -import dev.vxrp.bot.util.Enums.SLColors; -import dev.vxrp.bot.util.colors.ColorTool; +import dev.vxrp.util.Enums.DCColor; +import dev.vxrp.util.Enums.SLColors; +import dev.vxrp.util.colors.ColorTool; import java.util.*; import java.util.regex.Matcher; diff --git a/src/main/java/dev/vxrp/bot/util/pastebin/PastebinUtil.java b/src/main/java/dev/vxrp/util/pastebin/PastebinUtil.java similarity index 93% rename from src/main/java/dev/vxrp/bot/util/pastebin/PastebinUtil.java rename to src/main/java/dev/vxrp/util/pastebin/PastebinUtil.java index 01671886..402ddbe9 100644 --- a/src/main/java/dev/vxrp/bot/util/pastebin/PastebinUtil.java +++ b/src/main/java/dev/vxrp/util/pastebin/PastebinUtil.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.pastebin; +package dev.vxrp.util.pastebin; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/dev/vxrp/bot/util/records/NoticeOfDeparture.java b/src/main/java/dev/vxrp/util/records/NoticeOfDeparture.java similarity index 77% rename from src/main/java/dev/vxrp/bot/util/records/NoticeOfDeparture.java rename to src/main/java/dev/vxrp/util/records/NoticeOfDeparture.java index 6a1e3c8d..e8751a26 100644 --- a/src/main/java/dev/vxrp/bot/util/records/NoticeOfDeparture.java +++ b/src/main/java/dev/vxrp/util/records/NoticeOfDeparture.java @@ -1,4 +1,4 @@ -package dev.vxrp.bot.util.records; +package dev.vxrp.util.records; public record NoticeOfDeparture(String id,String channel_id, String message_id, String start_time, String end_time) { } diff --git a/src/main/java/dev/vxrp/bot/util/records/Ticket.java b/src/main/java/dev/vxrp/util/records/Ticket.java similarity index 59% rename from src/main/java/dev/vxrp/bot/util/records/Ticket.java rename to src/main/java/dev/vxrp/util/records/Ticket.java index a60adb85..f7e9ffea 100644 --- a/src/main/java/dev/vxrp/bot/util/records/Ticket.java +++ b/src/main/java/dev/vxrp/util/records/Ticket.java @@ -1,6 +1,6 @@ -package dev.vxrp.bot.util.records; +package dev.vxrp.util.records; -import dev.vxrp.bot.util.Enums.TicketIdentifier; +import dev.vxrp.util.Enums.TicketIdentifier; public record Ticket(String id, TicketIdentifier identifier, String creation_date, String creatorId, String handlerId) { } diff --git a/src/main/resources/configs/config.yml b/src/main/resources/configs/config.yml index 1329a7c9..4ef58cc8 100644 --- a/src/main/resources/configs/config.yml +++ b/src/main/resources/configs/config.yml @@ -3,7 +3,7 @@ token: "" # Should debug mode be activated? debug: false -# Should additional debug mode be applied? +# Should additional debug info be displayed? advanced_debug: false # The activity type of the bot [COMPETING, CUSTOM_STATUS, LISTENING, PLAYING, WATCHING] @@ -30,7 +30,7 @@ logging: do_database_logging: true database_logging_channel_id: "" -# Commands that are activated by default remove to deactivate, default ["help", "template"]] +# Commands that are activated by default remove to deactivate, default ["help", "template"] commands: ["help", "template"] # Command settings # 'default_permissions' is pretty clear, find all permissions in this Javadoc https://docs.jda.wiki/net/dv8tion/jda/api/Permission.html. @@ -42,6 +42,16 @@ command_settings: default_permissions: ["ADMINISTRATOR"] description: "Command for pasting certain templates" +cedmod: + # Should Cedmod integration features be established or deactivated? + active: false + # Include https:// + instance_url: "" + # Exclude Bearer, put plain api key + api_key: "" + # This bot is only able to unban people that are on this banlist (feature for multi banlist bans coming in the future) + master_ban_list_id: "" + support_settings: # Enter ROLEIDS of roles to automatically add to new tickets roles_access_support_tickets: [] @@ -64,12 +74,10 @@ notice_of_departure: # The rate at that the notices are checked. check_rate: 1 -cedmod: - # Should Cedmod integration features be established or deactivated? - active: false - # Include https:// - instance_url: "" - # Exclude Bearer, put plain api key - api_key: "" - # This bot is only able to unban people that are on this banlist (feature for multi banlist bans coming in the future) - master_ban_list_id: "" \ No newline at end of file +regulars: + # Should example configuration be created (deactivate if you want to delete the example config) + create_example_configuration: true + # Should the bot only load from specified folder within the /regulars/ folder? + only_load_certain_folder: false + # Specify which folders should be specified if the option above is active + only_load_folders: [] \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index a9c0127a..725f72bb 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -21,7 +21,7 @@ 21 - + diff --git a/src/main/resources/regulars/example/config.json b/src/main/resources/regulars/example/config.json new file mode 100644 index 00000000..17e7627e --- /dev/null +++ b/src/main/resources/regulars/example/config.json @@ -0,0 +1,22 @@ +{"roles" : [ + { + "id" : "", + "description" : "", + "playtime_requirements" : 25 + }, + { + "id" : "", + "description" : "", + "playtime_requirements" : 50 + }, + { + "id" : "", + "description" : "", + "playtime_requirements" : 100 + }, + { + "id" : "", + "description" : "", + "playtime_requirements" : 200 + } +]} \ No newline at end of file diff --git a/src/main/resources/regulars/example/manifest.json b/src/main/resources/regulars/example/manifest.json new file mode 100644 index 00000000..f2cd6196 --- /dev/null +++ b/src/main/resources/regulars/example/manifest.json @@ -0,0 +1,8 @@ +{ + "name" : "", + "description" : "", + "custom_role" : { + "use" : false, + "id" : "" + } +} \ No newline at end of file From dfcdd88039c503eef92bb4a41c9ec5c36463147c Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:02:55 +0100 Subject: [PATCH 083/845] small fix --- .../java/dev/vxrp/util/configuration/LoadedConfigurations.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java b/src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java index 64e5ddf3..704384d3 100644 --- a/src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java +++ b/src/main/java/dev/vxrp/util/configuration/LoadedConfigurations.java @@ -1,6 +1,5 @@ package dev.vxrp.util.configuration; -import dev.vxrp.bot.util.configuration.records.*; import dev.vxrp.util.configuration.records.*; import java.util.HashSet; From eeedc61a3ebcf2ebbe2f20a751d32299e0f4e8a0 Mon Sep 17 00:00:00 2001 From: Vxrpenter <110356385+Vxrpenter@users.noreply.github.com> Date: Sat, 2 Nov 2024 18:31:42 +0100 Subject: [PATCH 084/845] RegularsManager --- .idea/inspectionProfiles/Project_Default.xml | 2 +- src/main/java/dev/vxrp/bot/ScpTools.java | 33 +++--- .../managers/regulars/RegularsManager.java | 110 +++++++++++++++++- .../configuration/configs/ConfigLoader.java | 11 +- .../configuration/records/ConfigGroup.java | 5 +- .../vxrp/util/configuration/util/CONFIG.java | 15 ++- .../java/dev/vxrp/util/records/Regular.java | 6 + .../dev/vxrp/util/records/RegularConfig.java | 4 + .../resources/regulars/example/config.json | 5 +- .../resources/regulars/example/manifest.json | 4 +- 10 files changed, 159 insertions(+), 36 deletions(-) create mode 100644 src/main/java/dev/vxrp/util/records/Regular.java create mode 100644 src/main/java/dev/vxrp/util/records/RegularConfig.java diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index e3673898..0a2ceeac 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -2,7 +2,7 @@