From f4eb1e79bf0de50cbc4393205c889d029e65ba83 Mon Sep 17 00:00:00 2001 From: floppydiskette Date: Sun, 22 Dec 2024 00:05:45 +0000 Subject: [PATCH] Update deps, add warn command --- pom.xml | 14 ++++++-- .../hypr/doki/commands/moderation/Warn.java | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/hypr/doki/commands/moderation/Warn.java diff --git a/pom.xml b/pom.xml index 82725dd..5ccf8f2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.hypr doki - 1.0.0 + 1.0.6 17 @@ -39,7 +39,7 @@ ch.qos.logback logback-classic - 1.5.6 + 1.5.13 org.mariadb.jdbc @@ -56,5 +56,15 @@ commons-dbutils 1.8.1 + + ch.qos.logback + logback-core + 1.5.13 + + + com.google.protobuf + protobuf-java + 4.28.2 + \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/commands/moderation/Warn.java b/src/main/java/net/hypr/doki/commands/moderation/Warn.java new file mode 100644 index 0000000..4c6be60 --- /dev/null +++ b/src/main/java/net/hypr/doki/commands/moderation/Warn.java @@ -0,0 +1,34 @@ +package net.hypr.doki.commands.moderation; + +import com.freya02.botcommands.api.annotations.BotPermissions; +import com.freya02.botcommands.api.annotations.CommandMarker; +import com.freya02.botcommands.api.annotations.UserPermissions; +import com.freya02.botcommands.api.application.ApplicationCommand; +import com.freya02.botcommands.api.application.annotations.AppOption; +import com.freya02.botcommands.api.application.slash.GuildSlashEvent; +import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; + +@CommandMarker +@BotPermissions(Permission.MODERATE_MEMBERS) +@UserPermissions(Permission.MODERATE_MEMBERS) +public class Warn extends ApplicationCommand { + @JDASlashCommand( + name = "warn", + description = "Warns a member" + ) + public void warn(GuildSlashEvent event, + @AppOption(name = "member", description = "The member to warn") Member member, + @AppOption(name = "reason", description = "The reason for warning them") String reason) { + EmbedBuilder warnEmbed = new EmbedBuilder() + .setTitle(String.format("You were warned in %s", event.getGuild().getName())) + .setDescription(String.format("**Reason:** %s", reason)); + member.getUser().openPrivateChannel().queue((dm) -> dm.sendMessageEmbeds(warnEmbed.build()).queue( + success -> event.replyFormat("Warned %s for %s", member.getAsMention(), reason).setEphemeral(true).queue(), + // User has blocked bot or disabled DMs + error -> event.replyFormat("Warned %s for %s\n-# (Unable to DM user)", member.getAsMention(), reason).queue() + )); + } +} \ No newline at end of file