1
0
mirror of https://github.com/sciwhiz12/Janitor.git synced 2024-09-19 22:14:03 +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, RestAction<Message> build(MessageChannel channel,
SubstitutionsMap globalSubstitutions, SubstitutionsMap globalSubstitutions,
Message triggerMessage, Message triggerMessage,
boolean reply,
List<T> entries); 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) { default RestAction<Message> build(MessageChannel channel, JanitorBot bot, Message triggerMessage, List<T> entries) {
return build(channel, bot.getSubstitutions(), triggerMessage, 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())) .apply(MessageHelper.member("bot.member", ctx.getSource().getGuild().getSelfMember()))
.with("guild.command_prefix", () -> config(ctx.getSource()).forGuild(COMMAND_PREFIX)) .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; return 1;
}); });
} }

View File

@ -29,6 +29,7 @@ public class ShutdownCommand extends BaseCommand {
.getMessage() .getMessage()
.getChannel() .getChannel()
.sendMessage("Shutting down, in accordance with the owner's command. Goodbye all!") .sendMessage("Shutting down, in accordance with the owner's command. Goodbye all!")
.reference(ctx.getSource().getMessage())
.submit() .submit()
.whenComplete(Util.handle( .whenComplete(Util.handle(
success -> JANITOR.debug("Sent shutdown message to channel {}", Util.toString(ctx.getSource().getAuthor())), 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) { if (memberList.size() == 1) {
final Member member = memberList.get(0); final Member member = memberList.get(0);
ctx.getSource().getChannel().sendMessage("Hello " + member.getAsMention() + "!") ctx.getSource().getChannel().sendMessage("Hello " + member.getAsMention() + "!")
.reference(ctx.getSource().getMessage())
.flatMap(message -> .flatMap(message ->
getBot().getReactions().newMessage(message) getBot().getReactions().newMessage(message)
.add("\u274C", (msg, event) -> message.delete() .add("\u274C", (msg, event) -> message.delete()

View File

@ -30,6 +30,7 @@ public class PingCommand extends BaseCommand {
.getMessage() .getMessage()
.getChannel() .getChannel()
.sendMessage(reply) .sendMessage(reply)
.reference(ctx.getSource().getMessage())
.queue( .queue(
success -> JANITOR.debug("Sent ping message to {}: {}", Util.toString(ctx.getSource().getAuthor()), reply), 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())) 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.MessageEmbed;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.requests.RestAction; 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.ListingMessage;
import sciwhiz12.janitor.api.messages.emote.ReactionMessage; import sciwhiz12.janitor.api.messages.emote.ReactionMessage;
import sciwhiz12.janitor.api.messages.substitution.ModifiableSubstitutor; import sciwhiz12.janitor.api.messages.substitution.ModifiableSubstitutor;
@ -72,14 +73,18 @@ public class ListingMessageBuilder<T> implements ListingMessage.Builder<T> {
public RestAction<Message> build(MessageChannel channel, public RestAction<Message> build(MessageChannel channel,
SubstitutionsMap globalSubstitutions, SubstitutionsMap globalSubstitutions,
Message triggerMessage, Message triggerMessage,
boolean reply,
List<T> entries) { List<T> entries) {
final ModifiableSubstitutor<?> customSubs = globalSubstitutions.with(customSubstitutions); final ModifiableSubstitutor<?> customSubs = globalSubstitutions.with(customSubstitutions);
final ImmutableList<T> list = ImmutableList.copyOf(entries); final ImmutableList<T> list = ImmutableList.copyOf(entries);
final PagedMessage pagedMessage = new PagedMessage(message, list, amountPerPage); final PagedMessage pagedMessage = new PagedMessage(message, list, amountPerPage);
return channel.sendMessage(pagedMessage.createMessage(customSubs, entryApplier)) MessageAction action = channel.sendMessage(pagedMessage.createMessage(customSubs, entryApplier));
.flatMap(listMsg -> { if (reply) {
action = action.reference(triggerMessage);
}
return action.flatMap(listMsg -> {
ReactionMessage reactionMsg = globalSubstitutions.getBot().getReactions().newMessage(listMsg) ReactionMessage reactionMsg = globalSubstitutions.getBot().getReactions().newMessage(listMsg)
.owner(triggerMessage.getAuthor().getIdLong()) .owner(triggerMessage.getAuthor().getIdLong())
.removeEmotes(true) .removeEmotes(true)

View File

@ -1,7 +1,7 @@
grgit_version=4.0.2 grgit_version=4.0.2
shadow_version=6.0.0 shadow_version=6.0.0
jda_version=4.2.0_207 jda_version=4.2.0_222
nightconfig_version=3.6.3 nightconfig_version=3.6.3
jopt_version=6.0-alpha-3 jopt_version=6.0-alpha-3
guava_version=29.0-jre guava_version=29.0-jre

View File

@ -58,7 +58,8 @@ public class BanCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -72,35 +73,41 @@ public class BanCommand extends ModBaseCommand {
if (guild.getSelfMember().equals(target)) { if (guild.getSelfMember().equals(target)) {
messages().getRegularMessage("general/error/cannot_action_self") messages().getRegularMessage("general/error/cannot_action_self")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (performer.equals(target)) { } else if (performer.equals(target)) {
messages().getRegularMessage("general/error/cannot_action_performer") messages().getRegularMessage("general/error/cannot_action_performer")
.apply(MessageHelper.member("performer", 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)) { } else if (!guild.getSelfMember().hasPermission(BAN_PERMISSION)) {
messages().getRegularMessage("general/error/insufficient_permissions") messages().getRegularMessage("general/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", BAN_PERMISSION::toString) .with("required_permissions", BAN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!guild.getSelfMember().canInteract(target)) { } else if (!guild.getSelfMember().canInteract(target)) {
messages().getRegularMessage("general/error/cannot_interact") messages().getRegularMessage("general/error/cannot_interact")
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.hasPermission(BAN_PERMISSION)) { } else if (!performer.hasPermission(BAN_PERMISSION)) {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", BAN_PERMISSION::toString) .with("required_permissions", BAN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.canInteract(target)) { } else if (!performer.canInteract(target)) {
messages().getRegularMessage("moderation/error/cannot_interact") messages().getRegularMessage("moderation/error/cannot_interact")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
target.getUser().openPrivateChannel() target.getUser().openPrivateChannel()
@ -120,6 +127,7 @@ public class BanCommand extends ModBaseCommand {
.with("delete_duration", () -> String.valueOf(days)) .with("delete_duration", () -> String.valueOf(days))
.with("reason", () -> reason) .with("reason", () -> reason)
.send(getBot(), channel) .send(getBot(), channel)
.reference(ctx.getSource().getMessage())
) )
) )
.queue(); .queue();

View File

@ -51,7 +51,8 @@ public class KickCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -65,35 +66,41 @@ public class KickCommand extends ModBaseCommand {
if (guild.getSelfMember().equals(target)) { if (guild.getSelfMember().equals(target)) {
messages().getRegularMessage("general/error/cannot_action_self") messages().getRegularMessage("general/error/cannot_action_self")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (performer.equals(target)) { } else if (performer.equals(target)) {
messages().getRegularMessage("general/error/cannot_action_performer") messages().getRegularMessage("general/error/cannot_action_performer")
.apply(MessageHelper.member("performer", 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)) { } else if (!guild.getSelfMember().hasPermission(KICK_PERMISSION)) {
messages().getRegularMessage("general/error/insufficient_permissions") messages().getRegularMessage("general/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", KICK_PERMISSION::toString) .with("required_permissions", KICK_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!guild.getSelfMember().canInteract(target)) { } else if (!guild.getSelfMember().canInteract(target)) {
messages().getRegularMessage("general/error/cannot_interact") messages().getRegularMessage("general/error/cannot_interact")
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.hasPermission(KICK_PERMISSION)) { } else if (!performer.hasPermission(KICK_PERMISSION)) {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", KICK_PERMISSION::toString) .with("required_permissions", KICK_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.canInteract(target)) { } else if (!performer.canInteract(target)) {
messages().getRegularMessage("moderation/error/cannot_interact") messages().getRegularMessage("moderation/error/cannot_interact")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
target.getUser().openPrivateChannel() target.getUser().openPrivateChannel()
@ -111,6 +118,7 @@ public class KickCommand extends ModBaseCommand {
.with("private_message", () -> res.isSuccess() ? "\u2705" : "\u274C") .with("private_message", () -> res.isSuccess() ? "\u2705" : "\u274C")
.with("reason", () -> reason) .with("reason", () -> reason)
.send(getBot(), channel) .send(getBot(), channel)
.reference(ctx.getSource().getMessage())
) )
) )
.queue(); .queue();

View File

@ -6,6 +6,7 @@ import com.mojang.brigadier.context.CommandContext;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; 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.MessageChannel;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -50,7 +51,8 @@ public class UnbanCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return; return;
} }
@ -67,10 +69,11 @@ public class UnbanCommand extends ModBaseCommand {
if (bans.size() > 1) { if (bans.size() > 1) {
messages().getRegularMessage("general/error/ambiguous_member") messages().getRegularMessage("general/error/ambiguous_member")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (bans.size() == 1) { } 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()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return; return;
} }
@ -101,22 +105,27 @@ public class UnbanCommand extends ModBaseCommand {
if (bans.size() != 1) { if (bans.size() != 1) {
return; 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)) { if (!guild.getSelfMember().hasPermission(UNBAN_PERMISSION)) {
messages().getRegularMessage("general/error/insufficient_permissions") messages().getRegularMessage("general/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", UNBAN_PERMISSION::toString) .with("required_permissions", UNBAN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(originalMsg)
.queue();
} else if (!performer.hasPermission(UNBAN_PERMISSION)) { } else if (!performer.hasPermission(UNBAN_PERMISSION)) {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", UNBAN_PERMISSION::toString) .with("required_permissions", UNBAN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(originalMsg).queue();
} else { } else {
ModerationHelper.unbanUser(guild, target) ModerationHelper.unbanUser(guild, target)
@ -124,6 +133,7 @@ public class UnbanCommand extends ModBaseCommand {
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(MessageHelper.user("target", target)) .apply(MessageHelper.user("target", target))
.send(getBot(), channel) .send(getBot(), channel)
.reference(originalMsg)
) )
.queue(); .queue();
} }

View File

@ -99,7 +99,8 @@ public class NoteCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(user("performer", ctx.getSource().getAuthor())) .apply(user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -113,18 +114,21 @@ public class NoteCommand extends ModBaseCommand {
if (guild.getSelfMember().equals(target)) { if (guild.getSelfMember().equals(target)) {
messages().getRegularMessage("general/error/cannot_action_self") messages().getRegularMessage("general/error/cannot_action_self")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (performer.equals(target)) { } else if (performer.equals(target)) {
messages().getRegularMessage("general/error/cannot_action_performer") messages().getRegularMessage("general/error/cannot_action_performer")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.hasPermission(NOTE_PERMISSION)) { } else if (!performer.hasPermission(NOTE_PERMISSION)) {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", NOTE_PERMISSION::toString) .with("required_permissions", NOTE_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
final NoteStorage storage = getNotes(guild); final NoteStorage storage = getNotes(guild);
@ -135,7 +139,8 @@ public class NoteCommand extends ModBaseCommand {
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.with("notes_amount", () -> String.valueOf(maxAmount)) .with("notes_amount", () -> String.valueOf(maxAmount))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
final NoteEntry entry = new NoteEntry(performer.getUser(), target.getUser(), dateTime, noteContents); 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") messages().getRegularMessage("moderation/note/add")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(ModerationHelper.noteEntry("note_entry", noteID, entry)) .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()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(user("performer", ctx.getSource().getAuthor())) .apply(user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -176,7 +183,8 @@ public class NoteCommand extends ModBaseCommand {
if (guild.getSelfMember().equals(target)) { if (guild.getSelfMember().equals(target)) {
messages().getRegularMessage("general/error/cannot_interact") messages().getRegularMessage("general/error/cannot_interact")
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -199,7 +207,8 @@ public class NoteCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", NOTE_PERMISSION::toString) .with("required_permissions", NOTE_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
messages().<Map.Entry<Integer, NoteEntry>>getListingMessage("moderation/note/list") messages().<Map.Entry<Integer, NoteEntry>>getListingMessage("moderation/note/list")
@ -225,7 +234,8 @@ public class NoteCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(user("performer", ctx.getSource().getAuthor())) .apply(user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -236,7 +246,8 @@ public class NoteCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", NOTE_PERMISSION::toString) .with("required_permissions", NOTE_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
final NoteStorage storage = getNotes(guild); final NoteStorage storage = getNotes(guild);
@ -246,7 +257,8 @@ public class NoteCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/note/add") messages().getRegularMessage("moderation/note/add")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("note_id", () -> String.valueOf(noteID)) .with("note_id", () -> String.valueOf(noteID))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
storage.removeNote(noteID); storage.removeNote(noteID);
@ -254,7 +266,8 @@ public class NoteCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/note/remove") messages().getRegularMessage("moderation/note/remove")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(ModerationHelper.noteEntry("note_entry", noteID, entry)) .apply(ModerationHelper.noteEntry("note_entry", noteID, entry))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} }
} }
return 1; return 1;

View File

@ -48,7 +48,8 @@ public class UnwarnCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return; return;
} }
@ -60,7 +61,8 @@ public class UnwarnCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", WARN_PERMISSION::toString) .with("required_permissions", WARN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
final WarningStorage storage = getWarns(guild); final WarningStorage storage = getWarns(guild);
@ -71,28 +73,32 @@ public class UnwarnCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/error/unwarn/no_case_found") messages().getRegularMessage("moderation/error/unwarn/no_case_found")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("case_id", () -> String.valueOf(caseID)) .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() } else if (entry.getWarned().getIdLong() == performer.getIdLong()
&& !config(guild).forGuild(ALLOW_REMOVE_SELF_WARNINGS)) { && !config(guild).forGuild(ALLOW_REMOVE_SELF_WARNINGS)) {
messages().getRegularMessage("moderation/error/unwarn/cannot_unwarn_self") messages().getRegularMessage("moderation/error/unwarn/cannot_unwarn_self")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(ModerationHelper.warningEntry("warning_entry", caseID, entry)) .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) } else if (config(guild).forGuild(WARNS_RESPECT_MOD_ROLES)
&& (temp = guild.getMember(entry.getPerformer())) != null && !performer.canInteract(temp)) { && (temp = guild.getMember(entry.getPerformer())) != null && !performer.canInteract(temp)) {
messages().getRegularMessage("moderation/error/unwarn/cannot_remove_higher_mod") messages().getRegularMessage("moderation/error/unwarn/cannot_remove_higher_mod")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(ModerationHelper.warningEntry("warning_entry", caseID, entry)) .apply(ModerationHelper.warningEntry("warning_entry", caseID, entry))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
storage.removeWarning(caseID); storage.removeWarning(caseID);
messages().getRegularMessage("moderation/unwarn/info") messages().getRegularMessage("moderation/unwarn/info")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(ModerationHelper.warningEntry("warning_entry", caseID, entry)) .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()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(MessageHelper.user("performer", ctx.getSource().getAuthor())) .apply(MessageHelper.user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -67,30 +68,35 @@ public class WarnCommand extends ModBaseCommand {
if (guild.getSelfMember().equals(target)) { if (guild.getSelfMember().equals(target)) {
messages().getRegularMessage("general/error/cannot_action_self") messages().getRegularMessage("general/error/cannot_action_self")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (performer.equals(target)) { } else if (performer.equals(target)) {
messages().getRegularMessage("general/error/cannot_action_performer") messages().getRegularMessage("general/error/cannot_action_performer")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.hasPermission(WARN_PERMISSION)) { } else if (!performer.hasPermission(WARN_PERMISSION)) {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.with("required_permissions", WARN_PERMISSION::toString) .with("required_permissions", WARN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else if (!performer.canInteract(target)) { } else if (!performer.canInteract(target)) {
messages().getRegularMessage("moderation/error/cannot_interact") messages().getRegularMessage("moderation/error/cannot_interact")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(MessageHelper.member("target", target)) .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)) { } else if (target.hasPermission(WARN_PERMISSION) && config(guild).forGuild(ALLOW_WARN_OTHER_MODERATORS)) {
messages().getRegularMessage("moderation/error/warn/cannot_warn_mods") messages().getRegularMessage("moderation/error/warn/cannot_warn_mods")
.apply(MessageHelper.member("performer", performer)) .apply(MessageHelper.member("performer", performer))
.apply(MessageHelper.member("target", target)) .apply(MessageHelper.member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
WarningEntry entry = new WarningEntry(performer.getUser(), target.getUser(), dateTime, reason); 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)) .apply(ModerationHelper.warningEntry("warning_entry", caseId, entry))
.with("private_message", () -> res.isSuccess() ? "\u2705" : "\u274C") .with("private_message", () -> res.isSuccess() ? "\u2705" : "\u274C")
.send(getBot(), channel) .send(getBot(), channel)
.reference(ctx.getSource().getMessage())
) )
.queue(); .queue();
} }

View File

@ -63,7 +63,8 @@ public class WarnListCommand extends ModBaseCommand {
if (!ctx.getSource().isFromGuild()) { if (!ctx.getSource().isFromGuild()) {
messages().getRegularMessage("general/error/guild_only_command") messages().getRegularMessage("general/error/guild_only_command")
.apply(user("performer", ctx.getSource().getAuthor())) .apply(user("performer", ctx.getSource().getAuthor()))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -78,7 +79,8 @@ public class WarnListCommand extends ModBaseCommand {
if (guild.getSelfMember().equals(target)) { if (guild.getSelfMember().equals(target)) {
messages().getRegularMessage("general/error/cannot_interact") messages().getRegularMessage("general/error/cannot_interact")
.apply(member("target", target)) .apply(member("target", target))
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
return 1; return 1;
} }
@ -95,7 +97,8 @@ public class WarnListCommand extends ModBaseCommand {
messages().getRegularMessage("moderation/error/insufficient_permissions") messages().getRegularMessage("moderation/error/insufficient_permissions")
.apply(member("performer", performer)) .apply(member("performer", performer))
.with("required_permissions", WARN_PERMISSION::toString) .with("required_permissions", WARN_PERMISSION::toString)
.send(getBot(), channel).queue(); .send(getBot(), channel)
.reference(ctx.getSource().getMessage()).queue();
} else { } else {
messages().<Map.Entry<Integer, WarningEntry>>getListingMessage("moderation/warn/list") messages().<Map.Entry<Integer, WarningEntry>>getListingMessage("moderation/warn/list")