Skip to content

Commit

Permalink
temp fix: improve contest event moderation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaktushose committed Jul 10, 2024
1 parent c5814e9 commit 003cfef
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
8 changes: 6 additions & 2 deletions embeds.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}

}

0 comments on commit 003cfef

Please sign in to comment.