use of com.sx4.bot.annotations.command.CommandId 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.CommandId 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.getTextChannel(), builder.build()).queue();
}
use of com.sx4.bot.annotations.command.CommandId 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.CommandId in project Sx4 by sx4-discord-bot.
the class LoggerCommand method toggle.
@Command(value = "toggle", aliases = { "enable", "disable" }, description = "Toggles the state of a logger")
@CommandId(56)
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Examples({ "logger toggle #logs", "logger toggle" })
public void toggle(Sx4CommandEvent event, @Argument(value = "channel", endless = true, nullDefault = true) TextChannel channel) {
TextChannel effectiveChannel = channel == null ? event.getTextChannel() : channel;
List<Bson> guildPipeline = List.of(Aggregates.project(Projections.fields(Projections.computed("premium", Operators.lt(Operators.nowEpochSecond(), Operators.ifNull("$premium.endAt", 0L))), Projections.computed("guildId", "$_id"))), Aggregates.match(Filters.eq("guildId", event.getGuild().getIdLong())));
List<Bson> pipeline = List.of(Aggregates.match(Filters.and(Filters.eq("guildId", event.getGuild().getIdLong()), Filters.exists("enabled", false))), Aggregates.project(Projections.include("channelId")), Aggregates.group(null, Accumulators.push("loggers", Operators.ROOT)), Aggregates.unionWith("guilds", guildPipeline), Aggregates.group(null, Accumulators.max("loggers", "$loggers"), Accumulators.max("premium", "$premium")), Aggregates.project(Projections.fields(Projections.computed("premium", Operators.ifNull("$premium", false)), Projections.computed("count", Operators.size(Operators.ifNull("$loggers", Collections.EMPTY_LIST))), Projections.computed("disabled", Operators.isEmpty(Operators.filter(Operators.ifNull("$loggers", Collections.EMPTY_LIST), Operators.eq("$$this.channelId", effectiveChannel.getIdLong())))))));
event.getMongo().aggregateLoggers(pipeline).thenCompose(documents -> {
Document data = documents.isEmpty() ? null : documents.get(0);
boolean disabled = data == null || data.getBoolean("disabled");
int count = data == null ? 0 : data.getInteger("count");
if (data != null && disabled && count >= 3 && !data.getBoolean("premium")) {
throw new IllegalArgumentException("You need to have Sx4 premium to have more than 3 enabled loggers, you can get premium at <https://www.patreon.com/Sx4>");
}
if (count >= 25) {
throw new IllegalArgumentException("You can not have any more than 25 enabled loggers");
}
List<Bson> update = List.of(Operators.set("enabled", Operators.cond(Operators.exists("$enabled"), Operators.REMOVE, false)));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).projection(Projections.include("enabled"));
return event.getMongo().findAndUpdateLogger(Filters.eq("channelId", effectiveChannel.getIdLong()), update, options);
}).whenComplete((data, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof IllegalArgumentException) {
event.replyFailure(cause.getMessage()).queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (data == null) {
event.replyFailure("There is not a logger in that channel").queue();
return;
}
event.replySuccess("The logger in " + effectiveChannel.getAsMention() + " is now **" + (data.get("enabled", true) ? "enabled" : "disabled") + "**").queue();
});
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class MuteCommand method defaultTime.
@Command(value = "default time", aliases = { "default duration" }, description = "Sets the default time to be used when a duration argument isn't given")
@CommandId(342)
@Examples({ "mute default time 10m", "mute default time 5d", "mute default time 1h 30m" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void defaultTime(Sx4CommandEvent event, @Argument(value = "duration", endless = true) Duration duration) {
long seconds = duration.toSeconds();
Bson update = seconds == ModUtility.DEFAULT_MUTE_DURATION ? Updates.unset("mute.defaultTime") : Updates.set("mute.defaultTime", seconds);
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 default time was already set to that").queue();
return;
}
event.replySuccess("Your mute default time has been set to **" + TimeUtility.LONG_TIME_FORMATTER.parse(seconds) + "**").queue();
});
}
Aggregations