Search in sources :

Example 6 with Variables

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

the class GuildSettingsUtils method loadVcAutoRoles.

public static void loadVcAutoRoles(Variables variables) {
    final DatabaseAdapter adapter = variables.getDatabaseAdapter();
    final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
    LOGGER.info("Loading vc auto roles.");
    adapter.getVcAutoRoles((items) -> {
        items.forEach((item) -> {
            final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
                // This returns the old value which was null
                vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
                return vcAutoRoleCache.get(item.getGuildId());
            });
            cache.put(item.getVoiceChannelId(), item.getRoleId());
        });
        LOGGER.info("Loaded " + items.size() + " vc auto roles.");
        return null;
    });
}
Also used : TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) TLongLongMap(gnu.trove.map.TLongLongMap) DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

Example 7 with Variables

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

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 8 with Variables

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

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)

Example 9 with Variables

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

the class AudioUtils method getMusicManager.

public GuildMusicManager getMusicManager(long guildId) {
    synchronized (this) {
        GuildMusicManager mng = musicManagers.get(guildId);
        if (mng == null) {
            mng = new GuildMusicManager(guildId, variables);
            musicManagers.put(guildId, mng);
        }
        return mng;
    }
}
Also used : GuildMusicManager(ml.duncte123.skybot.audio.GuildMusicManager)

Example 10 with Variables

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

the class GuildSettingsUtils method loadVcAutoRoles.

public static void loadVcAutoRoles(Variables variables) {
    final DatabaseAdapter adapter = variables.getDatabaseAdapter();
    final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
    LOGGER.info("Loading vc auto roles.");
    adapter.getVcAutoRoles((items) -> {
        items.forEach((item) -> {
            final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
                // This returns the old value which was null
                vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
                return vcAutoRoleCache.get(item.getGuildId());
            });
            cache.put(item.getVoiceChannelId(), item.getRoleId());
        });
        LOGGER.info("Loaded " + items.size() + " vc auto roles.");
        return null;
    });
}
Also used : TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) TLongLongMap(gnu.trove.map.TLongLongMap) DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

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