Search in sources :

Example 1 with HelpCommand

use of fredboat.command.info.HelpCommand in project FredBoat by Frederikam.

the class EventListenerBoat method doOnMessageReceived.

private void doOnMessageReceived(MessageReceivedEvent event) {
    if (ratelimiter.isBlacklisted(event.getAuthor().getIdLong())) {
        Metrics.blacklistedMessagesReceived.inc();
        return;
    }
    if (event.getPrivateChannel() != null) {
        log.info("PRIVATE" + " \t " + event.getAuthor().getName() + " \t " + event.getMessage().getContentRaw());
        return;
    }
    if (event.getAuthor().equals(event.getJDA().getSelfUser())) {
        log.info(event.getMessage().getContentRaw());
        return;
    }
    if (event.getAuthor().isBot()) {
        return;
    }
    // never null since we are filtering private messages out above
    TextChannel channel = event.getTextChannel();
    // where we can't talk in
    if (!channel.canTalk() && !event.getMessage().getContentRaw().toLowerCase().contains(CommandInitializer.HELP_COMM_NAME)) {
        return;
    }
    CommandContext context = commandContextParser.parse(event);
    if (context == null) {
        return;
    }
    log.info(event.getMessage().getContentRaw());
    // ignore all commands in channels where we can't write, except for the help command
    if (!channel.canTalk() && !(context.command instanceof HelpCommand)) {
        log.info("Ignoring command {} because this bot cannot write in that channel", context.command.name);
        return;
    }
    Metrics.commandsReceived.labels(context.command.getClass().getSimpleName()).inc();
    // BOT_ADMINs can always use all commands everywhere
    if (!PermsUtil.checkPerms(PermissionLevel.BOT_ADMIN, event.getMember())) {
        // ignore commands of disabled modules for plebs
        Module module = context.command.getModule();
        if (module != null && !context.getEnabledModules().contains(module)) {
            log.debug("Ignoring command {} because its module {} is disabled in guild {}", context.command.name, module.name(), event.getGuild().getIdLong());
            return;
        }
    }
    limitOrExecuteCommand(context);
}
Also used : CommandContext(fredboat.commandmeta.abs.CommandContext) HelpCommand(fredboat.command.info.HelpCommand) Module(fredboat.definitions.Module)

Aggregations

HelpCommand (fredboat.command.info.HelpCommand)1 CommandContext (fredboat.commandmeta.abs.CommandContext)1 Module (fredboat.definitions.Module)1