discljord.events.state

Middleware to cache all the state that Discord sends.

caching-handlers

Handler map for all state-caching events.

The state saved is of the following form:
```clojure
{:discljord.events.state/bot <current-user>
 :discljord.events.state/guilds {<guild-id> <guild-object>}
 :discljord.events.state/users {<user-id> <user-object>}
 :discljord.events.state/private-channels {<channel-id> <channel-object>}}
```

Guild objects are modified in a few ways. Roles, members, presences, threads and
channels are all stored as maps from id to object, and members' and presence's
user keys are the id of the user which is stored under the state's
`:discljord.events.state/users` key. Any information received from
`:presence-update` events is also merged into the user object, and a voice
state object is stored under `:voice`.

Threads also include a map of user ids to
[thread member objects](https://discord.com/developers/docs/resources/channel#thread-member-object) in their `:member` key.

Private channels are channels which lack a guild, including direct messages
and group messages.

caching-middleware

(caching-middleware state)(caching-middleware state caching-handlers)
Creates a middleware that caches Discord event data in `state`.

`state` must be an [[clojure.core/atom]] containing a map.
`caching-handlers`, if provided, must be a map of event keyword -> sequence of caching handlers.
Each caching handler is a function that takes the event type, data and the state atom and updates the atom where applicable.

If this parameter is not provided, the default [[caching-handlers]] are used.
See its docs for more information on the default cache layout and behavior.

caching-transducer

(caching-transducer state)(caching-transducer state caching-handlers)
Creates a transducer which caches event data and passes on all events.

Values on the transducer are expected to be tuples of event-type and
event-data.
`state` must be an [[clojure.core/atom]] containing a map.
`caching-handlers`, if provided, must be a map of event keyword -> sequence of caching handlers.
Each caching handler is a function that takes the event type, data and the state atom and updates the atom where applicable.

If this parameter is not provided, the default [[caching-handlers]] are used.
See its docs for more information on the default cache layout and behavior.

channel-delete

(channel-delete _ channel state)

channel-pins-update

(channel-pins-update _ {:keys [guild-id channel-id last-pin-timestamp]} state)

channel-update

(channel-update _ channel state)

guild-emojis-update

(guild-emojis-update _ {:keys [guild-id emojis]} state)

guild-member-remove

(guild-member-remove _ {:keys [guild-id user]} state)

guild-member-update

(guild-member-update _ {:keys [guild-id user], :as member} state)

guild-members-chunk

(guild-members-chunk _ {:keys [guild-id members]} state)

guild-role-delete

(guild-role-delete _ {:keys [guild-id role-id]} state)

guild-role-update

(guild-role-update _ {:keys [guild-id role]} state)

guild-update

(guild-update _ guild state)
Stores the guild into the state.

message-create

(message-create _ {:keys [guild-id channel-id id]} state)

prepare-guild

(prepare-guild guild)
Takes a guild and prepares it for storing in the cache.

The roles vector will be transformed to a map keyed off if, members
transformed to a map from user id to member object with `:user` key replaced
by the user id, channels will be changed to a map from id to channel object.

prepare-thread

(prepare-thread {:keys [member], :as thread})

presence-update

(presence-update _ {:keys [user guild-id activities status client-status], :as presence} state)

ready

(ready _ {:keys [user guilds]} state)
Stores the user and guilds into the state.

thread-delete

(thread-delete _ {:keys [guild-id id]} state)

thread-list-sync

(thread-list-sync _ {:keys [guild-id channel-ids threads members]} state)

thread-member-update

(thread-member-update _ {:keys [guild-id id user-id], :as member} state)

thread-members-update

(thread-members-update _ {:keys [added-members removed-member-ids id guild-id member-count :as event]} state)

thread-update

(thread-update _ {:keys [guild-id id], {:keys [archived]} :thread-metadata, :as thread} state)

user-update

(user-update _ user state)

voice-state-update

(voice-state-update _ {:keys [user-id], :as voice} state)