Class CatnipOptions

java.lang.Object
com.mewna.catnip.CatnipOptions
All Implemented Interfaces:
CatnipOptionsView, Cloneable

public final class CatnipOptions extends Object implements CatnipOptionsView, Cloneable
Since:
9/25/18.
Author:
amy
  • Constructor Details

    • CatnipOptions

      public CatnipOptions(@Nonnull String token)
  • Method Details

    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • token

      @Nonnull public String token()
      Description copied from interface: CatnipOptionsView
      The token for catnip to use.

      May not be overridden by extensions.

      Specified by:
      token in interface CatnipOptionsView
    • publicKey

      public String 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 interface CatnipOptionsView
    • shardManager

      @Nonnull public ShardManager shardManager()
      Description copied from interface: CatnipOptionsView
      The shard manager for catnip to use. Defaults to DefaultShardManager.
      Specified by:
      shardManager in interface CatnipOptionsView
    • sessionManager

      @Nonnull public SessionManager sessionManager()
      Description copied from interface: CatnipOptionsView
      The session manager for catnip to use. Defaults to DefaultSessionManager
      Specified by:
      sessionManager in interface CatnipOptionsView
    • gatewayRatelimiter

      @Nonnull public Ratelimiter gatewayRatelimiter()
      Description copied from interface: CatnipOptionsView
      The gateway ratelimiter for catnip to use. Defaults to MemoryRatelimiter
      Specified by:
      gatewayRatelimiter in interface CatnipOptionsView
    • logAdapter

      @Nonnull public LogAdapter logAdapter()
      Description copied from interface: CatnipOptionsView
      The log adapter for catnip to use. Defaults to DefaultLogAdapter, which uses SLF4J.
      Specified by:
      logAdapter in interface CatnipOptionsView
    • eventBuffer

      @Nonnull public EventBuffer eventBuffer()
      Description copied from interface: CatnipOptionsView
      The event buffer for catnip to use. Defaults to CachingBuffer. 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 interface CatnipOptionsView
    • cacheWorker

      @Nonnull public EntityCacheWorker cacheWorker()
      Description copied from interface: CatnipOptionsView
      The cache worker for catnip to use. Defaults to SplitMemoryEntityCache. Change this if you want to use your own EntityCacheWorker.
      Specified by:
      cacheWorker in interface CatnipOptionsView
    • dispatchManager

      @Nonnull public DispatchManager dispatchManager()
      Description copied from interface: CatnipOptionsView
      Manages event dispatching and consumers. Defaults to DefaultDispatchManager.
      Specified by:
      dispatchManager in interface CatnipOptionsView
    • 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 interface CatnipOptionsView
    • 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. an Extension that does things with the raw gateway payloads, like sending them to a message queue.
      Specified by:
      emitEventObjects in interface CatnipOptionsView
    • 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 via Catnip.rest(), but will enforce them if you call them from entity objects (ex. doing Guild.delete()).
      Specified by:
      enforcePermissions in interface CatnipOptionsView
    • initialPresence

      @Nullable public Presence 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 interface CatnipOptionsView
    • disabledEvents

      @Nonnull public Set<String> disabledEvents()
      Description copied from interface: CatnipOptionsView
      The events that catnip should not emit. You can use DiscordEvent.Raw to get the event names.
      Specified by:
      disabledEvents in interface CatnipOptionsView
    • requester

      @Nonnull public Requester requester()
      Description copied from interface: CatnipOptionsView
      The requester catnip uses for REST requests. Defaults to SerialRequester.
      Specified by:
      requester in interface CatnipOptionsView
    • logExtensionOverrides

      public boolean logExtensionOverrides()
      Description copied from interface: CatnipOptionsView
      Whether or not extensions overriding options should be logged. Defaults to true.

      May not be overridden by extensions.

      Specified by:
      logExtensionOverrides in interface CatnipOptionsView
    • 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 interface CatnipOptionsView
    • 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 interface CatnipOptionsView
    • 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 interface CatnipOptionsView
    • 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 interface CatnipOptionsView
    • 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 interface CatnipOptionsView
    • 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 to RxHelpers.FORK_JOIN_SCHEDULER.
      Specified by:
      rxScheduler in interface CatnipOptionsView
    • 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 configured CatnipOptionsView.logAdapter(), in addition to being emitted over the event bus.
      Specified by:
      logLifecycleEvents in interface CatnipOptionsView
    • manualChunkRerequesting

      public boolean manualChunkRerequesting()
      Description copied from interface: CatnipOptionsView
      If this option is enabled, emit a MemberChunkRerequest 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 interface CatnipOptionsView
    • 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. See CatnipOptionsView.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 interface CatnipOptionsView
    • taskScheduler

      @Nonnull public TaskScheduler 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 through Catnip.taskScheduler(), and can safely be used for any task scheduling needs you may have. Defaults to RxTaskScheduler.
      Specified by:
      taskScheduler in interface CatnipOptionsView
    • httpClient

      @Nonnull public HttpClient httpClient()
      Description copied from interface: CatnipOptionsView
      The HTTP client that catnip uses internally for websockets and REST requests. Defaults to an instance that uses RxHelpers.FORK_JOIN_POOL as its executor.
      Specified by:
      httpClient in interface CatnipOptionsView
    • compressionMode

      @Nonnull public CompressionMode compressionMode()
      Description copied from interface: CatnipOptionsView
      How catnip compresses incoming events from Discord. Default is CompressionMode.ZLIB.
      Specified by:
      compressionMode in interface CatnipOptionsView
    • 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 to true, 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 interface CatnipOptionsView
    • highLatencyThreshold

      public long highLatencyThreshold()
      Description copied from interface: CatnipOptionsView
      If heartbeat latency takes longer than this much time, catnip will emit a HighWebsocketLatency 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 interface CatnipOptionsView
    • entitySerializer

      @Nonnull public EntitySerializer<?> 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 interface CatnipOptionsView
    • apiHost

      @Nonnull public String apiHost()
      Description copied from interface: CatnipOptionsView
      The host used for Discord API requests. Defaults to https://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 interface CatnipOptionsView
    • apiVersion

      public int apiVersion()
      Specified by:
      apiVersion in interface CatnipOptionsView
      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

      @Nonnull public Set<GatewayIntent> intents()
      Specified by:
      intents in interface CatnipOptionsView
      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 of GatewayIntent for more information about what events are covered by each intent.
      NOTE THAT THIS IS NOT THE SAME AS CatnipOptionsView.disabledEvents()!
    • logPrivilegedIntentWarning

      public boolean logPrivilegedIntentWarning()
      Specified by:
      logPrivilegedIntentWarning in interface CatnipOptionsView
      Returns:
      Whether or not to log a warning about the use of privileged GatewayIntents. Defaults to true.
    • customIdentifyOptions

      @Nullable public com.grack.nanojson.JsonObject customIdentifyOptions()
      Specified by:
      customIdentifyOptions in interface CatnipOptionsView
      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 to null.
    • entityDelegator

      @Nonnull public EntityDelegator entityDelegator()
      Specified by:
      entityDelegator in interface CatnipOptionsView
      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 interface CatnipOptionsView
      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 interface CatnipOptionsView
      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 from NoopEntityCache.
    • iReallyWantToStartTheBotWithNoIntents

      public boolean iReallyWantToStartTheBotWithNoIntents()
      Specified by:
      iReallyWantToStartTheBotWithNoIntents in interface CatnipOptionsView
      Returns:
      Whether or not you can initialise a Catnip instance with no intents.
    • publicKey

      public CatnipOptions publicKey(String publicKey)
      Returns:
      this.
    • shardManager

      public CatnipOptions shardManager(@Nonnull ShardManager shardManager)
      Returns:
      this.
    • sessionManager

      public CatnipOptions sessionManager(@Nonnull SessionManager sessionManager)
      Returns:
      this.
    • gatewayRatelimiter

      public CatnipOptions gatewayRatelimiter(@Nonnull Ratelimiter gatewayRatelimiter)
      Returns:
      this.
    • logAdapter

      public CatnipOptions logAdapter(@Nonnull LogAdapter logAdapter)
      Returns:
      this.
    • eventBuffer

      public CatnipOptions eventBuffer(@Nonnull EventBuffer eventBuffer)
      Returns:
      this.
    • cacheWorker

      public CatnipOptions cacheWorker(@Nonnull EntityCacheWorker cacheWorker)
      Returns:
      this.
    • dispatchManager

      public CatnipOptions dispatchManager(@Nonnull DispatchManager dispatchManager)
      Returns:
      this.
    • chunkMembers

      public CatnipOptions chunkMembers(boolean chunkMembers)
      Returns:
      this.
    • emitEventObjects

      public CatnipOptions emitEventObjects(boolean emitEventObjects)
      Returns:
      this.
    • enforcePermissions

      public CatnipOptions enforcePermissions(boolean enforcePermissions)
      Returns:
      this.
    • initialPresence

      public CatnipOptions initialPresence(@Nullable Presence initialPresence)
      Returns:
      this.
    • disabledEvents

      public CatnipOptions disabledEvents(@Nonnull Set<String> disabledEvents)
      Returns:
      this.
    • requester

      public CatnipOptions requester(@Nonnull Requester requester)
      Returns:
      this.
    • logExtensionOverrides

      public CatnipOptions logExtensionOverrides(boolean logExtensionOverrides)
      Returns:
      this.
    • validateToken

      public CatnipOptions validateToken(boolean validateToken)
      Returns:
      this.
    • captureRestStacktraces

      public CatnipOptions captureRestStacktraces(boolean captureRestStacktraces)
      Returns:
      this.
    • logUncachedPresenceWhenNotChunking

      public CatnipOptions logUncachedPresenceWhenNotChunking(boolean logUncachedPresenceWhenNotChunking)
      Returns:
      this.
    • enableGuildSubscriptions

      public CatnipOptions enableGuildSubscriptions(boolean enableGuildSubscriptions)
      Returns:
      this.
    • memberChunkTimeout

      public CatnipOptions memberChunkTimeout(long memberChunkTimeout)
      Returns:
      this.
    • rxScheduler

      public CatnipOptions rxScheduler(io.reactivex.rxjava3.core.Scheduler rxScheduler)
      Returns:
      this.
    • logLifecycleEvents

      public CatnipOptions logLifecycleEvents(boolean logLifecycleEvents)
      Returns:
      this.
    • manualChunkRerequesting

      public CatnipOptions manualChunkRerequesting(boolean manualChunkRerequesting)
      Returns:
      this.
    • largeThreshold

      public CatnipOptions largeThreshold(int largeThreshold)
      Returns:
      this.
    • taskScheduler

      public CatnipOptions taskScheduler(@Nonnull TaskScheduler taskScheduler)
      Returns:
      this.
    • httpClient

      public CatnipOptions httpClient(@Nonnull HttpClient httpClient)
      Returns:
      this.
    • compressionMode

      public CatnipOptions compressionMode(@Nonnull CompressionMode compressionMode)
      Returns:
      this.
    • restRatelimitsWithoutClockSync

      public CatnipOptions restRatelimitsWithoutClockSync(boolean restRatelimitsWithoutClockSync)
      Returns:
      this.
    • highLatencyThreshold

      public CatnipOptions highLatencyThreshold(long highLatencyThreshold)
      Returns:
      this.
    • entitySerializer

      public CatnipOptions entitySerializer(@Nonnull EntitySerializer<?> entitySerializer)
      Returns:
      this.
    • apiHost

      public CatnipOptions apiHost(@Nonnull String apiHost)
      Returns:
      this.
    • apiVersion

      public CatnipOptions apiVersion(int apiVersion)
      Returns:
      this.
    • intents

      public CatnipOptions intents(@Nonnull Set<GatewayIntent> intents)
      Returns:
      this.
    • logPrivilegedIntentWarning

      public CatnipOptions logPrivilegedIntentWarning(boolean logPrivilegedIntentWarning)
      Returns:
      this.
    • customIdentifyOptions

      public CatnipOptions customIdentifyOptions(@Nullable com.grack.nanojson.JsonObject customIdentifyOptions)
      Returns:
      this.
    • entityDelegator

      public CatnipOptions entityDelegator(@Nonnull EntityDelegator entityDelegator)
      Returns:
      this.
    • logEventNotInIntentsWarning

      public CatnipOptions logEventNotInIntentsWarning(boolean logEventNotInIntentsWarning)
      Returns:
      this.
    • logEntityPresenceWarningOnCustomCache

      public CatnipOptions logEntityPresenceWarningOnCustomCache(boolean logEntityPresenceWarningOnCustomCache)
      Returns:
      this.
    • iReallyWantToStartTheBotWithNoIntents

      public CatnipOptions iReallyWantToStartTheBotWithNoIntents(boolean iReallyWantToStartTheBotWithNoIntents)
      Returns:
      this.