Search in sources :

Example 11 with Variables

use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.

the class MessageListener method doAutoModChecks.

private boolean doAutoModChecks(@Nonnull GuildMessageReceivedEvent event, GuildSetting settings, String raw) {
    final Guild guild = event.getGuild();
    if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) && !Objects.requireNonNull(event.getMember()).hasPermission(Permission.MESSAGE_MANAGE)) {
        checkMessageForInvites(guild, event, settings, raw);
        final Message messageToCheck = event.getMessage();
        final DunctebotGuild dbG = new DunctebotGuild(event.getGuild(), variables);
        if (blacklistedWordCheck(dbG, messageToCheck, event.getMember(), settings.getBlacklistedWords())) {
            return true;
        }
        if (checkSwearFilter(messageToCheck, event, dbG)) {
            return true;
        }
        checkSpamFilter(messageToCheck, event, settings, dbG);
    }
    return false;
}
Also used : DunctebotGuild(ml.duncte123.skybot.entities.jda.DunctebotGuild) DunctebotGuild(ml.duncte123.skybot.entities.jda.DunctebotGuild)

Example 12 with Variables

use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.

the class SQLiteTimers method checkUnbansAndUnmutes.

private static void checkUnbansAndUnmutes(Variables variables) {
    variables.getDatabaseAdapter().getExpiredBansAndMutes((bans, mutes) -> {
        final DatabaseAdapter adapter = variables.getDatabaseAdapter();
        handleUnban(bans, adapter, variables);
        handleUnmute(mutes, adapter, variables);
        return null;
    });
}
Also used : DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

Example 13 with Variables

use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.

the class MessageListener method onGuildMessageDelete.

protected void onGuildMessageDelete(final GuildMessageDeleteEvent event) {
    this.handlerThread.submit(() -> {
        try {
            final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
            if (!guild.getSettings().isMessageLogging()) {
                // just delete the message here as we don't want to keep it around
                this.redis.deleteMessage(event.getMessageId());
                return;
            }
            final MessageData data = this.redis.getAndDeleteMessage(event.getMessageId());
            if (data != null) {
                this.logDeletedMessage(data, guild);
            }
        } catch (Exception e) {
            LOGGER.error("Exception on message delete", e);
        }
    });
}
Also used : DunctebotGuild(ml.duncte123.skybot.entities.jda.DunctebotGuild) MessageData(ml.duncte123.skybot.objects.discord.MessageData)

Example 14 with Variables

use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.

the class CommandManager method runCustomCommand.

private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
    final CustomCommand cusomCommand = (CustomCommand) cmd;
    if (cusomCommand.getGuildId() != event.getGuild().getIdLong()) {
        return;
    }
    try {
        MDC.put("command.custom.message", cusomCommand.getMessage());
        final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables));
        final String message = parser.parse(cusomCommand.getMessage());
        final MessageConfig.Builder messageBuilder = MessageConfig.Builder.fromEvent(event);
        final DataObject object = parser.get("embed");
        boolean hasContent = false;
        if (!message.isEmpty()) {
            messageBuilder.setMessage("\u200B" + message);
            hasContent = true;
        }
        if (object != null) {
            final JDAImpl jda = (JDAImpl) event.getJDA();
            final EmbedBuilder embed = new EmbedBuilder(jda.getEntityBuilder().createMessageEmbed(object));
            messageBuilder.addEmbed(true, embed);
            hasContent = true;
        }
        if (hasContent) {
            sendMsg(messageBuilder.build());
        }
        parser.clear();
    } catch (Exception e) {
        sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Error with parsing custom command: " + e.getMessage()).build());
        Sentry.captureException(e);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) CustomCommand(ml.duncte123.skybot.objects.command.custom.CustomCommand) MessageConfig(me.duncte123.botcommons.messaging.MessageConfig) DataObject(net.dv8tion.jda.api.utils.data.DataObject) CommandContext(ml.duncte123.skybot.objects.command.CommandContext) JDAImpl(net.dv8tion.jda.internal.JDAImpl) Parser(com.jagrosh.jagtag.Parser)

Example 15 with Variables

use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.

the class CommandManager method runNormalCommand.

private void runNormalCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
    if (cmd.getCategory() == CommandCategory.NSFW && this.isSafeForWork(event)) {
        sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Woops, this channel is not marked as NSFW.\n" + "Please mark this channel as NSFW to use this command").build());
        return;
    }
    MDC.put("command.class", cmd.getClass().getName());
    LOGGER.info("Dispatching command \"{}\" in guild \"{}\" with {}", cmd.getClass().getSimpleName(), event.getGuild(), args);
    cmd.executeCommand(new CommandContext(invoke, args, event, variables));
}
Also used : CommandContext(ml.duncte123.skybot.objects.command.CommandContext)

Aggregations

DunctebotGuild (ml.duncte123.skybot.entities.jda.DunctebotGuild)8 CommandContext (ml.duncte123.skybot.objects.command.CommandContext)8 MessageData (ml.duncte123.skybot.objects.discord.MessageData)8 GuildSetting (com.dunctebot.models.settings.GuildSetting)6 CustomCommand (ml.duncte123.skybot.objects.command.custom.CustomCommand)6 UnknownUser (ml.duncte123.skybot.objects.user.UnknownUser)6 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)6 MessageConfig (me.duncte123.botcommons.messaging.MessageConfig)4 DatabaseAdapter (ml.duncte123.skybot.adapters.DatabaseAdapter)4 Parser (com.jagrosh.jagtag.Parser)2 TLongLongMap (gnu.trove.map.TLongLongMap)2 TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)2 Sentry (io.sentry.Sentry)2 Instant (java.time.Instant)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 java.util (java.util)2 Executors (java.util.concurrent.Executors)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 TimeUnit (java.util.concurrent.TimeUnit)2 Consumer (java.util.function.Consumer)2