Class CatnipImpl

java.lang.Object
com.mewna.catnip.internal.CatnipImpl
All Implemented Interfaces:
Catnip, AutoCloseable

public final class CatnipImpl extends Object implements Catnip
Since:
8/31/18.
Author:
amy
  • Field Details

    • BOUNCY_CASTLE_PROVIDER

      public static final org.bouncycastle.jce.provider.BouncyCastleProvider BOUNCY_CASTLE_PROVIDER
  • Constructor Details

  • Method Details

    • injectOptions

      @Nonnull public Catnip injectOptions(@Nonnull Extension extension, @Nonnull UnaryOperator<CatnipOptions> optionsPatcher)
      Description copied from interface: Catnip
      Inject options into this catnip instance from the given extension. This allows extensions to do things like automatically register a new cache worker without having to tell the end-user to specify options. By default, options that get injected will be logged.
      Specified by:
      injectOptions in interface Catnip
      Parameters:
      extension - The extension injecting the options.
      optionsPatcher - Function responsible for updating the settings.
      Returns:
      Itself.
    • requester

      public Requester requester()
    • loadExtension

      @Nonnull public Catnip loadExtension(@Nonnull Extension extension)
      Description copied from interface: Catnip
      Load an extension for this catnip instance. See Extension for more information.
      Specified by:
      loadExtension in interface Catnip
      Parameters:
      extension - The extension to load.
      Returns:
      Itself.
    • selfUser

      @Nonnull @CheckReturnValue public io.reactivex.rxjava3.core.Maybe<User> selfUser()
      Specified by:
      selfUser in interface Catnip
      Returns:
      The currently-logged-in user. May be null if no shards have logged in.
    • clientId

      public String clientId()
      Description copied from interface: Catnip
      The ID of this client
      Specified by:
      clientId in interface Catnip
      Returns:
      The ID of this client.
    • clientIdAsLong

      public long clientIdAsLong()
      Description copied from interface: Catnip
      The ID of this client, as a long.
      Specified by:
      clientIdAsLong in interface Catnip
      Returns:
      The ID of the client, as a long.
    • shutdown

      public void shutdown()
      Description copied from interface: Catnip
      Shutdown the catnip instance, and undeploy all shards.
      Specified by:
      shutdown in interface Catnip
    • unavailableGuilds

      @Nonnull public Set<String> unavailableGuilds()
      Specified by:
      unavailableGuilds in interface Catnip
      Returns:
      A set of all ids of unavailable guilds.
    • markAvailable

      public void markAvailable(String id)
    • markUnavailable

      public void markUnavailable(String id)
    • isUnavailable

      public boolean isUnavailable(@Nonnull String guildId)
      Specified by:
      isUnavailable in interface Catnip
      Parameters:
      guildId - The guild to check.
      Returns:
      Whether or not the guild is unavailable.
    • openVoiceConnection

      public void openVoiceConnection(@Nonnull String guildId, @Nonnull String channelId, boolean selfMute, boolean selfDeaf)
      Description copied from interface: Catnip
      Opens a voice connection to the provided guild and channel. The connection is opened asynchronously, with VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE events being fired when the connection is opened.
      Specified by:
      openVoiceConnection in interface Catnip
      Parameters:
      guildId - Guild to connect.
      channelId - Channel to connect.
      selfMute - Whether or not to connect as muted.
      selfDeaf - Whether or not to connect as deafened.
    • closeVoiceConnection

      public void closeVoiceConnection(@Nonnull String guildId)
      Description copied from interface: Catnip
      Closes the voice connection on the specified guild.
      Specified by:
      closeVoiceConnection in interface Catnip
      Parameters:
      guildId - Guild to disconnect.
    • closeVoiceConnection

      public void closeVoiceConnection(long guildId)
      Description copied from interface: Catnip
      Closes the voice connection on the specified guild.
      Specified by:
      closeVoiceConnection in interface Catnip
      Parameters:
      guildId - Guild to disconnect.
    • chunkMembers

      public void chunkMembers(@Nonnull String guildId, @Nonnull String query, @Nonnegative int limit, @Nullable String nonce)
      Description copied from interface: Catnip
      Request guild members for the given guild.
      Specified by:
      chunkMembers in interface Catnip
      Parameters:
      guildId - Guild to request for.
      query - Members returned must have a username starting with this.
      limit - Maximum number of members to return. 0 for no limit.
      nonce - Nonce to use for knowing which chunks came from which request.
    • presence

      public Presence presence(@Nonnegative int shardId)
      Description copied from interface: Catnip
      Get the presence for the specified shard.
      Specified by:
      presence in interface Catnip
      Parameters:
      shardId - The shard id to get presence for.
      Returns:
      The shard's presence.
    • presence

      public void presence(@Nonnull Presence presence)
      Description copied from interface: Catnip
      Update the presence for all shards.
      Specified by:
      presence in interface Catnip
      Parameters:
      presence - The new presence to set.
    • presence

      public void presence(@Nonnull Presence presence, @Nonnegative int shardId)
      Description copied from interface: Catnip
      Update the presence for a specific shard.
      Specified by:
      presence in interface Catnip
      Parameters:
      presence - The new presence to set.
      shardId - The shard to set presence for.
    • presence

      public void presence(@Nullable Presence.OnlineStatus status, @Nullable String game, @Nullable Presence.ActivityType type, @Nullable String url)
      Description copied from interface: Catnip
      Update the presence for all shards by specifying each part of the presence individually.
      Specified by:
      presence in interface Catnip
      Parameters:
      status - The new online status. Set to null for online.
      game - The new game name. Set to null to clear.
      type - The type of the new game status. Set to null for "playing."
      url - The new URL for the presence. Will be ignored if type is not Presence.ActivityType.STREAMING.
    • setup

      @Nonnull public io.reactivex.rxjava3.core.Single<Catnip> setup()
    • connect

      @Nonnull public Catnip connect()
      Description copied from interface: Catnip
      Start all shards asynchronously. To customize the shard spawning / management strategy, see CatnipOptions.
      Specified by:
      connect in interface Catnip
      Returns:
      Itself.
    • gatewayInfo

      @Nullable public GatewayInfo gatewayInfo()
      Specified by:
      gatewayInfo in interface Catnip
      Returns:
      The cached gateway info. May be null if it hasn't been fetched yet.
    • fetchGatewayInfo

      @Nonnull public io.reactivex.rxjava3.core.Single<GatewayInfo> fetchGatewayInfo()
      Description copied from interface: Catnip
      Fetches the gateway info and updates the cache. Calls made to Catnip.gatewayInfo() after this stage completes successfully are guaranteed to return a non null value.

      Updates the cached gateway info.

      Specified by:
      fetchGatewayInfo in interface Catnip
      Returns:
      The gateway info fetched from discord.
    • token

      public String token()
    • logExtensionOverrides

      public boolean logExtensionOverrides()
    • validateToken

      public boolean validateToken()
    • rest

      public Rest rest()
      Specified by:
      rest in interface Catnip
      Returns:
      The REST API instance for this catnip instance.
    • extensionManager

      public ExtensionManager extensionManager()
      Specified by:
      extensionManager in interface Catnip
      Returns:
      The extension manager being used by this catnip instance.
    • keepaliveThread

      public Thread keepaliveThread()
    • latch

      public CountDownLatch latch()
    • startedKeepalive

      public boolean startedKeepalive()
    • options

      public CatnipOptions options()
      Specified by:
      options in interface Catnip
      Returns:
      An immutable view of the current instance's options.
    • entityBuilder

      public EntityBuilder entityBuilder()
      Description copied from interface: Catnip
      The entity builder used by this catnip instance. This is exposed publicly so that, if necessary, it can be used to construct entities from JSON objects as needed.
      Specified by:
      entityBuilder in interface Catnip
      Returns:
      This catnip instance's EntityBuilder.