use of com.sx4.bot.annotations.command.AuthorPermissions 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();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class RoleCommand method remove.
@Command(value = "remove", description = "Remove a role from a member")
@CommandId(251)
@Redirects({ "removerole", "remove role", "rr" })
@Examples({ "role remove @Shea#6653 Role", "role remove Shea 345718366373150720", "role remove @Role" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
@BotPermissions(permissions = { Permission.MANAGE_ROLES })
public void remove(Sx4CommandEvent event, @Argument(value = "user", nullDefault = true) Member member, @Argument(value = "role", endless = true) Role role) {
if (role.isManaged()) {
event.replyFailure("I cannot remove managed roles").queue();
return;
}
if (role.isPublicRole()) {
event.replyFailure("I cannot remove the @everyone role").queue();
return;
}
if (!event.getMember().canInteract(role)) {
event.replyFailure("You cannot remove a role higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("I cannot remove a role higher or equal than my top role").queue();
return;
}
Member effectiveMember = member == null ? event.getMember() : member;
event.getGuild().removeRoleFromMember(effectiveMember, role).flatMap($ -> event.replySuccess(role.getAsMention() + " has been removed from **" + effectiveMember.getUser().getAsTag() + "**")).queue();
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class TemplateCommand method add.
@Command(value = "add", description = "Add a template in the current server")
@CommandId(255)
@Examples({ "template add tos Broke ToS", "template add spam Spamming excessively" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void add(Sx4CommandEvent event, @Argument(value = "template") @Limit(max = 100) String template, @Argument(value = "reason", endless = true) String reason) {
Document data = new Document("template", template).append("reason", reason).append("guildId", event.getGuild().getIdLong());
event.getMongo().insertTemplate(data).whenComplete((result, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof MongoWriteException && ((MongoWriteException) cause).getError().getCategory() == ErrorCategory.DUPLICATE_KEY) {
event.replyFailure("You already have a template with that name").queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("That template has been added with id `" + result.getInsertedId().asObjectId().getValue().toHexString() + "`").queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method add.
@Command(value = "add", description = "Add a channel to get free game notifications from Epic Games")
@CommandId(474)
@Examples({ "free games add", "free games add #channel" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Canary
public void add(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true, endless = true) BaseGuildMessageChannel channel) {
MessageChannel messageChannel = event.getChannel();
if (channel == null && !(messageChannel instanceof BaseGuildMessageChannel)) {
event.replyFailure("You cannot use this channel type").queue();
return;
}
BaseGuildMessageChannel effectiveChannel = channel == null ? (BaseGuildMessageChannel) messageChannel : channel;
Document data = new Document("channelId", effectiveChannel.getIdLong()).append("guildId", event.getGuild().getIdLong());
event.getMongo().insertFreeGameChannel(data).whenComplete((result, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof MongoWriteException && ((MongoWriteException) cause).getError().getCategory() == ErrorCategory.DUPLICATE_KEY) {
event.replyFailure("You already have a free games channel in " + effectiveChannel.getAsMention()).queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("Free game notifications will now be sent in " + effectiveChannel.getAsMention()).queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method message.
@Command(value = "message", description = "Set the message for the free game notifications")
@CommandId(477)
@Examples({ "free games message {game.title} is now free!", "free games message {game.title} {game.original_price.equals(0).then().else(was £{game.original_price.format(,##0.00)} and)} is now free!" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void message(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) BaseGuildMessageChannel channel, @Argument(value = "message", endless = true) @Limit(max = 2000) String message) {
MessageChannel messageChannel = event.getChannel();
if (channel == null && !(messageChannel instanceof BaseGuildMessageChannel)) {
event.replyFailure("You cannot use this channel type").queue();
return;
}
BaseGuildMessageChannel effectiveChannel = channel == null ? (BaseGuildMessageChannel) messageChannel : channel;
event.getMongo().updateFreeGameChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("message.content", message), new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getMatchedCount() == 0) {
event.replyFailure("You don't have a free game channel setup").queue();
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Your message for free game notifications is already set to that").queue();
return;
}
event.replySuccess("Your message for free game notifications has been updated").queue();
});
}
Aggregations