discljord.connections.impl
Implementation of websocket connections to Discord.
*handle-re-shard*
dynamic
Determines if the bot will re-shard on its own, or require user coordination.
If bound to true and a re-shard occurs, the bot will make a request to discord
for the new number of shards to connect with and then connect them. If bound
to false, then a :re-shard event will be sent to the user library and all
shards will be disconnected.
*identify-limiter*
dynamic
*identify-when*
dynamic
Function that returns a channel that yields when it's time to identify.
*stop-on-fatal-code*
dynamic
Bind to to true to disconnect the entire bot after a fatal stop code.
after-timeout!
(after-timeout! f timeout)
Calls a function of no arguments after the given `timeout`.
Returns a channel which will have the return value of the function put on it.
buffer-size
The maximum size of the websocket buffer
byte-array-buffer-size
The size of the byte array to allocate for the decompression buffer
connect-shards!
(connect-shards! output-ch communication-ch url token intents shard-count shard-ids compress)
Connects a set of shards with the given `shard-ids`.
Returns nil.
connect-websocket!
(connect-websocket! buffer-size url event-ch compress)
Connect a websocket to the `url` that puts all events onto the `event-ch`.
Events are represented as vectors with a keyword for the event type and then
event data as the rest of the vector based on the type of event.
| Type | Data |
|---------------+------|
| `:connect` | None.
| `:disconnect` | Stop code, string message.
| `:error` | Error value.
| `:message` | String message.
fatal-code?
Set of stop codes which after recieving, discljord will disconnect all shards.
get-shard-from-guild
(get-shard-from-guild guild-id guild-count)
get-websocket-gateway
(get-websocket-gateway url token)
Gets the shard count and websocket endpoint from Discord's API.
Takes the `url` of the gateway and the `token` of the bot.
Returns a map with the keys :url, :shard-count, and :session-start limit, or
nil in the case of an error.
handle-bot-fx!
multimethod
Handles a bot-level side effect triggered by a shard.
This method should never block, and should not do intense computation. Takes a
place to output events to the library user, the url to connect sockets, the
bot's token, the vector of shards, a vector of channels which resolve to the
shard's next state, the index of the shard the effect is from, and the effect.
Returns a vector of the vector of shards and the vector of shard channels.
handle-communication!
multimethod
Handles communicating to the `shards`.
Takes an `event` vector, a vector of `shards`, and a vector of channels which
resolve to each shard's next state, and returns a vector of the vector of
shards and the vector of channels.
handle-connection-event!
multimethod
Handles events which connect or disconnect the shard, returning effects.
handle-discord-event
multimethod
Handles discord events for a specific shard, specifying effects.
handle-payload
multimethod
Update a `shard` based on a message.
Takes a `shard` and `msg` and returns a map with a :shard and an :effects
vector.
handle-shard-communication!
multimethod
Processes a communication `event` on the given `shard` for side effects.
Returns a map with the new :shard and bot-evel :effects to process.
handle-shard-fx!
multimethod
Processes an `event` on a given `shard` for side effects.
Returns a map with the new :shard and bot-level :effects to process.
handle-websocket-event
multimethod
Updates a `shard` based on shard events.
Takes a `shard` and a shard event vector and returns a map of the new state of
the shard and zero or more events to process.
make-identify-fn
(make-identify-fn token shard)
make-shard
(make-shard intents id shard-count compress)
Creates a new shard with the given `id` and `shard-count`.
new-session-stop-code?
Set of stop codes after which a resume isn't possible.
re-shard-stop-code?
Stop codes which Discord will send when the bot needs to be re-sharded.
remove-shards
(remove-shards pred shards shard-chs)
Removes shards fitting a predicate from the vector of shards and channels.
run-on-agent-with-limit
(run-on-agent-with-limit a f millis)
Runs the given function on the agent, then other actions wait `millis`.
shard-matches-any?
(shard-matches-any? match-any shard)
Returns true if the shard matches against any of the passed matchers.
shard-matches?
(shard-matches? shard match)
Returns true if all keys in `match` are equal to the ones in `shard`.
should-resume?
(should-resume? shard)
Returns if a shard should try to resume.
step-shard!
(step-shard! shard url token)
Starts a process to step a `shard`, handling side-effects.
Returns a channel which will have a map with the new `:shard` and a vector of
`:effects` for the entire bot to respond to placed on it after the next item
the socket may respond to occurs.
user-error-code?
Set of stop codes which can only be received if there was user error.