use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class GiveawayCommand method end.
@Command(value = "end", description = "Ends an active giveaway early")
@CommandId(50)
@Examples({ "giveaway end 727224132202397726" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void end(Sx4CommandEvent event, @Argument(value = "message id") MessageArgument messageArgument) {
Document data = event.getMongo().getGiveawayById(messageArgument.getMessageId());
if (data == null) {
event.replyFailure("There is no giveaway with that id").queue();
return;
}
if (data.containsKey("winners")) {
event.replyFailure("That giveaway has already ended").queue();
return;
}
event.getBot().getGiveawayManager().endGiveaway(data, true);
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class LeaverCommand method toggle.
@Command(value = "toggle", description = "Toggle the state of leaver")
@CommandId(189)
@Examples({ "leaver toggle" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void toggle(Sx4CommandEvent event) {
List<Bson> update = List.of(Operators.set("leaver.enabled", Operators.cond("$leaver.enabled", Operators.REMOVE, true)));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).projection(Projections.include("leaver.enabled")).upsert(true);
event.getMongo().findAndUpdateGuildById(event.getGuild().getIdLong(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("Leaver is now " + (data.getEmbedded(List.of("leaver", "enabled"), false) ? "enabled" : "disabled")).queue();
});
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class LeaverCommand method preview.
@Command(value = "preview", description = "Preview your leaver message")
@CommandId(195)
@Examples({ "leaver preview" })
public void preview(Sx4CommandEvent event) {
Document data = event.getMongo().getGuildById(event.getGuild().getIdLong(), Projections.include("leaver.message", "leaver.enabled"));
Document leaver = data.get("leaver", MongoDatabase.EMPTY_DOCUMENT);
if (!leaver.get("enabled", false)) {
event.replyFailure("Leaver is not enabled").queue();
return;
}
WebhookMessageBuilder builder;
try {
builder = LeaverUtility.getLeaverMessage(leaver.get("message", LeaverManager.DEFAULT_MESSAGE), event.getMember());
} catch (IllegalArgumentException e) {
event.replyFailure(e.getMessage()).queue();
return;
}
MessageUtility.fromWebhookMessage(event.getChannel(), builder.build()).queue();
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class LoggerCommand method name.
@Command(value = "name", description = "Set the name of the webhook that sends logs")
@CommandId(423)
@Examples({ "logger name #logs Logs", "logger name Logger" })
@Premium
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void name(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) BaseGuildMessageChannel channel, @Argument(value = "name", endless = true) String name) {
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().updateLogger(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("webhook.name", name)).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Your webhook name for that logger was already set to that").queue();
return;
}
event.replySuccess("Your webhook name has been updated for that logger, this only works with premium <https://patreon.com/Sx4>").queue();
});
}
use of com.sx4.bot.annotations.command.Examples 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);
}
Aggregations