Class CatnipOptions
- All Implemented Interfaces:
CatnipOptionsView
,Cloneable
- Since:
- 9/25/18.
- Author:
- amy
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionapiHost()
The host used for Discord API requests.int
apiVersion
(int apiVersion) The cache worker for catnip to use.cacheWorker
(EntityCacheWorker cacheWorker) boolean
Whether or not catnip should capture REST stacktraces before running REST requests.captureRestStacktraces
(boolean captureRestStacktraces) boolean
Whether or not catnip should chunk members.chunkMembers
(boolean chunkMembers) clone()
How catnip compresses incoming events from Discord.compressionMode
(CompressionMode compressionMode) com.grack.nanojson.JsonObject
customIdentifyOptions
(com.grack.nanojson.JsonObject customIdentifyOptions) The events that catnip should not emit.disabledEvents
(Set<String> disabledEvents) Manages event dispatching and consumers.dispatchManager
(DispatchManager dispatchManager) boolean
Whether or not catnip should emit full event objects.emitEventObjects
(boolean emitEventObjects) boolean
Whether or not Discord should subscribe to guild workers and provide stuff such as presence updates, typing events, member updates and other stuff, see discord-api-docs#1016 for more information.enableGuildSubscriptions
(boolean enableGuildSubscriptions) boolean
Whether or not catnip should enforce permissions for REST actions.enforcePermissions
(boolean enforcePermissions) entityDelegator
(EntityDelegator entityDelegator) The entity serializer that catnip uses for de/serializing entities for external usage.entitySerializer
(EntitySerializer<?> entitySerializer) The event buffer for catnip to use.eventBuffer
(EventBuffer eventBuffer) The gateway ratelimiter for catnip to use.gatewayRatelimiter
(Ratelimiter gatewayRatelimiter) long
If heartbeat latency takes longer than this much time, catnip will emit aHighWebsocketLatency
event containing information about which shard is experiencing high latency and how high the latency is.
This value is specified in nanoseconds.highLatencyThreshold
(long highLatencyThreshold) The HTTP client that catnip uses internally for websockets and REST requests.httpClient
(HttpClient httpClient) The presence that catnip should set for shards as they log in.initialPresence
(Presence initialPresence) intents()
intents
(Set<GatewayIntent> intents) boolean
iReallyWantToStartTheBotWithNoIntents
(boolean iReallyWantToStartTheBotWithNoIntents) int
Total number of members where the gateway will stop sending offline members in the guild member list.largeThreshold
(int largeThreshold) The log adapter for catnip to use.logAdapter
(LogAdapter logAdapter) boolean
logEntityPresenceWarningOnCustomCache
(boolean logEntityPresenceWarningOnCustomCache) boolean
logEventNotInIntentsWarning
(boolean logEventNotInIntentsWarning) boolean
Whether or not extensions overriding options should be logged.logExtensionOverrides
(boolean logExtensionOverrides) boolean
If this option is enabled, lifecycle-related events -- things like shard connects / disconnects, 429 HTTP responses, ...logLifecycleEvents
(boolean logLifecycleEvents) boolean
logPrivilegedIntentWarning
(boolean logPrivilegedIntentWarning) boolean
Whether or not to log "Received presence for uncached user XXX" when catnip is not chunking members.logUncachedPresenceWhenNotChunking
(boolean logUncachedPresenceWhenNotChunking) boolean
If this option is enabled, emit aMemberChunkRerequest
over the event bus when a shard needs to re-request member chunks for a guild, instead of automatically re-requesting them.manualChunkRerequesting
(boolean manualChunkRerequesting) long
How long catnip should wait to ensure that all member chunks have been received, in milliseconds.memberChunkTimeout
(long memberChunkTimeout) The application's public key.The requester catnip uses for REST requests.boolean
Whether or not catnip should assume the inability to have a properly synchronized clock when computing REST ratelimits.restRatelimitsWithoutClockSync
(boolean restRatelimitsWithoutClockSync) io.reactivex.rxjava3.core.Scheduler
The RxJava scheduler that catnip should use for scheduling things like stream subscriptions.rxScheduler
(io.reactivex.rxjava3.core.Scheduler rxScheduler) The session manager for catnip to use.sessionManager
(SessionManager sessionManager) The shard manager for catnip to use.shardManager
(ShardManager shardManager) The task scheduler that catnip will use for scheduling its own internal tasks.taskScheduler
(TaskScheduler taskScheduler) token()
The token for catnip to use.boolean
Whether or not to validate the provided token when setting up catnip.validateToken
(boolean validateToken)
-
Constructor Details
-
CatnipOptions
-
-
Method Details
-
clone
-
token
Description copied from interface:CatnipOptionsView
The token for catnip to use.May not be overridden by extensions.
- Specified by:
token
in interfaceCatnipOptionsView
-
publicKey
Description copied from interface:CatnipOptionsView
The application's public key. Used for interactions (think slash commands).May not be overriden by extensions.
- Specified by:
publicKey
in interfaceCatnipOptionsView
-
shardManager
Description copied from interface:CatnipOptionsView
The shard manager for catnip to use. Defaults toDefaultShardManager
.- Specified by:
shardManager
in interfaceCatnipOptionsView
-
sessionManager
Description copied from interface:CatnipOptionsView
The session manager for catnip to use. Defaults toDefaultSessionManager
- Specified by:
sessionManager
in interfaceCatnipOptionsView
-
gatewayRatelimiter
Description copied from interface:CatnipOptionsView
The gateway ratelimiter for catnip to use. Defaults toMemoryRatelimiter
- Specified by:
gatewayRatelimiter
in interfaceCatnipOptionsView
-
logAdapter
Description copied from interface:CatnipOptionsView
The log adapter for catnip to use. Defaults toDefaultLogAdapter
, which uses SLF4J.- Specified by:
logAdapter
in interfaceCatnipOptionsView
-
eventBuffer
Description copied from interface:CatnipOptionsView
The event buffer for catnip to use. Defaults toCachingBuffer
. If you want to use an alternative event buffering strategy (ex. no buffering, only buffer certain events, ...) you can write your own implementation. For no buffering,NoopBuffer
is provided.Do NOT change this if you don't know what you're doing!
- Specified by:
eventBuffer
in interfaceCatnipOptionsView
-
cacheWorker
Description copied from interface:CatnipOptionsView
The cache worker for catnip to use. Defaults toSplitMemoryEntityCache
. Change this if you want to use your ownEntityCacheWorker
.- Specified by:
cacheWorker
in interfaceCatnipOptionsView
-
dispatchManager
Description copied from interface:CatnipOptionsView
Manages event dispatching and consumers. Defaults toDefaultDispatchManager
.- Specified by:
dispatchManager
in interfaceCatnipOptionsView
-
chunkMembers
public boolean chunkMembers()Description copied from interface:CatnipOptionsView
Whether or not catnip should chunk members. Do not disable this if you don't know what it does.- Specified by:
chunkMembers
in interfaceCatnipOptionsView
-
emitEventObjects
public boolean emitEventObjects()Description copied from interface:CatnipOptionsView
Whether or not catnip should emit full event objects. Do not disable this if you don't know what it does. Mainly only useful for ex. anExtension
that does things with the raw gateway payloads, like sending them to a message queue.- Specified by:
emitEventObjects
in interfaceCatnipOptionsView
-
enforcePermissions
public boolean enforcePermissions()Description copied from interface:CatnipOptionsView
Whether or not catnip should enforce permissions for REST actions. Note that this will NOT enforce permissions if you directly call methods viaCatnip.rest()
, but will enforce them if you call them from entity objects (ex. doingGuild.delete()
).- Specified by:
enforcePermissions
in interfaceCatnipOptionsView
-
initialPresence
Description copied from interface:CatnipOptionsView
The presence that catnip should set for shards as they log in. This is for setting whether your bot appears online/DND/away/offline, as well as the "playing XXX" status.- Specified by:
initialPresence
in interfaceCatnipOptionsView
-
disabledEvents
Description copied from interface:CatnipOptionsView
The events that catnip should not emit. You can useDiscordEvent.Raw
to get the event names.- Specified by:
disabledEvents
in interfaceCatnipOptionsView
-
requester
Description copied from interface:CatnipOptionsView
The requester catnip uses for REST requests. Defaults toSerialRequester
.- Specified by:
requester
in interfaceCatnipOptionsView
-
logExtensionOverrides
public boolean logExtensionOverrides()Description copied from interface:CatnipOptionsView
Whether or not extensions overriding options should be logged. Defaults totrue
.May not be overridden by extensions.
- Specified by:
logExtensionOverrides
in interfaceCatnipOptionsView
-
validateToken
public boolean validateToken()Description copied from interface:CatnipOptionsView
Whether or not to validate the provided token when setting up catnip. It is HIGHLY recommended that you leave this with the default setting.May not be overridden by extensions.
- Specified by:
validateToken
in interfaceCatnipOptionsView
-
captureRestStacktraces
public boolean captureRestStacktraces()Description copied from interface:CatnipOptionsView
Whether or not catnip should capture REST stacktraces before running REST requests.catnip runs REST requests asynchronously. Because of this, we lose the caller's stacktrace, and exceptions thrown from REST calls are lost to the ether basically. If this option is enabled, catnip will capture a stacktrace before REST requests, and make it available to any exceptions thrown by the REST handler.
NOTE: Capturing stacktraces is s l o w. If you have performance problems around REST requests, you can disable this, at the cost of losing debuggability. Note that it may be useful to add
-XX:-OmitStackTraceInFastThrow
to your JVM flags to ensure that this doesn't get optimized out.TODO: Verify that -XX:-OmitStackTraceInFastThrow isn't needed now.
- Specified by:
captureRestStacktraces
in interfaceCatnipOptionsView
-
logUncachedPresenceWhenNotChunking
public boolean logUncachedPresenceWhenNotChunking()Description copied from interface:CatnipOptionsView
Whether or not to log "Received presence for uncached user XXX" when catnip is not chunking members. Basically, this avoids a ton of logspam.- Specified by:
logUncachedPresenceWhenNotChunking
in interfaceCatnipOptionsView
-
enableGuildSubscriptions
public boolean enableGuildSubscriptions()Description copied from interface:CatnipOptionsView
Whether or not Discord should subscribe to guild workers and provide stuff such as presence updates, typing events, member updates and other stuff, see discord-api-docs#1016 for more information.- Specified by:
enableGuildSubscriptions
in interfaceCatnipOptionsView
-
memberChunkTimeout
public long memberChunkTimeout()Description copied from interface:CatnipOptionsView
How long catnip should wait to ensure that all member chunks have been received, in milliseconds. If all member chunks still haven't been received after this period, member chunking will be re-requested, to try to make sure we're not missing any.- Specified by:
memberChunkTimeout
in interfaceCatnipOptionsView
-
rxScheduler
public io.reactivex.rxjava3.core.Scheduler rxScheduler()Description copied from interface:CatnipOptionsView
The RxJava scheduler that catnip should use for scheduling things like stream subscriptions. Defaults toRxHelpers.FORK_JOIN_SCHEDULER
.- Specified by:
rxScheduler
in interfaceCatnipOptionsView
-
logLifecycleEvents
public boolean logLifecycleEvents()Description copied from interface:CatnipOptionsView
If this option is enabled, lifecycle-related events -- things like shard connects / disconnects, 429 HTTP responses, ... -- will be directly logged via the configuredCatnipOptionsView.logAdapter()
, in addition to being emitted over the event bus.- Specified by:
logLifecycleEvents
in interfaceCatnipOptionsView
-
manualChunkRerequesting
public boolean manualChunkRerequesting()Description copied from interface:CatnipOptionsView
If this option is enabled, emit aMemberChunkRerequest
over the event bus when a shard needs to re-request member chunks for a guild, instead of automatically re-requesting them.- Specified by:
manualChunkRerequesting
in interfaceCatnipOptionsView
-
largeThreshold
public int largeThreshold()Description copied from interface:CatnipOptionsView
Total number of members where the gateway will stop sending offline members in the guild member list. If a guild's member count is over this limit, member chunking will happen. SeeCatnipOptionsView.chunkMembers()
CatnipOptionsView.manualChunkRerequesting()
CatnipOptionsView.memberChunkTimeout()
for more. This must be between 50 and 250.For Discord's documentation, go here: https://discord.com/developers/docs/topics/gateway#identify-identify-structure
- Specified by:
largeThreshold
in interfaceCatnipOptionsView
-
taskScheduler
Description copied from interface:CatnipOptionsView
The task scheduler that catnip will use for scheduling its own internal tasks. This scheduler is exposed to the outside world throughCatnip.taskScheduler()
, and can safely be used for any task scheduling needs you may have. Defaults toRxTaskScheduler
.- Specified by:
taskScheduler
in interfaceCatnipOptionsView
-
httpClient
Description copied from interface:CatnipOptionsView
The HTTP client that catnip uses internally for websockets and REST requests. Defaults to an instance that usesRxHelpers.FORK_JOIN_POOL
as its executor.- Specified by:
httpClient
in interfaceCatnipOptionsView
-
compressionMode
Description copied from interface:CatnipOptionsView
How catnip compresses incoming events from Discord. Default isCompressionMode.ZLIB
.- Specified by:
compressionMode
in interfaceCatnipOptionsView
-
restRatelimitsWithoutClockSync
public boolean restRatelimitsWithoutClockSync()Description copied from interface:CatnipOptionsView
Whether or not catnip should assume the inability to have a properly synchronized clock when computing REST ratelimits. When this option is set totrue
, catnip will assume that the local clock cannot be properly synced, and will use a less-efficient method provided by Discord for computing REST ratelimits. See https://github.com/discord/discord-api-docs/pull/1069 for more info.- Specified by:
restRatelimitsWithoutClockSync
in interfaceCatnipOptionsView
-
highLatencyThreshold
public long highLatencyThreshold()Description copied from interface:CatnipOptionsView
If heartbeat latency takes longer than this much time, catnip will emit aHighWebsocketLatency
event containing information about which shard is experiencing high latency and how high the latency is.
This value is specified in nanoseconds.- Specified by:
highLatencyThreshold
in interfaceCatnipOptionsView
-
entitySerializer
Description copied from interface:CatnipOptionsView
The entity serializer that catnip uses for de/serializing entities for external usage. The value of this option will not affect how catnip behaves internally, but rather will affect user-controlled serialization for interfacing with the outside world.- Specified by:
entitySerializer
in interfaceCatnipOptionsView
-
apiHost
Description copied from interface:CatnipOptionsView
The host used for Discord API requests. Defaults tohttps://discord.com
. Changing this is only really useful for the case of ex. running tests against a local mock API. Providing the protocol is REQUIRED.- Specified by:
apiHost
in interfaceCatnipOptionsView
-
apiVersion
public int apiVersion()- Specified by:
apiVersion
in interfaceCatnipOptionsView
- Returns:
- The version of the Discord REST API to use. Defaults to
6
. Changing this is really only useful for the case of ex. running tests against a local mock API. Note that catnip is not tested against API v7, nor is v7 actively supported at this time.
-
intents
- Specified by:
intents
in interfaceCatnipOptionsView
- Returns:
- The set of gateway intents that this bot wishes to use. This is
OPTIONAL as of gateway v6, but will be REQUIRED in gateway v7.
Gateway intents are used to control the events that your bot receives. Intents are relatively-broad categories of events; see the documentation on each member ofGatewayIntent
for more information about what events are covered by each intent.
NOTE THAT THIS IS NOT THE SAME ASCatnipOptionsView.disabledEvents()
!
-
logPrivilegedIntentWarning
public boolean logPrivilegedIntentWarning()- Specified by:
logPrivilegedIntentWarning
in interfaceCatnipOptionsView
- Returns:
- Whether or not to log a warning about the use of privileged
GatewayIntent
s. Defaults totrue
.
-
customIdentifyOptions
@Nullable public com.grack.nanojson.JsonObject customIdentifyOptions()- Specified by:
customIdentifyOptions
in interfaceCatnipOptionsView
- Returns:
- Custom
IDENTIFY
options to pass to the gateway when connecting. Useful for adding support for new features that catnip doesn't yet support. Defaults tonull
.
-
entityDelegator
- Specified by:
entityDelegator
in interfaceCatnipOptionsView
- Returns:
- The delegator used to delegate catnip entities into a custom wrapper entity. Defaults to the identity function.
-
logEventNotInIntentsWarning
public boolean logEventNotInIntentsWarning()- Specified by:
logEventNotInIntentsWarning
in interfaceCatnipOptionsView
- Returns:
- Whether or not a warning should be logged when attempting to
listen on an event that the current intents do not allow listening on.
Defaults to
true
.
-
logEntityPresenceWarningOnCustomCache
public boolean logEntityPresenceWarningOnCustomCache()- Specified by:
logEntityPresenceWarningOnCustomCache
in interfaceCatnipOptionsView
- Returns:
- Whether or not to log a warning when an entity is not present
in a
CustomizableEntityCache
implementation when it should be. This is useful for debugging a custom cache, while also hiding potential errors that may come fromNoopEntityCache
.
-
iReallyWantToStartTheBotWithNoIntents
public boolean iReallyWantToStartTheBotWithNoIntents()- Specified by:
iReallyWantToStartTheBotWithNoIntents
in interfaceCatnipOptionsView
- Returns:
- Whether or not you can initialise a
Catnip
instance with no intents.
-
publicKey
- Returns:
this
.
-
shardManager
- Returns:
this
.
-
sessionManager
- Returns:
this
.
-
gatewayRatelimiter
- Returns:
this
.
-
logAdapter
- Returns:
this
.
-
eventBuffer
- Returns:
this
.
-
cacheWorker
- Returns:
this
.
-
dispatchManager
- Returns:
this
.
-
chunkMembers
- Returns:
this
.
-
emitEventObjects
- Returns:
this
.
-
enforcePermissions
- Returns:
this
.
-
initialPresence
- Returns:
this
.
-
disabledEvents
- Returns:
this
.
-
requester
- Returns:
this
.
-
logExtensionOverrides
- Returns:
this
.
-
validateToken
- Returns:
this
.
-
captureRestStacktraces
- Returns:
this
.
-
logUncachedPresenceWhenNotChunking
- Returns:
this
.
-
enableGuildSubscriptions
- Returns:
this
.
-
memberChunkTimeout
- Returns:
this
.
-
rxScheduler
- Returns:
this
.
-
logLifecycleEvents
- Returns:
this
.
-
manualChunkRerequesting
- Returns:
this
.
-
largeThreshold
- Returns:
this
.
-
taskScheduler
- Returns:
this
.
-
httpClient
- Returns:
this
.
-
compressionMode
- Returns:
this
.
-
restRatelimitsWithoutClockSync
- Returns:
this
.
-
highLatencyThreshold
- Returns:
this
.
-
entitySerializer
- Returns:
this
.
-
apiHost
- Returns:
this
.
-
apiVersion
- Returns:
this
.
-
intents
- Returns:
this
.
-
logPrivilegedIntentWarning
- Returns:
this
.
-
customIdentifyOptions
public CatnipOptions customIdentifyOptions(@Nullable com.grack.nanojson.JsonObject customIdentifyOptions) - Returns:
this
.
-
entityDelegator
- Returns:
this
.
-
logEventNotInIntentsWarning
- Returns:
this
.
-
logEntityPresenceWarningOnCustomCache
public CatnipOptions logEntityPresenceWarningOnCustomCache(boolean logEntityPresenceWarningOnCustomCache) - Returns:
this
.
-
iReallyWantToStartTheBotWithNoIntents
public CatnipOptions iReallyWantToStartTheBotWithNoIntents(boolean iReallyWantToStartTheBotWithNoIntents) - Returns:
this
.
-