Search in sources :

Example 1 with JsonErrorMessageFactory

use of com.github.kaktushose.jda.commands.embeds.error.JsonErrorMessageFactory in project Levelbot by Kaktushose.

the class Levelbot method start.

public Levelbot start() throws LoginException, InterruptedException {
    log.info("Bot is running at version {}", settingsService.getVersion(guildId));
    embedCache.loadEmbedsToCache();
    log.debug("Starting jda...");
    String token = settingsService.getBotToken(guildId);
    jda = JDABuilder.create(token, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_PRESENCES).disableCache(CacheFlag.EMOTE, CacheFlag.CLIENT_STATUS).enableCache(CacheFlag.ACTIVITY).setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.NONE).setActivity(Activity.playing("starting...")).setStatus(OnlineStatus.DO_NOT_DISTURB).build().awaitReady();
    log.debug("Registering event listeners...");
    jda.addEventListener(new JoinLeaveListener(this), new LevelListener(this), new VoiceTextLink(jda.getTextChannelById(839226183409467442L)), new ShopListener(this), new DailyRewardListener(this), new ContestEventListener(settingsService, eventService));
    log.debug("Starting ReactionListener...");
    ReactionListener.setAutoRemove(true);
    ReactionListener.setAutoRemoveDelay(60, TimeUnit.SECONDS);
    ReactionListener.startListening(jda);
    log.debug("Starting jda-commands...");
    jdaCommands = JDACommands.start(jda, Bootstrapper.class, "de.kaktushose.levelbot");
    EmbedCache embeds = new EmbedCache("jdacEmbeds.json");
    embeds.loadEmbedsToCache();
    jdaCommands.getImplementationRegistry().setHelpMessageFactory(new JsonHelpMessageFactory(embeds));
    jdaCommands.getImplementationRegistry().setErrorMessageFactory(new JsonErrorMessageFactory(embeds));
    guild = jda.getGuildById(guildId);
    botChannel = guild.getTextChannelById(settingsService.getBotChannelId(guildId));
    logChannel = guild.getTextChannelById(settingsService.getLogChannelId(guildId));
    // first start of bot, check for expired items immediately
    shopService.checkForExpiredItems();
    // get offset time until it's 0 am, also ensures that this task only runs once every 24 hours
    long current = TimeUnit.HOURS.toMinutes(Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) + Calendar.getInstance().get(Calendar.MINUTE);
    long delay = TimeUnit.HOURS.toMinutes(24) - current;
    taskScheduler.addRepetitiveTask(() -> {
        log.info("Starting daily tasks!");
        try {
            log.info("Sending dm rank infos...");
            dmRankInfo();
            log.info("Checking for expired items...");
            shopService.checkForExpiredItems();
            log.info("Checking for new nitro boosters...");
            boosterService.updateBoosterStatus(guild, botChannel, embedCache);
            log.info("Checking for booster rewards...");
            checkForNitroBoostersRewards();
            log.info("Update user statistics...");
            updateUserStatistics();
            log.info("Done!");
        } catch (Throwable t) {
            log.error("An exception has occurred while executing daily tasks!", t);
        }
    }, delay, TimeUnit.HOURS.toMinutes(24), TimeUnit.MINUTES);
    taskScheduler.addRepetitiveTask(() -> {
        try {
            updateStatistics();
        } catch (Throwable t) {
            log.error("An exception has occurred while updating statistics!", t);
        }
    }, 0, 4, TimeUnit.HOURS);
    String version = settingsService.getVersion(guildId);
    jda.getPresence().setStatus(OnlineStatus.ONLINE);
    jda.getPresence().setActivity(Activity.playing(version));
    getBotChannel().sendMessageEmbeds(embedCache.getEmbed("botStart").injectValue("version", version).toMessageEmbed()).queue();
    httpServer.start();
    return this;
}
Also used : JsonErrorMessageFactory(com.github.kaktushose.jda.commands.embeds.error.JsonErrorMessageFactory) ShopListener(de.kaktushose.levelbot.shop.ShopListener) EmbedCache(com.github.kaktushose.jda.commands.embeds.EmbedCache) JsonHelpMessageFactory(com.github.kaktushose.jda.commands.embeds.help.JsonHelpMessageFactory) Bootstrapper(de.kaktushose.levelbot.Bootstrapper)

Aggregations

EmbedCache (com.github.kaktushose.jda.commands.embeds.EmbedCache)1 JsonErrorMessageFactory (com.github.kaktushose.jda.commands.embeds.error.JsonErrorMessageFactory)1 JsonHelpMessageFactory (com.github.kaktushose.jda.commands.embeds.help.JsonHelpMessageFactory)1 Bootstrapper (de.kaktushose.levelbot.Bootstrapper)1 ShopListener (de.kaktushose.levelbot.shop.ShopListener)1