Class: DiscordStore::Client
- Inherits:
-
Object
- Object
- DiscordStore::Client
- Defined in:
- lib/discord_store.rb
Overview
Ties the layers together: one transport, one rate limiter, and the stores built on top of them.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#rest ⇒ Object
readonly
Returns the value of attribute rest.
Instance Method Summary collapse
- #blobs ⇒ BlobStore
- #close ⇒ void
-
#initialize(config: DiscordStore.configuration, http: nil) ⇒ Client
constructor
A new instance of Client.
- #kv ⇒ KV
- #limits ⇒ GuildLimits
- #log ⇒ Log
-
#search ⇒ Search
Discord's message index.
-
#verify! ⇒ Hash
Confirms the token works and that the configured application_id matches the token's actual identity.
Constructor Details
#initialize(config: DiscordStore.configuration, http: nil) ⇒ Client
Returns a new instance of Client.
81 82 83 84 |
# File 'lib/discord_store.rb', line 81 def initialize(config: DiscordStore.configuration, http: nil) @config = config.validate! @rest = Transport::REST.new(config: @config, http: http) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
76 77 78 |
# File 'lib/discord_store.rb', line 76 def config @config end |
#rest ⇒ Object (readonly)
Returns the value of attribute rest.
76 77 78 |
# File 'lib/discord_store.rb', line 76 def rest @rest end |
Instance Method Details
#blobs ⇒ BlobStore
92 93 94 |
# File 'lib/discord_store.rb', line 92 def blobs @blobs ||= BlobStore.new(rest: @rest, config: @config) end |
#close ⇒ void
This method returns an undefined value.
137 |
# File 'lib/discord_store.rb', line 137 def close = @rest.close |
#kv ⇒ KV
97 98 99 |
# File 'lib/discord_store.rb', line 97 def kv @kv ||= KV.new(rest: @rest, config: @config) end |
#limits ⇒ GuildLimits
113 114 115 |
# File 'lib/discord_store.rb', line 113 def limits @limits ||= GuildLimits.new(rest: @rest, config: @config) end |
#log ⇒ Log
87 88 89 |
# File 'lib/discord_store.rb', line 87 def log @log ||= Log.new(rest: @rest, config: @config) end |
#search ⇒ Search
Discord's message index.
Not the read path -- see Search for why at length -- and needs the MESSAGE_CONTENT privileged intent. Exists for the queries that a channel scan answers badly, such as finding chunks whose manifest is gone.
108 109 110 |
# File 'lib/discord_store.rb', line 108 def search @search ||= Search.new(rest: @rest, config: @config) end |
#verify! ⇒ Hash
Confirms the token works and that the configured application_id matches the token's actual identity. Worth calling at boot: a mismatched application_id silently makes every read return nothing, because the own-messages guard rejects our own writes.
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/discord_store.rb', line 124 def verify! user = @rest.current_user if @config. && user["id"].to_s != @config.application_id.to_s raise ConfigurationError, "configured application_id #{@config.application_id.inspect} is not this token's " \ "identity (#{user["id"].inspect}). Every read would silently return nothing." end user end |