Search in sources :

Example 1 with ICommandRestricted

use of fredboat.commandmeta.abs.ICommandRestricted in project FredBoat by Frederikam.

the class HelpCommand method sendFormattedCommandHelp.

private static void sendFormattedCommandHelp(CommandContext context, String trigger) {
    Command command = CommandRegistry.findCommand(trigger);
    if (command == null) {
        String out = "`" + TextUtils.escapeMarkdown(context.getPrefix()) + trigger + "`: " + context.i18n("helpUnknownCommand");
        out += "\n" + context.i18nFormat("helpCommandsPromotion", "`" + TextUtils.escapeMarkdown(context.getPrefix()) + CommandInitializer.COMMANDS_COMM_NAME + "`");
        context.replyWithName(out);
        return;
    }
    String out = getFormattedCommandHelp(context, command, trigger);
    if (command instanceof ICommandRestricted && ((ICommandRestricted) command).getMinimumPerms() == PermissionLevel.BOT_OWNER)
        out += "\n#" + context.i18n("helpCommandOwnerRestricted");
    out = TextUtils.asCodeBlock(out, "md");
    out = context.i18n("helpProperUsage") + out;
    context.replyWithName(out);
}
Also used : SelectCommand(fredboat.command.music.control.SelectCommand) Command(fredboat.commandmeta.abs.Command) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) PrefixCommand(fredboat.command.config.PrefixCommand) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted)

Example 2 with ICommandRestricted

use of fredboat.commandmeta.abs.ICommandRestricted in project FredBoat by Frederikam.

the class CommandsCommand method addModuleCommands.

private EmbedBuilder addModuleCommands(@Nonnull EmbedBuilder embedBuilder, @Nonnull CommandContext context, @Nonnull CommandRegistry module) {
    List<Command> commands = module.getDeduplicatedCommands().stream().filter(command -> {
        if (command instanceof ICommandRestricted) {
            if (((ICommandRestricted) command).getMinimumPerms().getLevel() >= PermissionLevel.BOT_ADMIN.getLevel()) {
                return PermsUtil.checkPerms(PermissionLevel.BOT_ADMIN, context.invoker);
            }
        }
        return true;
    }).collect(Collectors.toList());
    String prefix = context.getPrefix();
    if (commands.size() >= 6) {
        // split the commands into three even columns
        StringBuilder[] sbs = new StringBuilder[3];
        sbs[0] = new StringBuilder();
        sbs[1] = new StringBuilder();
        sbs[2] = new StringBuilder();
        int i = 0;
        for (Command c : commands) {
            if (c instanceof DestroyCommand) {
                // dont want to publicly show this one
                continue;
            }
            sbs[i++ % 3].append(prefix).append(c.name).append("\n");
        }
        return embedBuilder.addField(context.i18n(module.module.translationKey), sbs[0].toString(), true).addField("", sbs[1].toString(), true).addField("", sbs[2].toString(), true);
    } else {
        StringBuilder sb = new StringBuilder();
        for (Command c : commands) {
            sb.append(prefix).append(c.name).append("\n");
        }
        return embedBuilder.addField(context.i18n(module.module.translationKey), sb.toString(), true).addBlankField(true).addBlankField(true);
    }
}
Also used : CommandRegistry(fredboat.commandmeta.CommandRegistry) CentralMessaging(fredboat.messaging.CentralMessaging) java.util(java.util) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) Command(fredboat.commandmeta.abs.Command) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) CommandContext(fredboat.commandmeta.abs.CommandContext) PermissionLevel(fredboat.definitions.PermissionLevel) TextUtils(fredboat.util.TextUtils) Collectors(java.util.stream.Collectors) CommandInitializer(fredboat.commandmeta.CommandInitializer) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Module(fredboat.definitions.Module) Context(fredboat.messaging.internal.Context) Nonnull(javax.annotation.Nonnull) DestroyCommand(fredboat.command.music.control.DestroyCommand) PermsUtil(fredboat.perms.PermsUtil) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) Command(fredboat.commandmeta.abs.Command) DestroyCommand(fredboat.command.music.control.DestroyCommand) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) DestroyCommand(fredboat.command.music.control.DestroyCommand)

