diff --git a/embeds.json b/embeds.json index c9f6096..2462b84 100644 --- a/embeds.json +++ b/embeds.json @@ -319,7 +319,6 @@ "description": "Du hast eine Lootbox :coin: gefunden und einen besonders wertvollen Inhalt gezogen: {item}", "color": "#67c94f" }, - "rankDecrease": { "title": ":arrow_down: Stufenabstieg!", "description": "{user}", @@ -359,5 +358,10 @@ "title": "Hinweis", "description": "Text-Befehle wurden deaktiviert. Du kannst stattdessen einfach `/` eingeben, um eine Übersicht über alle Befehle zu erhalten.", "color": "#67c94f" -} + }, + "memberExcluded": { + "title": "Okay", + "description": "Der Nutzer wurde vom Contest-Event ausgeschlossen", + "color": "#67c94f" + } } diff --git a/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestEventService.java b/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestEventService.java index 10735ed..52c2c06 100644 --- a/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestEventService.java +++ b/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestEventService.java @@ -176,6 +176,17 @@ public void decreaseVoteCount(long messageId, long userId) { } } + public void setVoteCount(long messageId, int count) { + try (Connection connection = dataSource.getConnection()) { + var statement = connection.prepareStatement("UPDATE contest_entries SET votes = ? where message_id = ?"); + statement.setLong(1, count); + statement.setLong(2, messageId); + statement.execute(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + public record ContestLeaderboardRow(int votes, long userId) { } diff --git a/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestListener.java b/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestListener.java index 2597ecf..c04ccb3 100644 --- a/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestListener.java +++ b/src/main/java/com/github/kaktushose/nplaybot/events/contest/ContestListener.java @@ -53,7 +53,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { @Override public void onMessageDelete(@NotNull MessageDeleteEvent event) { - eventService.deleteContestEntry(event.getMessageIdLong()); + eventService.setVoteCount(event.getMessageIdLong(), 0); } @Override diff --git a/src/main/java/com/github/kaktushose/nplaybot/events/contest/MemberExcludeCommand.java b/src/main/java/com/github/kaktushose/nplaybot/events/contest/MemberExcludeCommand.java new file mode 100644 index 0000000..7fd29ac --- /dev/null +++ b/src/main/java/com/github/kaktushose/nplaybot/events/contest/MemberExcludeCommand.java @@ -0,0 +1,32 @@ +package com.github.kaktushose.nplaybot.events.contest; + +import com.github.kaktushose.jda.commands.annotations.Inject; +import com.github.kaktushose.jda.commands.annotations.interactions.ContextCommand; +import com.github.kaktushose.jda.commands.annotations.interactions.Interaction; +import com.github.kaktushose.jda.commands.annotations.interactions.Permissions; +import com.github.kaktushose.jda.commands.data.EmbedCache; +import com.github.kaktushose.jda.commands.dispatching.interactions.commands.CommandEvent; +import com.github.kaktushose.nplaybot.Database; +import com.github.kaktushose.nplaybot.permissions.BotPermissions; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.interactions.commands.Command; + +@Interaction +@Permissions(BotPermissions.MODIFY_USER_BALANCE) +public class MemberExcludeCommand { + + @Inject + private Database database; + @Inject + private EmbedCache embedCache; + + @ContextCommand(value = "Vom Contest ausschließen", type = Command.Type.MESSAGE, isGuildOnly = true, ephemeral = true, enabledFor = Permission.BAN_MEMBERS) + public void onRemoveContestPost(CommandEvent event, Message message) { + database.getContestEventService().setVoteCount(message.getIdLong(), 0); + message.delete().queue(); + event.getGuild().addRoleToMember(message.getAuthor(), message.getGuild().getRoleById(885530505192284210L)).queue(); + event.reply(embedCache.getEmbed("memberExcluded")); + } + +}