Java Code Examples for net.dv8tion.jda.api.requests.RestAction#setPassContext()

The following examples show how to use net.dv8tion.jda.api.requests.RestAction#setPassContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiscordServiceImpl.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
public void init() {
    String token = workerProperties.getDiscord().getToken();
    Objects.requireNonNull(token, "No Discord Token specified");
    try {
        RestAction.setPassContext(false);
        DefaultShardManagerBuilder builder = new DefaultShardManagerBuilder()
                .setToken(token)
                .setEventManagerProvider(id -> eventManager)
                .addEventListeners(this)
                .setShardsTotal(workerProperties.getDiscord().getShardsTotal())
                .setEnableShutdownHook(false);
        if (audioService != null) {
            audioService.configure(this, builder);
        }
        shardManager = builder.build();
    } catch (LoginException e) {
        log.error("Could not login user with specified token", e);
    }
}
 
Example 2
Source File: SkyBot.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
private SkyBot() throws Exception {
        // Set our animated emotes as default reactions
        MessageUtils.setErrorReaction("a:_no:577795484060483584");
        MessageUtils.setSuccessReaction("a:_yes:577795293546938369");

        // Load in our container
        final Variables variables = new Variables();
        final DunctebotConfig config = variables.getConfig();
        final CommandManager commandManager = variables.getCommandManager();
        final Logger logger = LoggerFactory.getLogger(SkyBot.class);

        // Set the user-agent of the bot
        WebUtils.setUserAgent("Mozilla/5.0 (compatible; SkyBot/" + Settings.VERSION + "; +https://dunctebot.com;)");
        EmbedUtils.setEmbedBuilder(
            () -> new EmbedBuilder()
                .setColor(Settings.DEFAULT_COLOUR)
//                .setFooter("DuncteBot", Settings.DEFAULT_ICON)
//                .setTimestamp(Instant.now())
        );

        Settings.PREFIX = config.discord.prefix;

        // Set some defaults for rest-actions
        RestAction.setPassContext(true);
        RestAction.setDefaultFailure(ignore(UNKNOWN_MESSAGE));
        // If any rest-action doesn't get executed within 2 minutes we will mark it as failed
        RestAction.setDefaultTimeout(2L, TimeUnit.MINUTES);

        if (variables.useApi()) {
            logger.info(TextColor.GREEN + "Using api for all connections" + TextColor.RESET);
        } else {
            logger.warn("Using SQLite as the database");
            logger.warn("Please note that is is not recommended for production");
        }

        //Load the settings before loading the bot
        GuildSettingsUtils.loadAllSettings(variables);

        //Set the token to a string
        final String token = config.discord.token;

        //But this time we are going to shard it
        final int totalShards = config.discord.totalShards;

        this.activityProvider = (shardId) -> Activity.playing(
            config.discord.prefix + "help | Shard " + (shardId + 1)
        );

        final LongLongPair commandCount = commandManager.getCommandCount();

        logger.info("{} commands with {} aliases loaded.", commandCount.getFirst(), commandCount.getSecond());
        LavalinkManager.ins.start(config, variables.getAudioUtils());

        final EventManager eventManager = new EventManager(variables);
        // Build our shard manager
        final DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(
            GatewayIntent.GUILD_MEMBERS,
            GatewayIntent.GUILD_BANS,
            GatewayIntent.GUILD_EMOJIS,
            GatewayIntent.GUILD_VOICE_STATES,
            GatewayIntent.GUILD_MESSAGES
        )
            .setToken(token)
            .setShardsTotal(totalShards)
            .setActivityProvider(this.activityProvider)
            .setBulkDeleteSplittingEnabled(false)
            .setEventManagerProvider((id) -> eventManager)
            // Keep guild owners, voice members and patrons in cache
            .setMemberCachePolicy(MemberCachePolicy.DEFAULT.or(PATRON_POLICY))
//            .setMemberCachePolicy(MemberCachePolicy.NONE)
            // Enable lazy loading
            .setChunkingFilter(ChunkingFilter.NONE)
            // Enable lazy loading for guilds other than our own
//            .setChunkingFilter((guildId) -> guildId == Settings.SUPPORT_GUILD_ID)
            .enableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES)
            .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS)
            .setHttpClientBuilder(
                new OkHttpClient.Builder()
                    .connectTimeout(30L, TimeUnit.SECONDS)
                    .readTimeout(30L, TimeUnit.SECONDS)
                    .writeTimeout(30L, TimeUnit.SECONDS)
            );

        this.startGameTimer();

        // If lavalink is enabled we will hook it into jda
        if (LavalinkManager.ins.isEnabled()) {
            builder.setVoiceDispatchInterceptor(LavalinkManager.ins.getLavalink().getVoiceInterceptor());
        }

        this.shardManager = builder.build();

        HelpEmbeds.init(commandManager);

        // Load the web server if we are not running "locally"
        // TODO: change this config value to "web_server" or something
        if (!config.discord.local) {
            webRouter = new WebRouter(shardManager, variables);
        }
    }