From 51f1d3afc527c586c9dcea34dfdc528aa20c6a45 Mon Sep 17 00:00:00 2001 From: RettichLP Date: Tue, 16 Jul 2024 22:40:27 +0200 Subject: [PATCH 1/2] Remove unused if in release GitHub action --- .github/workflows/release.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1bc6b72..068dffc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,8 +31,7 @@ jobs: - name: Build with Maven run: mvn -B test package --file pom.xml - - if: github.event_name == 'push' - name: Upload via SCP + - name: Upload via SCP uses: appleboy/scp-action@v0.1.7 with: host: turniptales.net @@ -44,8 +43,7 @@ jobs: timeout: 120s strip_components: 1 - - if: github.event_name == 'push' - name: Restart TurnipTales API + - name: Restart TurnipTales API uses: appleboy/ssh-action@v1.0.3 with: host: turniptales.net From d9085beb432aeb9f0b388da76cf7a6c2d873b8eb Mon Sep 17 00:00:00 2001 From: RettichLP Date: Wed, 17 Jul 2024 00:40:08 +0200 Subject: [PATCH 2/2] Fix ticket interaction button and add voice channel button --- .../discord/TurnipTalesDiscord.java | 4 +- .../buttons/TicketCloseAbortButton.java | 3 +- .../buttons/TicketCloseConfirmButton.java | 11 ++--- .../discord/buttons/TicketCreateButton.java | 3 +- .../discord/buttons/TicketVoiceButton.java | 46 +++++++++++++++++++ 5 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 src/main/java/net/turniptales/discord/buttons/TicketVoiceButton.java diff --git a/src/main/java/net/turniptales/discord/TurnipTalesDiscord.java b/src/main/java/net/turniptales/discord/TurnipTalesDiscord.java index 8662e14..3177c6b 100644 --- a/src/main/java/net/turniptales/discord/TurnipTalesDiscord.java +++ b/src/main/java/net/turniptales/discord/TurnipTalesDiscord.java @@ -11,6 +11,7 @@ import net.turniptales.discord.buttons.TicketCloseButton; import net.turniptales.discord.buttons.TicketCloseConfirmButton; import net.turniptales.discord.buttons.TicketCreateButton; +import net.turniptales.discord.buttons.TicketVoiceButton; import net.turniptales.discord.commands.GiveawayCommand; import net.turniptales.discord.commands.MessageCommand; import net.turniptales.discord.commands.RolesCommand; @@ -85,7 +86,8 @@ private static void startDiscordBot() throws InterruptedException { new TicketCloseAbortButton(), new TicketCloseButton(), new TicketCloseConfirmButton(), - new TicketCreateButton() + new TicketCreateButton(), + new TicketVoiceButton() ) .build().awaitReady(); diff --git a/src/main/java/net/turniptales/discord/buttons/TicketCloseAbortButton.java b/src/main/java/net/turniptales/discord/buttons/TicketCloseAbortButton.java index d5ef62f..dbefe4b 100644 --- a/src/main/java/net/turniptales/discord/buttons/TicketCloseAbortButton.java +++ b/src/main/java/net/turniptales/discord/buttons/TicketCloseAbortButton.java @@ -10,6 +10,7 @@ public TicketCloseAbortButton() { @Override public void onButtonClick(ButtonInteractionEvent event) { - event.getMessage().delete().queue(); + String messageId = event.getMessage().getId(); + event.getChannel().deleteMessageById(messageId).queue(); } } diff --git a/src/main/java/net/turniptales/discord/buttons/TicketCloseConfirmButton.java b/src/main/java/net/turniptales/discord/buttons/TicketCloseConfirmButton.java index 8b7a0b7..7bf012f 100644 --- a/src/main/java/net/turniptales/discord/buttons/TicketCloseConfirmButton.java +++ b/src/main/java/net/turniptales/discord/buttons/TicketCloseConfirmButton.java @@ -1,10 +1,7 @@ package net.turniptales.discord.buttons; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import java.util.Objects; - import static net.turniptales.discord.TurnipTalesDiscord.discordBotProperties; public class TicketCloseConfirmButton extends ButtonBase { @@ -15,9 +12,9 @@ public TicketCloseConfirmButton() { @Override public void onButtonClick(ButtonInteractionEvent event) { - TextChannel textChannel = event.getChannel().asTextChannel(); - if (Objects.equals(textChannel.getParentCategory(), discordBotProperties.getTicketCategory()) && textChannel.getName().startsWith("ticket-")) { - textChannel.delete().queue(); - } + String userName = event.getChannel().getName().split("-")[1]; + discordBotProperties.getTicketCategory().getChannels().stream() + .filter(guildChannel -> guildChannel.getName().startsWith("ticket-") && guildChannel.getName().contains(userName)) + .forEach(guildChannel -> guildChannel.delete().queue()); } } diff --git a/src/main/java/net/turniptales/discord/buttons/TicketCreateButton.java b/src/main/java/net/turniptales/discord/buttons/TicketCreateButton.java index 9b11210..a37adbb 100644 --- a/src/main/java/net/turniptales/discord/buttons/TicketCreateButton.java +++ b/src/main/java/net/turniptales/discord/buttons/TicketCreateButton.java @@ -16,6 +16,7 @@ import static java.util.Objects.requireNonNull; import static net.dv8tion.jda.api.Permission.VIEW_CHANNEL; import static net.dv8tion.jda.api.entities.emoji.Emoji.fromUnicode; +import static net.dv8tion.jda.api.interactions.components.buttons.Button.secondary; import static net.dv8tion.jda.api.interactions.components.buttons.Button.success; import static net.dv8tion.jda.api.interactions.components.text.TextInputStyle.PARAGRAPH; import static net.dv8tion.jda.api.interactions.modals.Modal.create; @@ -75,7 +76,7 @@ public void onModalInteraction(ModalInteractionEvent event) { .sendMessage("Hey " + member.getAsMention() + "! Danke dass du ein Ticket erstellt hast. Die " + supporterRole.getAsMention() + " und " + moderatorRole.getAsMention() + " werden Dir schnellstmöglich deine Frage beantworten oder Dir helfen.\n" + "Spieler: " + minecraftName + "\n" + "Anliegen: " + log) - .addActionRow(success("closeTicket", "Ticket schließen").withEmoji(fromUnicode("U+1F512"))) + .addActionRow(success("btn_ticket_close", "Ticket schließen").withEmoji(fromUnicode("U+1F512")), secondary("btn_ticket_voice", "Voice-Channel erstellen").withEmoji(fromUnicode("U+1F50A"))) .queue(message -> event.reply("Du hast ein Ticket erstellt: " + message.getJumpUrl()).setEphemeral(true).queue())); } diff --git a/src/main/java/net/turniptales/discord/buttons/TicketVoiceButton.java b/src/main/java/net/turniptales/discord/buttons/TicketVoiceButton.java new file mode 100644 index 0000000..a58825b --- /dev/null +++ b/src/main/java/net/turniptales/discord/buttons/TicketVoiceButton.java @@ -0,0 +1,46 @@ +package net.turniptales.discord.buttons; + +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; + +import java.util.EnumSet; +import java.util.Optional; + +import static java.util.Objects.requireNonNull; +import static net.dv8tion.jda.api.Permission.VIEW_CHANNEL; +import static net.turniptales.discord.TurnipTalesDiscord.discordBotProperties; +import static net.turniptales.discord.common.services.UtilService.sendSelfDeletingMessage; + +public class TicketVoiceButton extends ButtonBase { + + public TicketVoiceButton() { + super("btn_ticket_voice"); + } + + @Override + public void onButtonClick(ButtonInteractionEvent event) { + Member member = event.getMember(); + + Optional optionalGuildChannel = discordBotProperties.getTicketCategory().getChannels().stream() + .filter(guildChannel -> guildChannel instanceof VoiceChannel) + .filter(guildChannel -> guildChannel.getName().equalsIgnoreCase("ticket-" + member.getUser().getName())) + .findFirst(); + + if (optionalGuildChannel.isPresent()) { + sendSelfDeletingMessage(event, "Für dieses Ticket gibt es bereits einen Voice-Channel!"); + return; + } + + String userName = requireNonNull(member).getUser().getName(); + + discordBotProperties.getTicketCategory().createVoiceChannel("ticket-" + userName) + .addPermissionOverride(discordBotProperties.getGuild().getPublicRole(), null, EnumSet.of(VIEW_CHANNEL)) + .addPermissionOverride(member, EnumSet.of(VIEW_CHANNEL), null) + .addPermissionOverride(discordBotProperties.getSeniorModeratorRole(), EnumSet.of(VIEW_CHANNEL), null) + .addPermissionOverride(discordBotProperties.getModeratorRole(), EnumSet.of(VIEW_CHANNEL), null) + .addPermissionOverride(discordBotProperties.getSupporterRole(), EnumSet.of(VIEW_CHANNEL), null) + .queue(voiceChannel -> sendSelfDeletingMessage(event, "Voice-Channel erstellt!")); + } +}