From 92bc1bb12e8bc9f653c0ffeb37e58dfa74e5c069 Mon Sep 17 00:00:00 2001 From: sciwhiz12 Date: Mon, 30 Nov 2020 14:25:31 +0800 Subject: [PATCH] Update JDA, make command reply to triggering message --- .../janitor/api/messages/ListingMessage.java | 11 +++ .../janitor/commands/bot/AboutCommand.java | 3 +- .../janitor/commands/bot/ShutdownCommand.java | 1 + .../janitor/commands/misc/HelloCommand.java | 1 + .../janitor/commands/misc/PingCommand.java | 1 + .../messages/ListingMessageBuilder.java | 67 ++++++++++--------- gradle.properties | 2 +- .../janitor/moderation/BanCommand.java | 22 ++++-- .../janitor/moderation/KickCommand.java | 22 ++++-- .../janitor/moderation/UnbanCommand.java | 26 ++++--- .../janitor/moderation/notes/NoteCommand.java | 39 +++++++---- .../moderation/warns/UnwarnCommand.java | 18 +++-- .../janitor/moderation/warns/WarnCommand.java | 19 ++++-- .../moderation/warns/WarnListCommand.java | 9 ++- 14 files changed, 158 insertions(+), 83 deletions(-) diff --git a/core/src/api/java/sciwhiz12/janitor/api/messages/ListingMessage.java b/core/src/api/java/sciwhiz12/janitor/api/messages/ListingMessage.java index 45cecbf..a8871c1 100644 --- a/core/src/api/java/sciwhiz12/janitor/api/messages/ListingMessage.java +++ b/core/src/api/java/sciwhiz12/janitor/api/messages/ListingMessage.java @@ -197,8 +197,19 @@ public class ListingMessage { RestAction build(MessageChannel channel, SubstitutionsMap globalSubstitutions, Message triggerMessage, + boolean reply, List entries); + default RestAction build(MessageChannel channel, JanitorBot bot, Message triggerMessage, boolean reply, + List entries) { + return build(channel, bot.getSubstitutions(), triggerMessage, reply, entries); + } + + default RestAction build(MessageChannel channel, SubstitutionsMap globalSubstitutions, Message triggerMessage, + List entries) { + return build(channel, globalSubstitutions, triggerMessage, true, entries); + } + default RestAction build(MessageChannel channel, JanitorBot bot, Message triggerMessage, List entries) { return build(channel, bot.getSubstitutions(), triggerMessage, entries); } diff --git a/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java b/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java index 32e49e5..6d21ded 100644 --- a/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java +++ b/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java @@ -36,7 +36,8 @@ public class AboutCommand extends BaseCommand { ) .apply(MessageHelper.member("bot.member", ctx.getSource().getGuild().getSelfMember())) .with("guild.command_prefix", () -> config(ctx.getSource()).forGuild(COMMAND_PREFIX)) - .send(getBot(), ctx.getSource().getChannel()).queue(); + .send(getBot(), ctx.getSource().getChannel()) + .reference(ctx.getSource().getMessage()).queue(); return 1; }); } diff --git a/core/src/main/java/sciwhiz12/janitor/commands/bot/ShutdownCommand.java b/core/src/main/java/sciwhiz12/janitor/commands/bot/ShutdownCommand.java index ce00661..27ebe02 100644 --- a/core/src/main/java/sciwhiz12/janitor/commands/bot/ShutdownCommand.java +++ b/core/src/main/java/sciwhiz12/janitor/commands/bot/ShutdownCommand.java @@ -29,6 +29,7 @@ public class ShutdownCommand extends BaseCommand { .getMessage() .getChannel() .sendMessage("Shutting down, in accordance with the owner's command. Goodbye all!") + .reference(ctx.getSource().getMessage()) .submit() .whenComplete(Util.handle( success -> JANITOR.debug("Sent shutdown message to channel {}", Util.toString(ctx.getSource().getAuthor())), diff --git a/core/src/main/java/sciwhiz12/janitor/commands/misc/HelloCommand.java b/core/src/main/java/sciwhiz12/janitor/commands/misc/HelloCommand.java index 0303146..b1e618d 100644 --- a/core/src/main/java/sciwhiz12/janitor/commands/misc/HelloCommand.java +++ b/core/src/main/java/sciwhiz12/janitor/commands/misc/HelloCommand.java @@ -35,6 +35,7 @@ public class HelloCommand extends BaseCommand { if (memberList.size() == 1) { final Member member = memberList.get(0); ctx.getSource().getChannel().sendMessage("Hello " + member.getAsMention() + "!") + .reference(ctx.getSource().getMessage()) .flatMap(message -> getBot().getReactions().newMessage(message) .add("\u274C", (msg, event) -> message.delete() diff --git a/core/src/main/java/sciwhiz12/janitor/commands/misc/PingCommand.java b/core/src/main/java/sciwhiz12/janitor/commands/misc/PingCommand.java index 0bfd17a..385fd28 100644 --- a/core/src/main/java/sciwhiz12/janitor/commands/misc/PingCommand.java +++ b/core/src/main/java/sciwhiz12/janitor/commands/misc/PingCommand.java @@ -30,6 +30,7 @@ public class PingCommand extends BaseCommand { .getMessage() .getChannel() .sendMessage(reply) + .reference(ctx.getSource().getMessage()) .queue( success -> JANITOR.debug("Sent ping message to {}: {}", Util.toString(ctx.getSource().getAuthor()), reply), err -> JANITOR.error("Error while sending ping message to {}", Util.toString(ctx.getSource().getAuthor())) diff --git a/core/src/main/java/sciwhiz12/janitor/messages/ListingMessageBuilder.java b/core/src/main/java/sciwhiz12/janitor/messages/ListingMessageBuilder.java index e3375b2..557eb64 100644 --- a/core/src/main/java/sciwhiz12/janitor/messages/ListingMessageBuilder.java +++ b/core/src/main/java/sciwhiz12/janitor/messages/ListingMessageBuilder.java @@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.MessageAction; import sciwhiz12.janitor.api.messages.ListingMessage; import sciwhiz12.janitor.api.messages.emote.ReactionMessage; import sciwhiz12.janitor.api.messages.substitution.ModifiableSubstitutor; @@ -72,41 +73,23 @@ public class ListingMessageBuilder implements ListingMessage.Builder { public RestAction build(MessageChannel channel, SubstitutionsMap globalSubstitutions, Message triggerMessage, + boolean reply, List entries) { final ModifiableSubstitutor customSubs = globalSubstitutions.with(customSubstitutions); final ImmutableList list = ImmutableList.copyOf(entries); final PagedMessage pagedMessage = new PagedMessage(message, list, amountPerPage); - return channel.sendMessage(pagedMessage.createMessage(customSubs, entryApplier)) - .flatMap(listMsg -> { - ReactionMessage reactionMsg = globalSubstitutions.getBot().getReactions().newMessage(listMsg) - .owner(triggerMessage.getAuthor().getIdLong()) - .removeEmotes(true) - .add("\u2b05", (msg, event) -> { // PREVIOUS - if (pagedMessage.advancePage(PageDirection.PREVIOUS)) { - event.retrieveMessage() - .flatMap(eventMsg -> eventMsg.editMessage( - pagedMessage.createMessage(customSubs, entryApplier)) - ) - .queue(); - } - }); - - if (addDeletionReaction) { - reactionMsg.add("\u274c", (msg, event) -> { // CLOSE - event.getChannel().deleteMessageById(event.getMessageIdLong()) - .flatMap(v -> !triggerMessage.isFromGuild() || - event.getGuild().getSelfMember() - .hasPermission(triggerMessage.getTextChannel(), - Permission.MESSAGE_MANAGE), - v -> triggerMessage.delete()) - .queue(); - }); - } - - reactionMsg.add("\u27a1", (msg, event) -> { // NEXT - if (pagedMessage.advancePage(PageDirection.NEXT)) { + MessageAction action = channel.sendMessage(pagedMessage.createMessage(customSubs, entryApplier)); + if (reply) { + action = action.reference(triggerMessage); + } + return action.flatMap(listMsg -> { + ReactionMessage reactionMsg = globalSubstitutions.getBot().getReactions().newMessage(listMsg) + .owner(triggerMessage.getAuthor().getIdLong()) + .removeEmotes(true) + .add("\u2b05", (msg, event) -> { // PREVIOUS + if (pagedMessage.advancePage(PageDirection.PREVIOUS)) { event.retrieveMessage() .flatMap(eventMsg -> eventMsg.editMessage( pagedMessage.createMessage(customSubs, entryApplier)) @@ -115,9 +98,31 @@ public class ListingMessageBuilder implements ListingMessage.Builder { } }); - return reactionMsg.create(listMsg); + if (addDeletionReaction) { + reactionMsg.add("\u274c", (msg, event) -> { // CLOSE + event.getChannel().deleteMessageById(event.getMessageIdLong()) + .flatMap(v -> !triggerMessage.isFromGuild() || + event.getGuild().getSelfMember() + .hasPermission(triggerMessage.getTextChannel(), + Permission.MESSAGE_MANAGE), + v -> triggerMessage.delete()) + .queue(); + }); } - ); + + reactionMsg.add("\u27a1", (msg, event) -> { // NEXT + if (pagedMessage.advancePage(PageDirection.NEXT)) { + event.retrieveMessage() + .flatMap(eventMsg -> eventMsg.editMessage( + pagedMessage.createMessage(customSubs, entryApplier)) + ) + .queue(); + } + }); + + return reactionMsg.create(listMsg); + } + ); } class PagedMessage { diff --git a/gradle.properties b/gradle.properties index 90fffd0..2812c93 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ grgit_version=4.0.2 shadow_version=6.0.0 -jda_version=4.2.0_207 +jda_version=4.2.0_222 nightconfig_version=3.6.3 jopt_version=6.0-alpha-3 guava_version=29.0-jre diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/BanCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/BanCommand.java index 8ba39bd..c8462ee 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/BanCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/BanCommand.java @@ -58,7 +58,8 @@ public class BanCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -72,35 +73,41 @@ public class BanCommand extends ModBaseCommand { if (guild.getSelfMember().equals(target)) { messages().getRegularMessage("general/error/cannot_action_self") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (performer.equals(target)) { messages().getRegularMessage("general/error/cannot_action_performer") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!guild.getSelfMember().hasPermission(BAN_PERMISSION)) { messages().getRegularMessage("general/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", BAN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!guild.getSelfMember().canInteract(target)) { messages().getRegularMessage("general/error/cannot_interact") .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.hasPermission(BAN_PERMISSION)) { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", BAN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.canInteract(target)) { messages().getRegularMessage("moderation/error/cannot_interact") .apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { target.getUser().openPrivateChannel() @@ -120,6 +127,7 @@ public class BanCommand extends ModBaseCommand { .with("delete_duration", () -> String.valueOf(days)) .with("reason", () -> reason) .send(getBot(), channel) + .reference(ctx.getSource().getMessage()) ) ) .queue(); diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/KickCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/KickCommand.java index ea565b1..eaf210e 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/KickCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/KickCommand.java @@ -51,7 +51,8 @@ public class KickCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -65,35 +66,41 @@ public class KickCommand extends ModBaseCommand { if (guild.getSelfMember().equals(target)) { messages().getRegularMessage("general/error/cannot_action_self") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (performer.equals(target)) { messages().getRegularMessage("general/error/cannot_action_performer") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!guild.getSelfMember().hasPermission(KICK_PERMISSION)) { messages().getRegularMessage("general/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", KICK_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!guild.getSelfMember().canInteract(target)) { messages().getRegularMessage("general/error/cannot_interact") .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.hasPermission(KICK_PERMISSION)) { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", KICK_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.canInteract(target)) { messages().getRegularMessage("moderation/error/cannot_interact") .apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { target.getUser().openPrivateChannel() @@ -111,6 +118,7 @@ public class KickCommand extends ModBaseCommand { .with("private_message", () -> res.isSuccess() ? "\u2705" : "\u274C") .with("reason", () -> reason) .send(getBot(), channel) + .reference(ctx.getSource().getMessage()) ) ) .queue(); diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/UnbanCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/UnbanCommand.java index 6b2c1f8..6ca8496 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/UnbanCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/UnbanCommand.java @@ -6,6 +6,7 @@ import com.mojang.brigadier.context.CommandContext; 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.Message; import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -50,7 +51,8 @@ public class UnbanCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return; } @@ -67,10 +69,11 @@ public class UnbanCommand extends ModBaseCommand { if (bans.size() > 1) { messages().getRegularMessage("general/error/ambiguous_member") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (bans.size() == 1) { - tryUnban(channel, guild, performer, bans.get(0).getUser()); + tryUnban(ctx.getSource().getMessage(), performer, bans.get(0).getUser()); } }); } @@ -85,7 +88,8 @@ public class UnbanCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return; } @@ -101,22 +105,27 @@ public class UnbanCommand extends ModBaseCommand { if (bans.size() != 1) { return; } - tryUnban(channel, guild, performer, bans.get(0).getUser()); + tryUnban(ctx.getSource().getMessage(), performer, bans.get(0).getUser()); }); } - void tryUnban(MessageChannel channel, Guild guild, Member performer, User target) { + void tryUnban(Message originalMsg, Member performer, User target) { + final MessageChannel channel = originalMsg.getChannel(); + final Guild guild = performer.getGuild(); if (!guild.getSelfMember().hasPermission(UNBAN_PERMISSION)) { messages().getRegularMessage("general/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", UNBAN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(originalMsg) + .queue(); } else if (!performer.hasPermission(UNBAN_PERMISSION)) { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", UNBAN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(originalMsg).queue(); } else { ModerationHelper.unbanUser(guild, target) @@ -124,6 +133,7 @@ public class UnbanCommand extends ModBaseCommand { .apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.user("target", target)) .send(getBot(), channel) + .reference(originalMsg) ) .queue(); } diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/notes/NoteCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/notes/NoteCommand.java index 95d670e..466fb02 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/notes/NoteCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/notes/NoteCommand.java @@ -99,7 +99,8 @@ public class NoteCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -113,18 +114,21 @@ public class NoteCommand extends ModBaseCommand { if (guild.getSelfMember().equals(target)) { messages().getRegularMessage("general/error/cannot_action_self") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (performer.equals(target)) { messages().getRegularMessage("general/error/cannot_action_performer") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.hasPermission(NOTE_PERMISSION)) { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", NOTE_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { final NoteStorage storage = getNotes(guild); @@ -135,7 +139,8 @@ public class NoteCommand extends ModBaseCommand { .apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("target", target)) .with("notes_amount", () -> String.valueOf(maxAmount)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { final NoteEntry entry = new NoteEntry(performer.getUser(), target.getUser(), dateTime, noteContents); @@ -144,7 +149,8 @@ public class NoteCommand extends ModBaseCommand { messages().getRegularMessage("moderation/note/add") .apply(MessageHelper.member("performer", performer)) .apply(ModerationHelper.noteEntry("note_entry", noteID, entry)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } } @@ -161,7 +167,8 @@ public class NoteCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -176,7 +183,8 @@ public class NoteCommand extends ModBaseCommand { if (guild.getSelfMember().equals(target)) { messages().getRegularMessage("general/error/cannot_interact") .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -199,7 +207,8 @@ public class NoteCommand extends ModBaseCommand { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", NOTE_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { messages().>getListingMessage("moderation/note/list") @@ -225,7 +234,8 @@ public class NoteCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -236,7 +246,8 @@ public class NoteCommand extends ModBaseCommand { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", NOTE_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { final NoteStorage storage = getNotes(guild); @@ -246,7 +257,8 @@ public class NoteCommand extends ModBaseCommand { messages().getRegularMessage("moderation/note/add") .apply(MessageHelper.member("performer", performer)) .with("note_id", () -> String.valueOf(noteID)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { storage.removeNote(noteID); @@ -254,7 +266,8 @@ public class NoteCommand extends ModBaseCommand { messages().getRegularMessage("moderation/note/remove") .apply(MessageHelper.member("performer", performer)) .apply(ModerationHelper.noteEntry("note_entry", noteID, entry)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } } return 1; diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/UnwarnCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/UnwarnCommand.java index 644f678..2d8e422 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/UnwarnCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/UnwarnCommand.java @@ -48,7 +48,8 @@ public class UnwarnCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return; } @@ -60,7 +61,8 @@ public class UnwarnCommand extends ModBaseCommand { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", WARN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { final WarningStorage storage = getWarns(guild); @@ -71,28 +73,32 @@ public class UnwarnCommand extends ModBaseCommand { messages().getRegularMessage("moderation/error/unwarn/no_case_found") .apply(MessageHelper.member("performer", performer)) .with("case_id", () -> String.valueOf(caseID)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (entry.getWarned().getIdLong() == performer.getIdLong() && !config(guild).forGuild(ALLOW_REMOVE_SELF_WARNINGS)) { messages().getRegularMessage("moderation/error/unwarn/cannot_unwarn_self") .apply(MessageHelper.member("performer", performer)) .apply(ModerationHelper.warningEntry("warning_entry", caseID, entry)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (config(guild).forGuild(WARNS_RESPECT_MOD_ROLES) && (temp = guild.getMember(entry.getPerformer())) != null && !performer.canInteract(temp)) { messages().getRegularMessage("moderation/error/unwarn/cannot_remove_higher_mod") .apply(MessageHelper.member("performer", performer)) .apply(ModerationHelper.warningEntry("warning_entry", caseID, entry)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { storage.removeWarning(caseID); messages().getRegularMessage("moderation/unwarn/info") .apply(MessageHelper.member("performer", performer)) .apply(ModerationHelper.warningEntry("warning_entry", caseID, entry)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } } diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnCommand.java index b69be2a..7a7b0bd 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnCommand.java @@ -52,7 +52,8 @@ public class WarnCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -67,30 +68,35 @@ public class WarnCommand extends ModBaseCommand { if (guild.getSelfMember().equals(target)) { messages().getRegularMessage("general/error/cannot_action_self") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (performer.equals(target)) { messages().getRegularMessage("general/error/cannot_action_performer") .apply(MessageHelper.member("performer", performer)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.hasPermission(WARN_PERMISSION)) { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(MessageHelper.member("performer", performer)) .with("required_permissions", WARN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (!performer.canInteract(target)) { messages().getRegularMessage("moderation/error/cannot_interact") .apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else if (target.hasPermission(WARN_PERMISSION) && config(guild).forGuild(ALLOW_WARN_OTHER_MODERATORS)) { messages().getRegularMessage("moderation/error/warn/cannot_warn_mods") .apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { WarningEntry entry = new WarningEntry(performer.getUser(), target.getUser(), dateTime, reason); @@ -108,6 +114,7 @@ public class WarnCommand extends ModBaseCommand { .apply(ModerationHelper.warningEntry("warning_entry", caseId, entry)) .with("private_message", () -> res.isSuccess() ? "\u2705" : "\u274C") .send(getBot(), channel) + .reference(ctx.getSource().getMessage()) ) .queue(); } diff --git a/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnListCommand.java b/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnListCommand.java index 5f9c5ce..689d381 100644 --- a/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnListCommand.java +++ b/moderation/src/main/java/sciwhiz12/janitor/moderation/warns/WarnListCommand.java @@ -63,7 +63,8 @@ public class WarnListCommand extends ModBaseCommand { if (!ctx.getSource().isFromGuild()) { messages().getRegularMessage("general/error/guild_only_command") .apply(user("performer", ctx.getSource().getAuthor())) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -78,7 +79,8 @@ public class WarnListCommand extends ModBaseCommand { if (guild.getSelfMember().equals(target)) { messages().getRegularMessage("general/error/cannot_interact") .apply(member("target", target)) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); return 1; } @@ -95,7 +97,8 @@ public class WarnListCommand extends ModBaseCommand { messages().getRegularMessage("moderation/error/insufficient_permissions") .apply(member("performer", performer)) .with("required_permissions", WARN_PERMISSION::toString) - .send(getBot(), channel).queue(); + .send(getBot(), channel) + .reference(ctx.getSource().getMessage()).queue(); } else { messages().>getListingMessage("moderation/warn/list")