use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class LoggerCommand method remove.
@Command(value = "remove", description = "Removes a logger from a certain channel")
@CommandId(55)
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Examples({ "logger remove #logs", "logger remove" })
public void remove(Sx4CommandEvent event, @Argument(value = "channel", endless = true, nullDefault = 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;
FindOneAndDeleteOptions options = new FindOneAndDeleteOptions().projection(Projections.include("webhook.id"));
event.getMongo().findAndDeleteLogger(Filters.eq("channelId", effectiveChannel.getIdLong()), options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (data == null) {
event.replyFailure("You don't have a logger in " + effectiveChannel.getAsMention()).queue();
return;
}
event.getBot().getLoggerHandler().removeManager(effectiveChannel.getIdLong());
Document webhook = data.get("webhook", Document.class);
if (webhook != null) {
effectiveChannel.deleteWebhookById(Long.toString(webhook.getLong("id"))).queue(null, ErrorResponseException.ignore(ErrorResponse.UNKNOWN_WEBHOOK));
}
event.replySuccess("You no longer have a logger setup in " + effectiveChannel.getAsMention()).queue();
});
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class MediaModeCommand method add.
@Command(value = "add", description = "Add a channel as a media only channel")
@CommandId(350)
@Examples({ "media mode add", "media mode add #media" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void add(Sx4CommandEvent event, @Argument(value = "channel", endless = true, nullDefault = 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().insertMediaChannel(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("That channel is already a media only channel").queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess(effectiveChannel.getAsMention() + " is now a media only channel").queue();
});
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class MediaModeCommand method types.
@Command(value = "types", description = "Sets what types are allowed to be sent in the channel")
@CommandId(352)
@Examples({ "media mode types PNG", "media mode types #media JPG PNG", "media mode types GIF MP4" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void types(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) BaseGuildMessageChannel channel, @Argument(value = "types") MediaType... types) {
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().updateMediaChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("types", MediaType.getRaw(types)), new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("That media only channel already had those types set").queue();
return;
}
event.replySuccess("Types for that media only channel have been updated").queue();
});
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class ModLogCommand method view.
@Command(value = "view", aliases = { "viewcase", "view case", "list" }, description = "View a mod log case from the server")
@CommandId(70)
@Examples({ "modlog view 5e45ce6d3688b30ee75201ae", "modlog view" })
public void view(Sx4CommandEvent event, @Argument(value = "id", nullDefault = true) ObjectId id) {
Bson projection = Projections.include("moderatorId", "reason", "targetId", "action");
if (id == null) {
List<Document> allData = event.getMongo().getModLogs(Filters.eq("guildId", event.getGuild().getIdLong()), projection).into(new ArrayList<>());
if (allData.isEmpty()) {
event.replyFailure("There are no mod logs in this server").queue();
return;
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), allData).setDisplayFunction(data -> {
long targetId = data.getLong("targetId");
User target = event.getShardManager().getUserById(targetId);
return Action.fromData(data.get("action", Document.class)) + " to `" + (target == null ? targetId : target.getAsTag() + "`");
}).setIncreasedIndex(true);
paged.onSelect(select -> event.reply(ModLog.fromData(select.getSelected()).getEmbed(event.getShardManager())).queue());
paged.execute(event);
} else {
Document data = event.getMongo().getModLogById(Filters.and(Filters.eq("_id", id), Filters.eq("guildId", event.getGuild().getIdLong())), projection);
if (data == null) {
event.replyFailure("I could not find a mod log with that id").queue();
return;
}
event.reply(ModLog.fromData(data).getEmbed(event.getShardManager())).queue();
}
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class ModLogCommand method remove.
@Command(value = "delete", aliases = { "remove" }, description = "Deletes a mod log from the server")
@CommandId(69)
@Examples({ "modlog delete 5e45ce6d3688b30ee75201ae", "modlog delete all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void remove(Sx4CommandEvent event, @Argument(value = "id | all") @AlternativeOptions("all") Alternative<ObjectId> option) {
User author = event.getAuthor();
if (option.isAlternative()) {
String acceptId = new CustomButtonId.Builder().setType(ButtonType.MOD_LOG_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(author.getName() + ", are you sure you want to delete **all** the suggestions in this server?").setActionRow(buttons).queue();
} else {
ObjectId id = option.getValue();
event.getMongo().findAndDeleteModLog(Filters.and(Filters.eq("_id", id), Filters.eq("guildId", event.getGuild().getIdLong()))).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (data == null) {
event.replyFailure("I could not find that mod log").queue();
return;
}
WebhookClient webhook = event.getBot().getModLogManager().getWebhook(data.getLong("channelId"));
if (webhook != null) {
webhook.delete(data.getLong("messageId"));
}
event.replySuccess("That mod log has been deleted").queue();
});
}
}
Aggregations