Example 3 with ICommandRestricted

use of fredboat.commandmeta.abs.ICommandRestricted in project FredBoat by Frederikam.

the class CommandManager method prefixCalled.

public void prefixCalled(CommandContext context) {
    Guild guild = context.guild;
    Command invoked = context.command;
    TextChannel channel = context.channel;
    Member invoker = context.invoker;
    totalCommandsExecuted.incrementAndGet();
    Metrics.commandsExecuted.labels(invoked.getClass().getSimpleName()).inc();
    if (FeatureFlags.PATRON_VALIDATION.isActive()) {
        PatronageChecker.Status status = patronageChecker.getStatus(guild);
        if (!status.isValid()) {
            String msg = "Access denied. This bot can only be used if invited from <https://patron.fredboat.com/> " + "by someone who currently has a valid pledge on Patreon.\n**Denial reason:** " + status.getReason() + "\n\n";
            msg += "Do you believe this to be a mistake? If so reach out to Fre_d on Patreon <" + BotConstants.PATREON_CAMPAIGN_URL + ">";
            context.reply(msg);
            return;
        }
    }
    // Hardcode music commands in FredBoatHangout. Blacklist any channel that isn't #spam_and_music or #staff, but whitelist Admins
    if (guild.getIdLong() == BotConstants.FREDBOAT_HANGOUT_ID && DiscordUtil.isOfficialBot(credentials)) {
        if (// #spam_and_music
        !channel.getId().equals("174821093633294338") && // #staff
        !channel.getId().equals("217526705298866177") && !PermsUtil.checkPerms(PermissionLevel.ADMIN, invoker)) {
            context.deleteMessage();
            context.replyWithName("Please read <#219483023257763842> for server rules and only use commands in <#174821093633294338>!", msg -> CentralMessaging.restService.schedule(() -> CentralMessaging.deleteMessage(msg), 5, TimeUnit.SECONDS));
            return;
        }
    }
    if (disabledCommands.contains(invoked)) {
        context.replyWithName("Sorry the `" + context.command.name + "` command is currently disabled. Please try again later");
        return;
    }
    if (invoked instanceof ICommandRestricted) {
        if (!PermsUtil.checkPermsWithFeedback(((ICommandRestricted) invoked).getMinimumPerms(), context)) {
            return;
        }
    }
    if (invoked instanceof IMusicCommand) {
        musicTextChannelProvider.setMusicChannel(channel);
    }
    try {
        invoked.onInvoke(context);
    } catch (Exception e) {
        TextUtils.handleException(e, context);
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) PatronageChecker(fredboat.feature.PatronageChecker) Command(fredboat.commandmeta.abs.Command) IMusicCommand(fredboat.commandmeta.abs.IMusicCommand) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) Guild(net.dv8tion.jda.core.entities.Guild) IMusicCommand(fredboat.commandmeta.abs.IMusicCommand) Member(net.dv8tion.jda.core.entities.Member)

Aggregations

Command (fredboat.commandmeta.abs.Command)3 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)3 IInfoCommand (fredboat.commandmeta.abs.IInfoCommand)2 PrefixCommand (fredboat.command.config.PrefixCommand)1 DestroyCommand (fredboat.command.music.control.DestroyCommand)1 SelectCommand (fredboat.command.music.control.SelectCommand)1 CommandInitializer (fredboat.commandmeta.CommandInitializer)1 CommandRegistry (fredboat.commandmeta.CommandRegistry)1 CommandContext (fredboat.commandmeta.abs.CommandContext)1 IMusicCommand (fredboat.commandmeta.abs.IMusicCommand)1 Module (fredboat.definitions.Module)1 PermissionLevel (fredboat.definitions.PermissionLevel)1 PatronageChecker (fredboat.feature.PatronageChecker)1 CentralMessaging (fredboat.messaging.CentralMessaging)1 Context (fredboat.messaging.internal.Context)1 PermsUtil (fredboat.perms.PermsUtil)1 TextUtils (fredboat.util.TextUtils)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1