use of com.sx4.bot.entities.mod.action.ModAction in project Sx4 by sx4-discord-bot.
the class MuteCommand method leaveAction.
@Command(value = "leave action", aliases = { "leaveaction" }, description = "Set an action to occur when a user leaves and rejoins while muted")
@CommandId(451)
@Examples({ "mute leave action BAN", "mute leave action MUTE_EXTEND 24h", "mute leave action reset" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void leaveAction(Sx4CommandEvent event, @Argument(value = "action | reset", endless = true) @AlternativeOptions({ "reset" }) @EnumOptions(value = { "KICK", "UNBAN", "UNMUTE" }, exclude = true) Alternative<TimedArgument<ModAction>> option) {
Bson update;
if (option.isAlternative()) {
update = Updates.unset("mute.leaveAction");
} else {
TimedArgument<ModAction> timedAction = option.getValue();
ModAction action = timedAction.getArgument();
Document modAction = new Document("type", action.getType());
if (action.isTimed()) {
Duration duration = timedAction.getDuration();
if (duration == null) {
event.replyFailure("You need to provide a duration for this mod action").queue();
return;
}
modAction.append("duration", duration.toSeconds());
}
update = Updates.set("mute.leaveAction", modAction);
}
event.getMongo().updateGuildById(event.getGuild().getIdLong(), update).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0 && result.getUpsertedId() == null) {
event.replyFailure("Your leave action was already " + (option.isAlternative() ? "unset" : "set to that")).queue();
return;
}
event.replySuccess("Your leave action has been " + (option.isAlternative() ? "unset" : "updated")).queue();
});
}
Aggregations