use of com.sx4.bot.entities.mod.action.Action in project Sx4 by sx4-discord-bot.
the class UserInfoCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user", nullDefault = true) @UserId long userId) {
RestAction<User> action = userId == 0L ? new CompletedRestAction<>(event.getJDA(), event.getAuthor()) : event.getJDA().retrieveUserById(userId);
action.flatMap(user -> {
EmbedBuilder embed = new EmbedBuilder().setDescription(event.getConfig().getUserFlagEmotes(user.getFlags())).setAuthor(user.getAsTag(), user.getEffectiveAvatarUrl(), user.getEffectiveAvatarUrl()).setThumbnail(user.getEffectiveAvatarUrl()).addField("Joined Discord", user.getTimeCreated().format(TimeUtility.DEFAULT_FORMATTER), true).addField("User ID", user.getId(), true).addField("Bot", user.isBot() ? "Yes" : "No", false);
return event.reply(embed.build());
}).onErrorFlatMap(exception -> {
if (exception instanceof ErrorResponseException && ((ErrorResponseException) exception).getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
return event.replyFailure("I could not find that user");
}
return null;
}).queue();
}
use of com.sx4.bot.entities.mod.action.Action in project Sx4 by sx4-discord-bot.
the class SelfRoleCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "role", endless = true) Role role) {
Document selfRole = event.getMongo().getSelfRole(Filters.eq("roleId", role.getIdLong()), Projections.include("_id"));
if (selfRole == null) {
event.replyFailure("That role is not a self role").queue();
return;
}
boolean hasRole = event.getMember().getRoles().contains(role);
RestAction<Void> action;
if (hasRole) {
action = event.getGuild().removeRoleFromMember(event.getMember(), role);
} else {
action = event.getGuild().addRoleToMember(event.getMember(), role);
}
action.flatMap($ -> event.replySuccess("You " + (hasRole ? "no longer" : "now") + " have " + role.getAsMention())).queue();
}
use of com.sx4.bot.entities.mod.action.Action 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.action.Action 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