use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class WelcomerCommand method toggle.
@Command(value = "toggle", description = "Toggle the state of welcomer")
@CommandId(92)
@Examples({ "welcomer toggle" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void toggle(Sx4CommandEvent event) {
List<Bson> update = List.of(Operators.set("welcomer.enabled", Operators.cond("$welcomer.enabled", Operators.REMOVE, true)));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).projection(Projections.include("welcomer.enabled")).upsert(true);
event.getMongo().findAndUpdateGuildById(event.getGuild().getIdLong(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("Welcomer is now " + (data.getEmbedded(List.of("welcomer", "enabled"), false) ? "enabled" : "disabled")).queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class WelcomerCommand method embed.
@Command(value = "embed", description = "Set your welcomer message to use a basic embed")
@CommandId(434)
@Examples({ "welcomer embed A new person has joined", "welcomer embed Welcome {user.mention}! --colour=#ffff00", "welcomer embed Welcome {user.mention}! --colour=#ffff00 --image" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void embed(Sx4CommandEvent event, @Argument(value = "message", endless = true) String message, @Option(value = "image", description = "Use this option if you want the image welcomer in the embed") boolean image, @Option(value = "colour", description = "Sets the embed colour for the message") @Colour Integer colour) {
Document data = new Document("description", message).append("author", new Document("name", "{user.tag}").append("icon_url", "{user.avatar}"));
if (colour != null) {
data.append("color", colour);
}
if (image) {
data.append("image", new Document("url", "{file.url}"));
}
event.getMongo().updateGuildById(event.getGuild().getIdLong(), Updates.set("welcomer.message", new Document("embed", data))).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Your welcomer message is already set to that").queue();
return;
}
event.replySuccess("Your welcomer message has been updated").queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class AutoRoleCommand method add.
@Command(value = "add", description = "Add a role to be given when a user joins")
@CommandId(39)
@Examples({ "auto role add @Role", "auto role add Role", "auto role add 406240455622262784" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
public void add(Sx4CommandEvent event, @Argument(value = "role", endless = true) Role role) {
if (role.isManaged()) {
event.replyFailure("You cannot add a managed role as an auto role").queue();
return;
}
if (role.isPublicRole()) {
event.replyFailure("You cannot add the @everyone role as an auto role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("You cannot add an auto role higher or equal than my top role").queue();
return;
}
if (!event.getMember().canInteract(role)) {
event.replyFailure("You cannot give n auto role higher or equal than your top role").queue();
return;
}
Document data = new Document("roleId", role.getIdLong()).append("guildId", event.getGuild().getIdLong());
event.getMongo().insertAutoRole(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 role is already an auto role").queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("The role " + role.getAsMention() + " has been added as an auto role").queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class AutoRoleCommand method remove.
@Command(value = "remove", aliases = { "delete" }, description = "Remove a role from being given when a user joins")
@CommandId(40)
@Examples({ "auto role remove @Role", "auto role remove Role", "auto role remove 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()) {
String acceptId = new CustomButtonId.Builder().setType(ButtonType.AUTO_ROLE_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(event.getAuthor().getName() + ", are you sure you want to remove every auto role in the server?").setActionRow(buttons).queue();
} else {
Role role = option.getValue();
event.getMongo().deleteAutoRole(Filters.eq("roleId", role.getIdLong())).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getDeletedCount() == 0) {
event.replyFailure("That role is not an auto role").queue();
return;
}
event.replySuccess(role.getAsMention() + " is no longer an auto role").queue();
});
}
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class GiveawayCommand method restart.
@Command(value = "restart", description = "Restarts a giveaway")
@CommandId(48)
@Examples({ "giveaway restart 727224132202397726" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void restart(Sx4CommandEvent event, @Argument(value = "message id") MessageArgument messageArgument, @Argument(value = "duration", endless = true, nullDefault = true) Duration duration) {
long timeNow = Clock.systemUTC().instant().getEpochSecond();
List<Bson> update = List.of(Operators.set("endAt", Operators.cond(Operators.exists("$winners"), duration == null ? Operators.add(timeNow, "$duration") : duration.toSeconds() + timeNow, "$endAt")), Operators.set("duration", Operators.cond(Operators.exists("$winners"), duration == null ? "$duration" : duration.toSeconds(), "$duration")), Operators.unset("winners"));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE).projection(Projections.exclude("winners"));
event.getMongo().findAndUpdateGiveawayById(messageArgument.getMessageId(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (data == null) {
event.replyFailure("There is no giveaway with that id").queue();
return;
}
if (data.getLong("endAt") - timeNow > 0) {
event.replyFailure("That giveaway has not ended yet").queue();
return;
}
long seconds = duration == null ? data.getLong("duration") : duration.toSeconds();
BaseGuildMessageChannel channel = event.getGuild().getChannelById(BaseGuildMessageChannel.class, data.getLong("channelId"));
if (channel == null) {
event.replyFailure("That giveaway no longer exists").queue();
return;
}
channel.editMessageEmbedsById(data.getLong("messageId"), this.getEmbed(data.getInteger("winnersAmount"), seconds, data.getString("item"))).queue();
event.getBot().getGiveawayManager().putGiveaway(data, seconds);
event.replySuccess("That giveaway has been restarted").queue();
});
}
Aggregations