use of com.sx4.bot.annotations.argument.AlternativeOptions in project Sx4 by sx4-discord-bot.
the class StarboardCommand method delete.
@Command(value = "delete", aliases = { "remove" }, description = "Deletes a starboard")
@CommandId(204)
@Examples({ "starboard delete 5ff636647f93247aeb2ac429", "starboard delete all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void delete(Sx4CommandEvent event, @Argument(value = "id | all") @AlternativeOptions("all") Alternative<ObjectId> option) {
if (option.isAlternative()) {
String acceptId = new CustomButtonId.Builder().setType(ButtonType.STARBOARD_DELETE_CONFIRM).setOwners(event.getAuthor().getIdLong()).setTimeout(60).getId();
String rejectId = new CustomButtonId.Builder().setType(ButtonType.GENERIC_REJECT).setOwners(event.getAuthor().getIdLong()).setTimeout(60).getId();
List<Button> buttons = List.of(Button.success(acceptId, "Yes"), Button.danger(rejectId, "No"));
event.reply(event.getAuthor().getName() + ", are you sure you want to delete **all** starboards in this server?").setActionRow(buttons).queue();
} else {
ObjectId id = option.getValue();
AtomicReference<Document> atomicData = new AtomicReference<>();
event.getMongo().findAndDeleteStarboard(Filters.and(Filters.eq("_id", id), Filters.eq("guildId", event.getGuild().getIdLong()))).thenCompose(data -> {
if (data == null) {
return CompletableFuture.completedFuture(null);
}
atomicData.set(data);
return event.getMongo().deleteManyStars(Filters.eq("messageId", data.getLong("originalMessageId")));
}).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result == null) {
event.replyFailure("I could not find that starboard").queue();
return;
}
Document data = atomicData.get();
WebhookClient webhook = event.getBot().getStarboardManager().getWebhook(data.getLong("channelId"));
if (webhook != null) {
webhook.delete(data.getLong("messageId"));
}
event.replySuccess("That starboard has been deleted").queue();
});
}
}
use of com.sx4.bot.annotations.argument.AlternativeOptions in project Sx4 by sx4-discord-bot.
the class AutoRoleCommand method remove.
@Command(value = "remove", aliases = { "delete" }, description = "Remove a role from being given when a user joins")
@CommandId(40)
@Examples({ "auto role remove @Role", "auto role remove Role", "auto role remove all" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
public void remove(Sx4CommandEvent event, @Argument(value = "role | all", endless = true) @AlternativeOptions("all") Alternative<Role> option) {
if (option.isAlternative()) {
String acceptId = new CustomButtonId.Builder().setType(ButtonType.AUTO_ROLE_DELETE_CONFIRM).setOwners(event.getAuthor().getIdLong()).setTimeout(60).getId();
String rejectId = new CustomButtonId.Builder().setType(ButtonType.GENERIC_REJECT).setOwners(event.getAuthor().getIdLong()).setTimeout(60).getId();
List<Button> buttons = List.of(Button.success(acceptId, "Yes"), Button.danger(rejectId, "No"));
event.reply(event.getAuthor().getName() + ", are you sure you want to remove every auto role in the server?").setActionRow(buttons).queue();
} else {
Role role = option.getValue();
event.getMongo().deleteAutoRole(Filters.eq("roleId", role.getIdLong())).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getDeletedCount() == 0) {
event.replyFailure("That role is not an auto role").queue();
return;
}
event.replySuccess(role.getAsMention() + " is no longer an auto role").queue();
});
}
}
use of com.sx4.bot.annotations.argument.AlternativeOptions in project Sx4 by sx4-discord-bot.
the class LeaverCommand method channel.
@Command(value = "channel", description = "Sets the channel where leaver messages are sent to")
@CommandId(190)
@Examples({ "leaver channel", "leaver channel #leaves", "leaver channel reset" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void channel(Sx4CommandEvent event, @Argument(value = "channel | reset", endless = true, nullDefault = true) @AlternativeOptions("reset") Alternative<BaseGuildMessageChannel> option) {
MessageChannel messageChannel = event.getChannel();
if (option == null && !(messageChannel instanceof BaseGuildMessageChannel)) {
event.replyFailure("You cannot use this channel type").queue();
return;
}
BaseGuildMessageChannel channel = option == null ? (BaseGuildMessageChannel) messageChannel : option.isAlternative() ? null : option.getValue();
List<Bson> update = List.of(Operators.set("leaver.channelId", channel == null ? Operators.REMOVE : channel.getIdLong()), Operators.unset("leaver.webhook.id"), Operators.unset("leaver.webhook.token"));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().upsert(true).projection(Projections.include("leaver.webhook.token", "leaver.webhook.id", "leaver.channelId")).returnDocument(ReturnDocument.BEFORE);
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("leaver", "channelId"), 0L);
event.getBot().getLeaverManager().removeWebhook(channelId);
if ((channel == null ? 0L : channel.getIdLong()) == channelId) {
event.replyFailure("The leaver channel is already " + (channel == null ? "unset" : "set to " + channel.getAsMention())).queue();
return;
}
BaseGuildMessageChannel oldChannel = channelId == 0L ? null : event.getGuild().getChannelById(BaseGuildMessageChannel.class, channelId);
long webhookId = data == null ? 0L : data.getEmbedded(List.of("leaver", "webhook", "id"), 0L);
if (oldChannel != null && webhookId != 0L) {
oldChannel.deleteWebhookById(Long.toString(webhookId)).queue(null, ErrorResponseException.ignore(ErrorResponse.UNKNOWN_WEBHOOK));
}
event.replySuccess("The leaver channel has been " + (channel == null ? "unset" : "set to " + channel.getAsMention())).queue();
});
}
use of com.sx4.bot.annotations.argument.AlternativeOptions 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.argument.AlternativeOptions in project Sx4 by sx4-discord-bot.
the class FakePermissionsCommand method delete.
@Command(value = "delete", aliases = { "remove" }, description = "Deletes fake permissions for a user or role")
@CommandId(172)
@Examples({ "fake permissions delete @Shea#6653", "fake permissions delete @Mods", "fake permissions delete all" })
@AuthorPermissions(permissions = { Permission.ADMINISTRATOR })
public void delete(Sx4CommandEvent event, @Argument(value = "user | role | all", endless = true, nullDefault = true) @AlternativeOptions("all") Alternative<IPermissionHolder> option) {
if (option == null) {
List<Document> fakePermissions = event.getProperty("fakePermissions");
if (fakePermissions.isEmpty()) {
event.replyFailure("Nothing has fake permissions in this server").queue();
return;
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), fakePermissions).setAuthor("User & Roles", null, event.getGuild().getIconUrl()).setTimeout(60).setDisplayFunction(data -> {
int type = data.getInteger("type");
long id = data.getLong("id");
if (type == HolderType.USER.getType()) {
User user = event.getShardManager().getUserById(id);
return user == null ? "Anonymous#0000 (" + id + ")" : user.getAsTag();
} else {
Role role = event.getGuild().getRoleById(id);
return role == null ? "Deleted Role (" + id + ")" : role.getAsMention();
}
});
paged.onTimeout(() -> event.reply("Timed out :stopwatch:").queue());
paged.onSelect(select -> {
Document data = select.getSelected();
boolean isRole = data.getInteger("type") == HolderType.ROLE.getType();
long id = data.getLong("id");
User user = isRole ? null : event.getShardManager().getUserById(id);
Role role = isRole ? event.getGuild().getRoleById(id) : null;
event.getMongo().updateGuildById(event.getGuild().getIdLong(), Updates.pull("fakePermissions.holders", Filters.eq("id", id))).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("That " + (isRole ? "role" : "user") + " doesn't have any fake permissions").queue();
return;
}
event.replySuccess((isRole ? (role == null ? "Deleted Role (" + id + ")" : role.getAsMention()) : "**" + (user == null ? "Anonymous#0000** (" + id + ")" : user.getAsTag() + "**")) + " no longer has any fake permissions").queue();
});
});
paged.execute(event);
} else if (option.isAlternative()) {
String acceptId = new CustomButtonId.Builder().setType(ButtonType.FAKE_PERMISSIONS_DELETE_CONFIRM).setOwners(event.getAuthor().getIdLong()).setTimeout(60).getId();
String rejectId = new CustomButtonId.Builder().setType(ButtonType.GENERIC_REJECT).setOwners(event.getAuthor().getIdLong()).setTimeout(60).getId();
List<Button> buttons = List.of(Button.success(acceptId, "Yes"), Button.danger(rejectId, "No"));
event.reply(event.getAuthor().getName() + ", are you sure you want to delete **all** fake permissions data?").setActionRow(buttons).queue();
} else {
IPermissionHolder holder = option.getValue();
boolean role = holder instanceof Role;
event.getMongo().updateGuildById(event.getGuild().getIdLong(), Updates.pull("fakePermissions.holders", Filters.eq("id", holder.getIdLong()))).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("That " + (role ? "role" : "user") + " doesn't have any fake permissions").queue();
return;
}
event.replySuccess((role ? ((Role) holder).getAsMention() : "**" + ((Member) holder).getUser().getAsTag() + "**") + " no longer has any fake permissions").queue();
});
}
}
Aggregations