1
0
mirror of https://github.com/sciwhiz12/Janitor.git synced 2024-11-13 00:51:26 +00:00

Update JDA, make command reply to triggering message

This commit is contained in:
sciwhiz12 2020-11-30 14:25:31 +08:00
parent d18a0010cc
commit 92bc1bb12e
Signed by: sciwhiz12
GPG Key ID: 622CF446534317E1
14 changed files with 158 additions and 83 deletions

View File

@ -197,8 +197,19 @@ public class ListingMessage {
RestAction<Message> build(MessageChannel channel,
SubstitutionsMap globalSubstitutions,
Message triggerMessage,
boolean reply,
List<T> entries);
default RestAction<Message> build(MessageChannel channel, JanitorBot bot, Message triggerMessage, boolean reply,
List<T> entries) {
return build(channel, bot.getSubstitutions(), triggerMessage, reply, entries);
}
default RestAction<Message> build(MessageChannel channel, SubstitutionsMap globalSubstitutions, Message triggerMessage,
List<T> entries) {
return build(channel, globalSubstitutions, triggerMessage, true, entries);
}
default RestAction<Message> build(MessageChannel channel, JanitorBot bot, Message triggerMessage, List<T> entries) {
return build(channel, bot.getSubstitutions(), triggerMessage, entries);
}

View File

@ -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;
});
}

View File

@ -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())),

View File

@ -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()

View File

@ -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()))

View File

@ -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<T> implements ListingMessage.Builder<T> {
public RestAction<Message> build(MessageChannel channel,
SubstitutionsMap globalSubstitutions,
Message triggerMessage,
boolean reply,
List<T> entries) {
final ModifiableSubstitutor<?> customSubs = globalSubstitutions.with(customSubstitutions);
final ImmutableList<T> 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<T> implements ListingMessage.Builder<T> {
}
});
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 {

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -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();
}

View File

@ -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().<Map.Entry<Integer, NoteEntry>>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;

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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().<Map.Entry<Integer, WarningEntry>>getListingMessage("moderation/warn/list")