Concord - C Discord API library
A Discord API wrapper library written in C

Wrapper to the Discord Gateway API. More...

Collaboration diagram for WebSockets API:

Modules

 Client's session status
 Client's session status.
 
 Gateway intents
 Events user is interested on listening to.
 

Data Structures

struct  discord_gateway_session
 The handle for storing the Discord Gateway session. More...
 
struct  discord_gateway_payload
 The handle for storing the Discord response payload. More...
 
struct  discord_gateway
 The handle used for interfacing with Discord's Gateway API. More...
 

Typedefs

typedef void(* discord_ev_event) (struct discord *client, const void *event)
 
typedef void(* discord_ev_message) (struct discord *client, const struct discord_message *event)
 

Functions

void discord_gateway_init (struct discord_gateway *gw, struct logconf *conf, const char token[])
 Initialize a Gateway handle. More...
 
void discord_gateway_cleanup (struct discord_gateway *gw)
 Free a Gateway handle. More...
 
CCORDcode discord_gateway_start (struct discord_gateway *gw)
 Initialize handle with the new session primitives. More...
 
bool discord_gateway_end (struct discord_gateway *gw)
 Cleanup and reset gw session primitives. More...
 
CCORDcode discord_gateway_perform (struct discord_gateway *gw)
 Check and manage on-going Gateway session. More...
 
void discord_gateway_shutdown (struct discord_gateway *gw)
 Gracefully shutdown a ongoing Discord connection over WebSockets. More...
 
void discord_gateway_reconnect (struct discord_gateway *gw, bool resume)
 Gracefully reconnect a ongoing Discord connection over WebSockets. More...
 
void discord_gateway_send_identify (struct discord_gateway *gw, struct discord_identify *event)
 Trigger the initial handshake with the gateway. More...
 
void discord_gateway_send_resume (struct discord_gateway *gw, struct discord_resume *event)
 Replay missed events when a disconnected client resumes. More...
 
void discord_gateway_send_heartbeat (struct discord_gateway *gw, int seq)
 Maintain an active gateway connection. More...
 
void discord_gateway_send_request_guild_members (struct discord_gateway *gw, struct discord_request_guild_members *event)
 Request all members for a guild or a list of guilds. More...
 
void discord_gateway_send_update_voice_state (struct discord_gateway *gw, struct discord_update_voice_state *event)
 Sent when a client wants to join, move or disconnect from a voice channel. More...
 
void discord_gateway_send_presence_update (struct discord_gateway *gw, struct discord_presence_update *event)
 Send client's presence status update payload. More...
 
void discord_gateway_dispatch (struct discord_gateway *gw)
 Dispatch user callback matched to event. More...
 

Detailed Description

Wrapper to the Discord Gateway API.

Typedef Documentation

◆ discord_ev_event

typedef void(* discord_ev_event) (struct discord *client, const void *event)

A generic event callback for casting

◆ discord_ev_message

typedef void(* discord_ev_message) (struct discord *client, const struct discord_message *event)

An event callback for DISCORD_EV_MESSAGE_CREATE

Function Documentation

◆ discord_gateway_init()

void discord_gateway_init ( struct discord_gateway gw,
struct logconf conf,
const char  token[] 
)

Initialize a Gateway handle.

Structure used for interfacing with the Discord's Gateway API

Parameters
gwthe gateway handle to be initialized
confpointer to discord logging module
tokenthe bot token

◆ discord_gateway_cleanup()

void discord_gateway_cleanup ( struct discord_gateway gw)

Free a Gateway handle.

Parameters
gwthe handle initialized with discord_gateway_init()

◆ discord_gateway_start()

CCORDcode discord_gateway_start ( struct discord_gateway gw)

Initialize handle with the new session primitives.

Parameters
gwthe handle initialized with discord_gateway_init()
Returns
CCORDcode value for how the operation went, CCORD_OK means nothing out of the ordinary

◆ discord_gateway_end()

bool discord_gateway_end ( struct discord_gateway gw)

Cleanup and reset gw session primitives.

Parameters
wsthe WebSockets handle created with ws_init()
Returns
true if session is over, false if session can be retried for reconnection

◆ discord_gateway_perform()

CCORDcode discord_gateway_perform ( struct discord_gateway gw)

Check and manage on-going Gateway session.

Parameters
reqthe request handler
Returns
CCORDcode value for how the operation went, CCORD_OK means nothing out of the ordinary

◆ discord_gateway_shutdown()

void discord_gateway_shutdown ( struct discord_gateway gw)

Gracefully shutdown a ongoing Discord connection over WebSockets.

Parameters
gwthe handle initialized with discord_gateway_init()

◆ discord_gateway_reconnect()

void discord_gateway_reconnect ( struct discord_gateway gw,
bool  resume 
)

Gracefully reconnect a ongoing Discord connection over WebSockets.

Parameters
gwthe handle initialized with discord_gateway_init()
resumetrue to attempt to resume to previous session, false restart a fresh session

◆ discord_gateway_send_identify()

void discord_gateway_send_identify ( struct discord_gateway gw,
struct discord_identify event 
)

Trigger the initial handshake with the gateway.

Parameters
gwthe handle initialized with discord_gateway_init()
eventprovide client identification information

◆ discord_gateway_send_resume()

void discord_gateway_send_resume ( struct discord_gateway gw,
struct discord_resume event 
)

Replay missed events when a disconnected client resumes.

Parameters
gwthe handle initialized with discord_gateway_init()
eventsession resume information

◆ discord_gateway_send_heartbeat()

void discord_gateway_send_heartbeat ( struct discord_gateway gw,
int  seq 
)

Maintain an active gateway connection.

Parameters
gwthe handle initialized with discord_gateway_init()
seqthe last session sequence number

◆ discord_gateway_send_request_guild_members()

void discord_gateway_send_request_guild_members ( struct discord_gateway gw,
struct discord_request_guild_members event 
)

Request all members for a guild or a list of guilds.

Parameters
gwthe handle initialized with discord_gateway_init()
eventrequest guild members information

◆ discord_gateway_send_update_voice_state()

void discord_gateway_send_update_voice_state ( struct discord_gateway gw,
struct discord_update_voice_state event 
)

Sent when a client wants to join, move or disconnect from a voice channel.

Parameters
gwthe handle initialized with discord_gateway_init()
eventrequest guild members information

◆ discord_gateway_send_presence_update()

void discord_gateway_send_presence_update ( struct discord_gateway gw,
struct discord_presence_update event 
)

Send client's presence status update payload.

Parameters
gwthe handle initialized with discord_gateway_init()
eventthe presence to be set

◆ discord_gateway_dispatch()

void discord_gateway_dispatch ( struct discord_gateway gw)

Dispatch user callback matched to event.

Parameters
gwthe handle initialized with discord_gateway_init()