Elixir v0.2.1 Nostrum.Consumer behaviour

Consumer process for gateway event handling.

Consuming Gateway Events

To handle events, Nostrum uses a GenStage implementation. GenStage is “new” with Elixir version 1.4, expanding on the old functionality of GenEvent.

Nostrum defines the producer in the GenStage design. To consume the events you must create at least one consumer process. For an example of this behaviour please see here.

It is generally recommended that you spawn a consumer per core. To find this number you can use System.schedulers_online/0.

Summary

Callbacks

Callback used to handle events

Types

build_ban_remove()
build_ban_remove() :: {:GUILD_BAN_REMOVE, {Nostrum.Struct.User.t}, ws_state}
channel_create()
channel_create() :: {:CHANNEL_CREATE, {Nostrum.Struct.Channel.t}, ws_state}
channel_delete()
channel_delete() :: {:CHANNEL_DELETE, {Nostrum.Struct.Channel.t}, ws_state}
channel_pins_ack()
channel_pins_ack() :: {:CHANNEL_PINS_ACK, {map}, ws_state}
channel_pins_update()
channel_pins_update() :: {:CHANNEL_PINS_UPDATE, {map}, ws_state}
channel_update()
channel_update() :: {:CHANNEL_UPDATE, {old_channel :: Nostrum.Struct.Channel.t, new_channel :: Nostrum.Struct.Channel.t}, ws_state}
from()
from() :: {pid, tag :: term}

Tuple describing the client of a call request.

pid is the PID of the caller and tag is a unique term used to identify the call.

guild_ban_add()
guild_ban_add() :: {:GUILD_BAN_ADD, {Nostrum.Struct.User.t}, ws_state}
guild_create()
guild_create() :: {:GUILD_CREATE, {new_guild :: Nostrum.Struct.Guild.t}, ws_state}
guild_delete()
guild_delete() :: {:GUILD_DELETE, {old_guild :: Nostrum.Struct.Guild.t}, ws_state}
guild_emojis_update()
guild_emojis_update() :: {:GUILD_EMOJIS_UPDATE, {old_emojis :: [Nostrum.Struct.Message.Emoji.t], new_emojis :: [Nostrum.Struct.Message.Emoji.t]}, ws_state}
guild_integrations_update()
guild_integrations_update() :: {:GUILD_INTEGERATIONS_UPDATE, {map}, ws_state}
guild_member_add()
guild_member_add() :: {:GUILD_MEMBER_ADD, {new_member :: Nostrum.Struct.Guild.Member.t}, ws_state}
guild_member_remove()
guild_member_remove() :: {:GUILD_MEMBER_REMOVE, {old_member :: Nostrum.Struct.Guild.Member.t}, ws_state}
guild_member_update()
guild_member_update() :: {:GUILD_MEMBER_UPDATE, {old_member :: Nostrum.Struct.Guild.Member.t, new_member :: Nostrum.Struct.Guild.Member.t}, ws_state}
guild_members_chunk()
guild_members_chunk() :: {:GUILD_MEMBERS_CHUNK, {map}, ws_state}
guild_role_create()
guild_role_create() :: {:GUILD_ROLE_CREATE, {new_role :: Nostrum.Struct.Guild.Role.t}, ws_state}
guild_role_delete()
guild_role_delete() :: {:GUILD_ROLE_DELETE, {old_role :: Nostrum.Struct.Guild.Role.t}, ws_state}
guild_role_update()
guild_role_update() :: {:GUILD_ROLE_UPDATE, {old_role :: Nostrum.Struct.Guild.Role.t, new_role :: Nostrum.Struct.Guild.Role.t}, ws_state}
guild_unavailable()
guild_unavailable() :: {:GUILD_UNAVAILABLE, {unavailable_guild :: Nostrum.Struct.Guild.UnavailableGuild.t}, ws_state}
guild_update()
guild_update() :: {:GUILD_CREATE, {old_guild :: Nostrum.Struct.Guild.t, new_guild :: Nostrum.Struct.Guild.t}, ws_state}
message_create()
message_create() :: {:MESSAGE_CREATE, {message :: Nostrum.Struct.Message.t}, ws_state}
message_delete()
message_delete() :: {:MESSAGE_DELETE, {message :: Nostrum.Struct.Message.t}, ws_state}
message_delete_bulk()
message_delete_bulk() :: {:MESSAGE_DELETE_BULK, {updated_messages :: [Nostrum.Struct.Message.t]}, ws_state}
message_reaction_add()
message_reaction_add() :: {:MESSAGE_REACTION_ADD, map}
message_reaction_remove()
message_reaction_remove() :: {:MESSAGE_REACTION_REMOVE, map}
message_update()
message_update() :: {:MESSAGE_UPDATE, {updated_message :: Nostrum.Struct.Message.t}, ws_state}
presence_update()
presence_update() :: {:PRESENCE_UPDATE, {map}, ws_state}
ready()
ready() :: {:READY, {map}, ws_state}
resumed()
resumed() :: {:RESUMED, {map}, ws_state}
state()
state() :: map

The state of the consumer process.

typing_start()
typing_start() :: {:TYPING_START, {map}, ws_state}
user_settings_update()
user_settings_update() :: no_return
user_update()
user_update() :: {:USER_UPDATE, {old_user :: Nostrum.Struct.User.t, new_user :: Nostrum.Struct.User.t}, ws_state}
voice_server_update()
voice_server_update() :: {:VOICE_SERVER_UPDATE, {map}, ws_state}
voice_state_update()
voice_state_update() :: {:VOICE_STATE_UPDATE, {map}, ws_state}
ws_state()
ws_state() :: map

The state of the websocket connection for the shard the event occured on.

Functions

start_link(mod)

Callbacks

handle_event(event, state)
handle_event(event, state) :: {:ok, map}

Callback used to handle events.

Event

event is a tuple describing the event. The tuple will include information in the following format:

{event_name, {event_payload(s)}, ws_state}

For example, a message create will look like this

{:MESSAGE_CREATE, {Nostrum.Struct.Message.t}, ws_state}

In some cases there will be multiple payloads when something is updated, so as to include the new and the old versions. In the event of there being two payloads, the old payload will always be first, followed by the new payload.

{:CHANNEL_UPDATE, {old :: Nostrum.Struct.Channel.t, new :: Nostrum.Struct.Channel.t}, ws_state}

For a full listing of events, please see Nostrum.Consumer.event.

Websocket State

ws_state is the current state of the websocket that the event was received on. For more information on this please see Nostrum.Shard.Payload.state_map.t.

State

state is the internal state of your consumer.