use of com.sx4.bot.annotations.command.CommandId 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.CommandId 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()) {
List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
event.reply(author.getName() + ", are you sure you want to delete **all** the suggestions in this server?").setActionRow(buttons).submit().thenCompose(message -> {
return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
}).whenComplete((e, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof CancelException) {
GenericEvent cancelEvent = ((CancelException) cause).getEvent();
if (cancelEvent != null) {
((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
}
return;
} else if (cause instanceof TimeoutException) {
event.reply("Timed out :stopwatch:").queue();
return;
} else if (ExceptionUtility.sendExceptionally(event, cause)) {
return;
}
event.getMongo().deleteManyModLogs(Filters.eq("guildId", event.getGuild().getIdLong())).whenComplete((result, databaseException) -> {
if (ExceptionUtility.sendExceptionally(event, databaseException)) {
return;
}
if (result.getDeletedCount() == 0) {
e.reply("There are no mod logs in this server " + event.getConfig().getFailureEmote()).queue();
return;
}
e.reply("All your mod logs have been deleted " + event.getConfig().getSuccessEmote()).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();
});
}
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class SelfRoleCommand method remove.
@Command(value = "delete", aliases = { "remove" }, description = "Delete a self role from the current server")
@CommandId(333)
@Examples({ "self role delete @Role", "self role delete Role", "self role delete 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()) {
List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
event.reply(event.getAuthor().getName() + ", are you sure you want to delete every self role in the server?").setActionRow(buttons).submit().thenCompose(message -> {
return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
}).whenComplete((e, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof CancelException) {
GenericEvent cancelEvent = ((CancelException) cause).getEvent();
if (cancelEvent != null) {
((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
}
return;
} else if (cause instanceof TimeoutException) {
event.reply("Timed out :stopwatch:").queue();
return;
} else if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.getMongo().deleteManySelfRoles(Filters.eq("guildId", event.getGuild().getIdLong())).whenComplete((result, databaseException) -> {
if (ExceptionUtility.sendExceptionally(event, databaseException)) {
return;
}
if (result.getDeletedCount() == 0) {
event.replyFailure("There are no self roles in this server").queue();
return;
}
e.reply("All self roles have been deleted " + event.getConfig().getSuccessEmote()).queue();
});
});
} else {
Role role = option.getValue();
event.getMongo().deleteSelfRole(Filters.eq("roleId", role.getIdLong())).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess(role.getAsMention() + " is no longer a self role").queue();
});
}
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class TemporaryBanCommand 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(344)
@Examples({ "temporary ban default time 10m", "temporary ban default time 5d", "temporary ban 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_TEMPORARY_BAN_DURATION ? Updates.unset("temporaryBan.defaultTime") : Updates.set("temporaryBan.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 temporary ban default time was already set to that").queue();
return;
}
event.replySuccess("Your temporary ban default time has been set to **" + TimeUtility.LONG_TIME_FORMATTER.parse(seconds) + "**").queue();
});
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class TemporaryBanCommand method list.
@Command(value = "list", description = "Lists all the users who have temporary bans")
@CommandId(345)
@Examples({ "temporary ban list" })
public void list(Sx4CommandEvent event) {
List<Document> bans = event.getMongo().getTemporaryBans(Filters.eq("guildId", event.getGuild().getIdLong()), Projections.include("unbanAt", "userId")).into(new ArrayList<>());
if (bans.isEmpty()) {
event.replyFailure("There is no one with a temporary ban in this server").queue();
return;
}
bans.sort(Comparator.comparingLong(d -> d.getLong("unbanAt")));
PagedResult<Document> paged = new PagedResult<>(event.getBot(), bans).setAuthor("Muted Users", null, event.getGuild().getIconUrl()).setIndexed(false).setSelect().setDisplayFunction(data -> {
User user = event.getShardManager().getUserById(data.getLong("userId"));
return (user == null ? "Anonymous#0000" : user.getAsTag()) + " - " + TimeUtility.LONG_TIME_FORMATTER.parse(data.getLong("unbanAt") - Clock.systemUTC().instant().getEpochSecond());
});
paged.execute(event);
}
Aggregations