use of com.sx4.bot.entities.mod.Reason in project Sx4 by sx4-discord-bot.
the class UnbanCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") String userArgument, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
SearchUtility.getBan(event.getGuild(), userArgument).whenComplete((ban, exception) -> {
if (ban == null) {
event.replyFailure("I could not find that banned user").queue();
return;
}
User user = ban.getUser();
event.getGuild().unban(user).reason(ModUtility.getAuditReason(reason, event.getAuthor())).submit().whenComplete(($, unbanException) -> {
if (unbanException instanceof ErrorResponseException && ((ErrorResponseException) unbanException).getErrorResponse() == ErrorResponse.UNKNOWN_BAN) {
event.replyFailure("That user is not banned").queue();
return;
}
event.replySuccess("**" + user.getAsTag() + "** has been unbanned").queue();
event.getBot().getModActionManager().onModAction(new UnbanEvent(event.getMember(), user, reason));
event.getBot().getTemporaryBanManager().removeBan(event.getGuild().getIdLong(), user.getIdLong(), false);
});
});
}
use of com.sx4.bot.entities.mod.Reason in project Sx4 by sx4-discord-bot.
the class UnmuteCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
long roleId = event.getMongo().getGuildById(event.getGuild().getIdLong(), Projections.include("mute.roleId")).getEmbedded(List.of("mute", "roleId"), 0L);
Role role = roleId == 0L ? null : event.getGuild().getRoleById(roleId);
if (role == null || !member.getRoles().contains(role)) {
event.replyFailure("That user is not muted").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("I am unable to unmute that user as the mute role is higher or equal than my top role").queue();
return;
}
event.getMongo().deleteMute(Filters.and(Filters.eq("userId", member.getIdLong()), Filters.eq("guildId", event.getGuild().getIdLong()))).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.getGuild().removeRoleFromMember(member, role).reason(ModUtility.getAuditReason(reason, event.getAuthor())).queue($ -> {
event.replySuccess("**" + member.getUser().getAsTag() + "** has been unmuted").queue();
event.getBot().getMuteManager().deleteExecutor(event.getGuild().getIdLong(), member.getIdLong());
event.getBot().getModActionManager().onModAction(new UnmuteEvent(event.getMember(), member.getUser(), reason));
});
});
}
use of com.sx4.bot.entities.mod.Reason in project Sx4 by sx4-discord-bot.
the class WarnCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
if (member.getIdLong() == event.getSelfUser().getIdLong()) {
event.replyFailure("You cannot warn me, that is illegal").queue();
return;
}
if (!event.getMember().canInteract(member)) {
event.replyFailure("You cannot warn someone higher or equal than your top role").queue();
return;
}
ModUtility.warn(event.getBot(), member, event.getMember(), reason).whenComplete((warning, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause != null) {
event.replyFailure(cause.getMessage()).queue();
return;
}
Warn warn = warning.getWarning();
Action action = warn.getAction();
event.replyFormat("**%s** has received a %s%s (%s warning) " + event.getConfig().getSuccessEmote(), member.getUser().getAsTag(), action.getModAction().getName().toLowerCase(), action instanceof TimeAction ? " for " + TimeUtility.LONG_TIME_FORMATTER.parse(((TimeAction) action).getDuration()) : "", NumberUtility.getSuffixed(warn.getNumber())).queue();
});
}
use of com.sx4.bot.entities.mod.Reason in project Sx4 by sx4-discord-bot.
the class KickCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
if (member.getIdLong() == event.getSelfUser().getIdLong()) {
event.replyFailure("You cannot kick me, that is illegal").queue();
return;
}
if (!event.getMember().canInteract(member)) {
event.replyFailure("You cannot kick someone higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(member)) {
event.replyFailure("I cannot kick someone higher or equal than my top role").queue();
return;
}
member.kick().reason(ModUtility.getAuditReason(reason, event.getAuthor())).queue($ -> {
event.replySuccess("**" + member.getUser().getAsTag() + "** has been kicked").queue();
event.getBot().getModActionManager().onModAction(new KickEvent(event.getMember(), member.getUser(), reason));
});
}
Aggregations