use of com.sx4.bot.entities.argument.Alternative in project Sx4 by sx4-discord-bot.
the class StarboardCommand method channel.
@Command(value = "channel", description = "Sets the channel for starboard messages to be sent in")
@CommandId(198)
@Examples({ "starboard channel", "starboard channel #starboard", "starboard channel reset" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void channel(Sx4CommandEvent event, @Argument(value = "channel | reset", endless = true, nullDefault = true) @AlternativeOptions("reset") Alternative<TextChannel> option) {
TextChannel channel = option == null ? event.getTextChannel() : option.getValue();
List<Bson> update = List.of(Operators.set("starboard.channelId", channel == null ? Operators.REMOVE : channel.getIdLong()), Operators.unset("starboard.webhook.id"), Operators.unset("starboard.webhook.token"));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE).projection(Projections.include("starboard.webhook.id", "starboard.channelId")).upsert(true);
event.getMongo().findAndUpdateGuildById(event.getGuild().getIdLong(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
long channelId = data == null ? 0L : data.getEmbedded(List.of("starboard", "channelId"), 0L);
event.getBot().getStarboardManager().removeWebhook(channelId);
if ((channel == null ? 0L : channel.getIdLong()) == channelId) {
event.replyFailure("The starboard channel is already " + (channel == null ? "unset" : "set to " + channel.getAsMention())).queue();
return;
}
TextChannel oldChannel = channelId == 0L ? null : event.getGuild().getTextChannelById(channelId);
long webhookId = data == null ? 0L : data.getEmbedded(List.of("starboard", "webhook", "id"), 0L);
if (oldChannel != null && webhookId != 0L) {
oldChannel.deleteWebhookById(Long.toString(webhookId)).queue(null, ErrorResponseException.ignore(ErrorResponse.UNKNOWN_WEBHOOK));
}
event.replySuccess("The starboard channel has been " + (channel == null ? "unset" : "set to " + channel.getAsMention())).queue();
});
}
use of com.sx4.bot.entities.argument.Alternative in project Sx4 by sx4-discord-bot.
the class TemplateCommand method delete.
@Command(value = "delete", aliases = { "remove" }, description = "Deletes a template from the current server")
@CommandId(256)
@Examples({ "template delete 6006ff6b94c9ed0f764ada83", "template delete all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void delete(Sx4CommandEvent event, @Argument(value = "id | all") @AlternativeOptions("all") Alternative<ObjectId> option) {
if (option.isAlternative()) {
List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
event.reply(event.getAuthor().getName() + ", are you sure you want to delete **all** the templates in this server?").setActionRow(buttons).submit().thenCompose(message -> {
return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
}).whenComplete((e, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof CancelException) {
GenericEvent cancelEvent = ((CancelException) cause).getEvent();
if (cancelEvent != null) {
((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
}
return;
} else if (cause instanceof TimeoutException) {
event.reply("Timed out :stopwatch:").queue();
return;
} else if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.getMongo().deleteManyTemplates(Filters.eq("guildId", event.getGuild().getIdLong())).whenComplete((result, databaseException) -> {
if (ExceptionUtility.sendExceptionally(event, databaseException)) {
return;
}
if (result.getDeletedCount() == 0) {
e.reply("There are no templates in this server " + event.getConfig().getFailureEmote()).queue();
return;
}
e.reply("All templates have been deleted in this server " + event.getConfig().getSuccessEmote()).queue();
});
});
} else {
event.getMongo().deleteTemplateById(option.getValue()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getDeletedCount() == 0) {
event.replyFailure("I could not find that template").queue();
return;
}
event.replySuccess("That template has been deleted").queue();
});
}
}
use of com.sx4.bot.entities.argument.Alternative 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.entities.argument.Alternative in project Sx4 by sx4-discord-bot.
the class MuteCommand method role.
@Command(value = "role", description = "Set the mute role to a custom one")
@CommandId(340)
@Examples({ "mute role @Muted", "mute role Muted", "mute role reset" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void role(Sx4CommandEvent event, @Argument(value = "role | reset", endless = true) Alternative<Role> option) {
Role role = option.getValue();
Bson update = option.isAlternative() ? Updates.unset("mute.roleId") : Updates.set("mute.roleId", role.getIdLong());
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 mute role was already " + (option.isAlternative() ? "unset" : "set to that")).queue();
return;
}
event.replySuccess("Your mute role has been " + (option.isAlternative() ? "unset" : "set to " + role.getAsMention())).queue();
});
}
Aggregations