Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.javadiscord.javabot.data.config.BotConfig;
Expand Down Expand Up @@ -52,7 +51,7 @@ protected WebhookMessageCreateAction<Message> handleModerationUserCommand(@Nonnu
if (!Checks.hasPermission(event.getGuild(), Permission.BAN_MEMBERS)) {
return Responses.replyInsufficientPermissions(event.getHook(), Permission.BAN_MEMBERS);
}
boolean quiet = event.getOption("quiet", false, OptionMapping::getAsBoolean);
boolean quiet = isQuiet(event);
ModerationService service = new ModerationService(notificationService, botConfig, event.getInteraction(), warnRepository, asyncPool);
service.ban(target, reason, commandUser, event.getChannel(), quiet);
return Responses.success(event.getHook(), "User Banned", "%s has been banned.", target.getAsMention());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.javadiscord.javabot.data.config.BotConfig;
Expand Down Expand Up @@ -52,7 +51,7 @@ protected WebhookMessageCreateAction<Message> handleModerationUserCommand(@Nonnu
if (!Checks.hasPermission(event.getGuild(), Permission.KICK_MEMBERS)) {
return Responses.replyInsufficientPermissions(event.getHook(), Permission.KICK_MEMBERS);
}
boolean quiet = event.getOption("quiet", false, OptionMapping::getAsBoolean);
boolean quiet = isQuiet(event);
ModerationService service = new ModerationService(notificationService, botConfig, event.getInteraction(), warnRepository, asyncPool);
service.kick(target, reason, event.getMember(), event.getChannel(), quiet);
return Responses.success(event.getHook(), "User Kicked", "%s has been kicked.", target.getAsMention());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,33 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter
}

protected abstract WebhookMessageCreateAction<Message> handleModerationUserCommand(@Nonnull SlashCommandInteractionEvent event, @Nonnull Member commandUser, @Nonnull User target, @Nullable String reason);

/**
* Determines whether this command is executed quitely.
*
* If it is, no (public) response should be sent in the current channel. This does not effect logging.
*
* By default, moderative actions in the log channel are quiet.
* @param event The {@link SlashCommandInteractionEvent} corresponding to the executed command
* @return {@code true} iff the command is quiet, else {@code false}
*/
protected boolean isQuiet(SlashCommandInteractionEvent event) {
return isQuiet(botConfig, event);
}

/**
* Determines whether this command is executed quitely.
*
* If it is, no (public) response should be sent in the current channel. This does not effect logging.
*
* By default, moderative actions in the log channel are quiet.
* @param botConfig the main configuration of the bot
* @param event The {@link SlashCommandInteractionEvent} corresponding to the executed command
* @return {@code true} iff the command is quiet, else {@code false}
*/
public static boolean isQuiet(BotConfig botConfig, SlashCommandInteractionEvent event) {
return event.getOption("quiet",
() -> event.getChannel().getIdLong() == botConfig.get(event.getGuild()).getModerationConfig().getLogChannelId(),
OptionMapping::getAsBoolean);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public UnbanCommand(NotificationService notificationService, BotConfig botConfig
setModerationSlashCommandData(Commands.slash("unban", "Unbans a member")
.addOption(OptionType.STRING, "id", "The id of the user you want to unban", true)
.addOption(OptionType.STRING, "reason", "The reason for unbanning this user", true)
.addOption(OptionType.BOOLEAN, "quiet", "If true, don't send a message in the server channel where the unban is issued.", false)
);
}

Expand All @@ -51,7 +52,7 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter
return Responses.replyMissingArguments(event);
}
long id = idOption.getAsLong();
boolean quiet = event.getOption("quiet", false, OptionMapping::getAsBoolean);
boolean quiet = ModerateUserCommand.isQuiet(botConfig, event);
ModerationService service = new ModerationService(notificationService, botConfig, event.getInteraction(), warnRepository, asyncPool);
if (service.unban(id, reasonOption.getAsString(), event.getMember(), event.getChannel(), quiet)) {
return Responses.success(event, "User Unbanned", "User with id `%s` has been unbanned.", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import net.javadiscord.javabot.data.config.BotConfig;
import net.javadiscord.javabot.systems.moderation.ModerateUserCommand;
import net.javadiscord.javabot.systems.moderation.ModerationService;
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
import net.javadiscord.javabot.systems.notification.NotificationService;
Expand Down Expand Up @@ -75,7 +76,7 @@ protected ReplyCallbackAction handleTimeoutCommand(@NotNull SlashCommandInteract
return Responses.error(event, "This command can only be performed in a server message channel.");
}
MessageChannel channel = event.getMessageChannel();
boolean quiet = event.getOption("quiet", false, OptionMapping::getAsBoolean);
boolean quiet = ModerateUserCommand.isQuiet(botConfig, event);
if (member.isTimedOut()) {
return Responses.error(event, "Could not timeout %s; they're already timed out.", member.getAsMention());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import net.javadiscord.javabot.data.config.BotConfig;
import net.javadiscord.javabot.systems.moderation.ModerateUserCommand;
import net.javadiscord.javabot.systems.moderation.ModerationService;
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
import net.javadiscord.javabot.systems.notification.NotificationService;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected ReplyCallbackAction handleTimeoutCommand(@NotNull SlashCommandInteract
if (!channel.getType().isMessage()) {
return Responses.error(event, "This command can only be performed in a server message channel.");
}
boolean quiet = event.getOption("quiet", false, OptionMapping::getAsBoolean);
boolean quiet = ModerateUserCommand.isQuiet(botConfig, event);
if (!member.isTimedOut()) {
return Responses.error(event, "Could not remove timeout from member %s; they're not timed out.", member.getAsMention());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.javadiscord.javabot.systems.moderation.ModerationService;
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
import net.javadiscord.javabot.systems.notification.NotificationService;
import net.javadiscord.javabot.util.Checks;
import net.javadiscord.javabot.util.Responses;

import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -54,6 +55,10 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
Responses.replyGuildOnly(event).queue();
return;
}
if(!Checks.hasStaffRole(botConfig, event.getMember())) {
Responses.replyStaffOnly(event, botConfig.get(event.getGuild())).queue();
return;
}
User target = userMapping.getAsUser();
new ModerationService(notificationService, botConfig, event.getInteraction(), warnRepository, asyncPool).discardAllWarns(target, event.getMember());
Responses.success(event, "Warns Discarded", "Successfully discarded all warns from **%s**.", UserUtils.getUserTag(target)).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.javadiscord.javabot.systems.moderation.ModerationService;
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
import net.javadiscord.javabot.systems.notification.NotificationService;
import net.javadiscord.javabot.util.Checks;
import net.javadiscord.javabot.util.Responses;

import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -52,6 +53,10 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
Responses.replyGuildOnly(event).queue();
return;
}
if(!Checks.hasStaffRole(botConfig, event.getMember())) {
Responses.replyStaffOnly(event, botConfig.get(event.getGuild())).queue();
return;
}
int id = idMapping.getAsInt();
ModerationService service = new ModerationService(notificationService, botConfig, event, warnRepository, asyncPool);
if (service.discardWarnById(id, event.getUser())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.javadiscord.javabot.data.config.BotConfig;
import net.javadiscord.javabot.systems.moderation.ModerateUserCommand;
import net.javadiscord.javabot.systems.moderation.ModerationService;
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
import net.javadiscord.javabot.systems.moderation.warn.model.WarnSeverity;
import net.javadiscord.javabot.systems.notification.NotificationService;
import net.javadiscord.javabot.util.Checks;
import net.javadiscord.javabot.util.Responses;

import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -66,13 +68,17 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
Responses.replyGuildOnly(event).queue();
return;
}
if(!Checks.hasStaffRole(botConfig, event.getMember())) {
Responses.replyStaffOnly(event, botConfig.get(event.getGuild())).queue();
return;
}
User target = userMapping.getAsUser();
WarnSeverity severity = WarnSeverity.valueOf(severityMapping.getAsString().trim().toUpperCase());
if (target.isBot()) {
Responses.warning(event, "You cannot warn bots.").queue();
return;
}
boolean quiet = event.getOption("quiet", false, OptionMapping::getAsBoolean);
boolean quiet = ModerateUserCommand.isQuiet(botConfig, event);
ModerationService service = new ModerationService(notificationService, botConfig, event, warnRepository, asyncPool);
service.warn(target, severity, reasonMapping.getAsString(), event.getMember(), event.getChannel(), quiet);
Responses.success(event, "User Warned", "%s has been successfully warned.", target.getAsMention()).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
import net.javadiscord.javabot.systems.moderation.warn.model.Warn;
import net.javadiscord.javabot.systems.notification.NotificationService;
import net.javadiscord.javabot.util.Checks;
import net.javadiscord.javabot.util.ExceptionLogger;
import net.javadiscord.javabot.util.Responses;

Expand Down Expand Up @@ -71,6 +72,10 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
Responses.replyGuildOnly(event).queue();
return;
}
if(!Checks.hasStaffRole(botConfig, event.getMember())) {
Responses.replyStaffOnly(event, botConfig.get(event.getGuild())).queue();
return;
}
User target = userMapping.getAsUser();
ModerationService service = new ModerationService(notificationService, botConfig, event, warnRepository, asyncPool);
List<Warn> warns = service.getAllWarns(target.getIdLong());
Expand Down