Java Code Examples for net.dv8tion.jda.api.utils.cache.CacheFlag#getRequiredIntent()

The following examples show how to use net.dv8tion.jda.api.utils.cache.CacheFlag#getRequiredIntent() . 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: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private DefaultShardManagerBuilder applyIntents()
{
    EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class);
    for (CacheFlag flag : CacheFlag.values())
    {
        GatewayIntent requiredIntent = flag.getRequiredIntent();
        if (requiredIntent == null || (requiredIntent.getRawValue() & intents) != 0)
            disabledCache.remove(flag);
    }

    boolean enableMembers = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    return setChunkingFilter(enableMembers ? ChunkingFilter.ALL : ChunkingFilter.NONE)
            .setMemberCachePolicy(enableMembers ? MemberCachePolicy.ALL : MemberCachePolicy.DEFAULT)
            .setDisabledCache(disabledCache);
}
 
Example 2
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void checkIntents()
{
    boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL)
        throw new IllegalStateException("Cannot use MemberCachePolicy.ALL without GatewayIntent.GUILD_MEMBERS enabled!");
    else if (!membersIntent && chunkingFilter != ChunkingFilter.NONE)
        DefaultShardManager.LOG.warn("Member chunking is disabled due to missing GUILD_MEMBERS intent.");

    if (!automaticallyDisabled.isEmpty())
    {
        JDAImpl.LOG.warn("Automatically disabled CacheFlags due to missing intents");
        // List each missing intent
        automaticallyDisabled.stream()
            .map(it -> "Disabled CacheFlag." + it + " (missing GatewayIntent." + it.getRequiredIntent() + ")")
            .forEach(JDAImpl.LOG::warn);

        // Tell user how to disable this warning
        JDAImpl.LOG.warn("You can manually disable these flags to remove this warning by using disableCache({}) on your DefaultShardManagerBuilder",
            automaticallyDisabled.stream()
                    .map(it -> "CacheFlag." + it)
                    .collect(Collectors.joining(", ")));
        // Only print this warning once
        automaticallyDisabled.clear();
    }

    if (cacheFlags.isEmpty())
        return;

    EnumSet<GatewayIntent> providedIntents = GatewayIntent.getIntents(intents);
    for (CacheFlag flag : cacheFlags)
    {
        GatewayIntent intent = flag.getRequiredIntent();
        if (intent != null && !providedIntents.contains(intent))
            throw new IllegalArgumentException("Cannot use CacheFlag." + flag + " without GatewayIntent." + intent + "!");
    }
}
 
Example 3
Source File: JDABuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private JDABuilder applyIntents()
{
    EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class);
    for (CacheFlag flag : CacheFlag.values())
    {
        GatewayIntent requiredIntent = flag.getRequiredIntent();
        if (requiredIntent == null || (requiredIntent.getRawValue() & intents) != 0)
            disabledCache.remove(flag);
    }

    boolean enableMembers = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    return setChunkingFilter(enableMembers ? ChunkingFilter.ALL : ChunkingFilter.NONE)
            .setMemberCachePolicy(enableMembers ? MemberCachePolicy.ALL : MemberCachePolicy.DEFAULT)
            .setDisabledCache(disabledCache);
}
 
Example 4
Source File: JDABuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void checkIntents()
{
    boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL)
        throw new IllegalStateException("Cannot use MemberCachePolicy.ALL without GatewayIntent.GUILD_MEMBERS enabled!");
    else if (!membersIntent && chunkingFilter != ChunkingFilter.NONE)
        JDAImpl.LOG.warn("Member chunking is disabled due to missing GUILD_MEMBERS intent.");

    if (!automaticallyDisabled.isEmpty())
    {
        JDAImpl.LOG.warn("Automatically disabled CacheFlags due to missing intents");
        // List each missing intent
        automaticallyDisabled.stream()
            .map(it -> "Disabled CacheFlag." + it + " (missing GatewayIntent." + it.getRequiredIntent() + ")")
            .forEach(JDAImpl.LOG::warn);

        // Tell user how to disable this warning
        JDAImpl.LOG.warn("You can manually disable these flags to remove this warning by using disableCache({}) on your JDABuilder",
            automaticallyDisabled.stream()
                .map(it -> "CacheFlag." + it)
                .collect(Collectors.joining(", ")));
        // Only print this warning once
        automaticallyDisabled.clear();
    }

    if (cacheFlags.isEmpty())
        return;

    EnumSet<GatewayIntent> providedIntents = GatewayIntent.getIntents(intents);
    for (CacheFlag flag : cacheFlags)
    {
        GatewayIntent intent = flag.getRequiredIntent();
        if (intent != null && !providedIntents.contains(intent))
            throw new IllegalArgumentException("Cannot use CacheFlag." + flag + " without GatewayIntent." + intent + "!");
    }
}