use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class LoggerCommand method list.
@Command(value = "list", description = "List and get info about loggers in the current server")
@CommandId(458)
@Examples({ "logger list" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void list(Sx4CommandEvent event, @Argument(value = "channel", endless = true, nullDefault = true) BaseGuildMessageChannel channel) {
Bson filter = channel == null ? Filters.eq("guildId", event.getGuild().getIdLong()) : Filters.eq("channelId", channel.getIdLong());
List<Document> loggers = event.getMongo().getLoggers(filter, MongoDatabase.EMPTY_DOCUMENT).into(new ArrayList<>());
if (loggers.isEmpty()) {
event.replyFailure(channel == null ? "There are not any loggers setup" : "There is not a logger setup in " + channel.getAsMention()).queue();
return;
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), loggers).setAuthor("Loggers", null, event.getGuild().getIconUrl()).setAutoSelect(true).setDisplayFunction(data -> "<#" + data.getLong("channelId") + ">");
paged.onSelect(select -> {
Document data = select.getSelected();
EnumSet<LoggerEvent> events = LoggerEvent.getEvents(data.get("events", LoggerEvent.ALL));
PagedResult<LoggerEvent> loggerPaged = new PagedResult<>(event.getBot(), new ArrayList<>(events)).setSelect().setPerPage(20).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Logger Settings", null, event.getGuild().getIconUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setFooter(PagedResult.DEFAULT_FOOTER_TEXT).addField("Status", data.getBoolean("enabled", true) ? "Enabled" : "Disabled", true).addField("Channel", "<#" + data.getLong("channelId") + ">", true);
StringJoiner content = new StringJoiner("\n");
page.forEach((loggerEvent, index) -> content.add(loggerEvent.name()));
embed.addField("Enabled Events", content.toString(), false);
return new MessageBuilder().setEmbeds(embed.build());
});
loggerPaged.execute(event);
});
paged.execute(event);
}
use of com.sx4.bot.core.Sx4CommandEvent 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.core.Sx4CommandEvent 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.core.Sx4CommandEvent 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.core.Sx4CommandEvent 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();
}
}
Aggregations