Search in sources :

Example 31 with Examples

use of com.sx4.bot.annotations.command.Examples 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();
    });
}
Also used : MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) Document(org.bson.Document) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Example 32 with Examples

use of com.sx4.bot.annotations.command.Examples 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();
    });
}
Also used : MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) MongoWriteException(com.mongodb.MongoWriteException) CompletionException(java.util.concurrent.CompletionException) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) Document(org.bson.Document) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 33 with Examples

use of com.sx4.bot.annotations.command.Examples 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();
    });
}
Also used : MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) UpdateOptions(com.mongodb.client.model.UpdateOptions) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 34 with Examples

use of com.sx4.bot.annotations.command.Examples 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();
    }
}
Also used : Document(org.bson.Document) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) WebhookClient(club.minnced.discord.webhook.WebhookClient) Command(com.jockie.bot.core.command.Command) Permission(net.dv8tion.jda.api.Permission) CommandId(com.sx4.bot.annotations.command.CommandId) ErrorResponse(net.dv8tion.jda.api.requests.ErrorResponse) PagedResult(com.sx4.bot.paged.PagedResult) User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) Alternative(com.sx4.bot.entities.argument.Alternative) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) Button(net.dv8tion.jda.api.interactions.components.buttons.Button) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) AlternativeOptions(com.sx4.bot.annotations.argument.AlternativeOptions) Reason(com.sx4.bot.entities.mod.Reason) com.mongodb.client.model(com.mongodb.client.model) Range(com.sx4.bot.entities.argument.Range) Argument(com.jockie.bot.core.argument.Argument) Action(com.sx4.bot.entities.mod.action.Action) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Operators(com.sx4.bot.database.mongo.model.Operators) ErrorResponseException(net.dv8tion.jda.api.exceptions.ErrorResponseException) BaseGuildMessageChannel(net.dv8tion.jda.api.entities.BaseGuildMessageChannel) Sx4Command(com.sx4.bot.core.Sx4Command) Premium(com.sx4.bot.annotations.command.Premium) ModuleCategory(com.sx4.bot.category.ModuleCategory) ModLog(com.sx4.bot.entities.mod.ModLog) List(java.util.List) Examples(com.sx4.bot.annotations.command.Examples) ImageUrl(com.sx4.bot.annotations.argument.ImageUrl) CustomButtonId(com.sx4.bot.entities.interaction.CustomButtonId) ObjectId(org.bson.types.ObjectId) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) ButtonType(com.sx4.bot.entities.interaction.ButtonType) User(net.dv8tion.jda.api.entities.User) Document(org.bson.Document) PagedResult(com.sx4.bot.paged.PagedResult) Bson(org.bson.conversions.Bson) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 35 with Examples

use of com.sx4.bot.annotations.command.Examples 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()) {
        String acceptId = new CustomButtonId.Builder().setType(ButtonType.MOD_LOG_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(author.getName() + ", are you sure you want to delete **all** the suggestions in this server?").setActionRow(buttons).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();
        });
    }
}
Also used : User(net.dv8tion.jda.api.entities.User) WebhookClient(club.minnced.discord.webhook.WebhookClient) Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ObjectId(org.bson.types.ObjectId) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Aggregations

Sx4Command (com.sx4.bot.core.Sx4Command)177 Command (com.jockie.bot.core.command.Command)175 CommandId (com.sx4.bot.annotations.command.CommandId)115 Examples (com.sx4.bot.annotations.command.Examples)115 Document (org.bson.Document)111 Bson (org.bson.conversions.Bson)96 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)82 PagedResult (com.sx4.bot.paged.PagedResult)71 AuthorPermissions (com.sx4.bot.annotations.command.AuthorPermissions)59 Argument (com.jockie.bot.core.argument.Argument)53 ModuleCategory (com.sx4.bot.category.ModuleCategory)53 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)53 Permission (net.dv8tion.jda.api.Permission)53 BotPermissions (com.sx4.bot.annotations.command.BotPermissions)44 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)44 ExceptionUtility (com.sx4.bot.utility.ExceptionUtility)42 Operators (com.sx4.bot.database.mongo.model.Operators)41 User (net.dv8tion.jda.api.entities.User)40 Collectors (java.util.stream.Collectors)36 AlternativeOptions (com.sx4.bot.annotations.argument.AlternativeOptions)31