Concord - C Discord API library
A Discord API wrapper library written in C
discord.h File Reference

Public functions and datatypes. More...

#include <inttypes.h>
#include <stdbool.h>
#include "concord-error.h"
#include "types.h"
#include "io_poller.h"
#include "logmod.h"
#include "discord_codecs.h"
#include "discord-response.h"
#include "audit_log.h"
#include "auto_moderation.h"
#include "invite.h"
#include "channel.h"
#include "emoji.h"
#include "guild.h"
#include "guild_scheduled_event.h"
#include "guild_template.h"
#include "stage_instance.h"
#include "sticker.h"
#include "user.h"
#include "voice.h"
#include "webhook.h"
#include "gateway.h"
#include "oauth2.h"
#include "application_command.h"
#include "interaction.h"
#include "discord-cache.h"
#include "discord-events.h"
Include dependency graph for discord.h:

Go to the source code of this file.

Data Structures

struct  discord_config
 The Discord configuration handler. More...
 
struct  discord_timer
 struct used for modifying, and getting info about a timer More...
 

Macros

#define LOGMOD_HEADER
 
#define DISCORD_VERSION   "10"
 The Discord API version to use. More...
 
#define DISCORD_API_BASE_URL   "https://discord.com/api/v" DISCORD_VERSION
 
#define DISCORD_GATEWAY_URL_SUFFIX   "?v=" DISCORD_VERSION "&encoding=json"
 
#define DISCORD_MAX_NAME_LEN   4 * 100 + 1
 
#define DISCORD_MAX_TOPIC_LEN   4 * 1024 + 1
 
#define DISCORD_MAX_DESCRIPTION_LEN   4 * 2048 + 1
 
#define DISCORD_MAX_USERNAME_LEN   4 * 32 + 1
 
#define DISCORD_MAX_DISCRIMINATOR_LEN   4 + 1
 
#define DISCORD_MAX_REASON_LEN   4 * 512 + 1
 
#define DISCORD_MAX_MESSAGE_LEN   4 * 2000 + 1
 
#define DISCORD_MAX_PAYLOAD_LEN   4 * 4096 + 1
 
#define DISCORD_EMBED_TITLE_LEN   4 * 256 + 1
 
#define DISCORD_EMBED_DESCRIPTION_LEN   4 * 4096 + 1
 
#define DISCORD_EMBED_MAX_FIELDS   25
 
#define DISCORD_EMBED_FIELD_NAME_LEN   4 * 256 + 1
 
#define DISCORD_EMBED_FIELD_VALUE_LEN   4 * 1024 + 1
 
#define DISCORD_EMBED_FOOTER_TEXT_LEN   4 * 2048 + 1
 
#define DISCORD_EMBED_AUTHOR_NAME_LEN   4 * 256 + 1
 
#define DISCORD_WEBHOOK_NAME_LEN   4 * 80 + 1
 
#define CCORD_DISCORD_OK   CCORD_OK
 
#define CCORD_PENDING   1
 
#define CCORD_DISCORD_JSON_CODE   100
 
#define CCORD_DISCORD_BAD_AUTH   101
 
#define CCORD_DISCORD_RATELIMIT   102
 
#define CCORD_DISCORD_CONNECTION   103
 
#define discord_claim(client, data)   (__discord_claim(client, data), data)
 Claim ownership of a resource provided by Concord. More...
 
#define ccord_global_init()
 
#define ccord_global_cleanup()
 
#define ccord_shutdown_async()   discord_shutdown_all()
 Backwards compatible alias for discord_shutdown_all() More...
 
#define discord_init   discord_from_token
 Backwards compatible alias for discord_from_token() More...
 
#define discord_config_init   discord_from_json
 Backwards compatible alias for discord_from_json() More...
 
#define __CAT(_a, _b)   _a##_b
 
#define _CAT(_a, _b)   __CAT(_a, _b)
 
#define _EXPECT_CONTAINER__struct
 
#define _EXPECT_CONTAINER__union
 
#define _DISCORD_SYMBOL_WITHOUT_CONTAINER(_symbol)    _CAT(_EXPECT_CONTAINER__, _symbol)
 
#define discord_data_wrap   reflectc_wrap
 The Discord data wrap structure. More...
 
#define discord_data_wrap_from(_symbol, _client, _data)
 Wrap a Discord data type into a reflectc_wrap structure. More...
 
#define discord_data_cleanup(_client, _data)    discord_data_free(discord_get_registry((_client)), (_data))
 Cleanup a Discord data type wrapped into a reflectc_wrap structure. More...
 
#define discord_data_unwrap(_client, _data)    discord_data_release(discord_get_registry((_client)), (_data))
 Drop the wrap cached for _data without touching its contents. More...
 
#define discord_data_to_json(_symbol, _client, _data, _p_buf, _p_bufsize)
 Transform a Discord data type into a JSON string. More...
 
#define discord_data_to_jsonb(_symbol, _client, _jb, _data, _p_buf, _p_bufsize)
 Transform a Discord data type into a jsonb handle. More...
 
#define discord_data_from_json(_symbol, _client, _json, _len, _data)
 Parse a JSON string and fill a Discord data type. More...
 
#define discord_data_from_jsmnf(_client, _p, _json, _length, _type, _data)
 Parse a jsmnf_pair and fill a Discord data type. More...
 

Typedefs

typedef void(* discord_ev_timer) (struct discord *client, struct discord_timer *ev)
 callback to be used with struct discord_timer More...
 

Enumerations

enum  discord_timer_flags {
  DISCORD_TIMER_MILLISECONDS = 0 , DISCORD_TIMER_MICROSECONDS = 1 << 0 , DISCORD_TIMER_DELETE = 1 << 1 , DISCORD_TIMER_DELETE_AUTO = 1 << 2 ,
  DISCORD_TIMER_CANCELED = 1 << 3 , DISCORD_TIMER_TICK = 1 << 4 , DISCORD_TIMER_GET = 1 << 5 , DISCORD_TIMER_INTERVAL_FIXED = 1 << 6
}
 flags used to change behaviour of timer More...
 

Functions

struct reflectc * discord_get_registry (struct discord *client)
 Get the reflectc registry from a Discord client. More...
 
const char * discord_code_as_string (CCORDcode code)
 Return the value of CCORDcode as a string. More...
 
const char * discord_strerror (CCORDcode code, struct discord *client)
 Return the meaning of CCORDcode. More...
 
void __discord_claim (struct discord *client, const void *data)
 
void discord_unclaim (struct discord *client, const void *data)
 Unclaim ownership of a resource provided by Concord. More...
 
void discord_shutdown_all (void)
 Gracefully notify all Discord connections for shutting down. More...
 
bool discord_shutdown_all_ongoing (void)
 Check if all Discord connections shutting down is in progress. More...
 
struct discorddiscord_from_token (const char token[])
 Creates a Discord Client handle from a token. More...
 
struct discorddiscord_from_json (const char config_file[])
 Creates a Discord Client handle from a config.json file. More...
 
struct discorddiscord_from_config (const struct discord_config *config)
 Creates a Discord Client handle from a discord_config structure. More...
 
struct ccord_szbuf_readonly discord_config_get_field (struct discord *client, char *const path[], unsigned depth)
 Get the contents from the config file field. More...
 
struct discorddiscord_clone (const struct discord *orig)
 Clone a discord client. More...
 
void discord_cleanup (struct discord *client)
 Free a Discord Client handle. More...
 
const struct discord_user * discord_get_self (struct discord *client)
 Get the client's cached user. More...
 
CCORDcode discord_run (struct discord *client)
 Start a connection to the Discord Gateway. More...
 
void discord_shutdown (struct discord *client)
 Gracefully shutdown an ongoing Discord connection. More...
 
void discord_reconnect (struct discord *client, bool resume)
 Gracefully reconnects an ongoing Discord connection. More...
 
void * discord_set_data (struct discord *client, void *data)
 Store user arbitrary data that can be retrieved by discord_get_data() More...
 
void * discord_get_data (struct discord *client)
 Receive user arbitrary data stored with discord_set_data() More...
 
int discord_get_ping (struct discord *client)
 Get the client WebSockets ping. More...
 
uint64_t discord_timestamp (struct discord *client)
 Get the current timestamp (in milliseconds) More...
 
uint64_t discord_timestamp_us (struct discord *client)
 Get the current timestamp (in microseconds) More...
 
struct logmoddiscord_get_logmod (struct discord *client)
 Retrieve client's logging module for configuration purposes. More...
 
struct io_poller * discord_get_io_poller (struct discord *client)
 get the io_poller used by the discord client More...
 
void discord_data_free (struct reflectc *registry, void *data)
 
void discord_data_release (struct reflectc *registry, void *data)
 
CCORDcode discord_data_wrap_to_json (const struct reflectc_wrap *member, char *p_buf[], size_t *p_bufsize)
 Transform a wrapped Discord data type into a JSON string. More...
 
CCORDcode discord_data_wrap_to_jsonb (struct jsonb *jb, const struct reflectc_wrap *member, char *p_buf[], size_t *p_bufsize)
 Transform a wrapped Discord data type into a jsonb handle. More...
 
CCORDcode discord_data_wrap_from_json (const char *json, size_t len, struct reflectc_wrap *root)
 Parse a JSON string and fill a wrapped Discord data type. More...
 
CCORDcode discord_data_wrap_from_jsmnf (const struct jsmnf_pair *p, const char *json, size_t length, const struct reflectc_wrap *member)
 Parse a jsmnf_pair and fill a wrapped Discord data type. More...
 
unsigned discord_timer_ctl (struct discord *client, struct discord_timer *timer)
 modifies or creates a timer More...
 
unsigned discord_timer (struct discord *client, discord_ev_timer on_tick_cb, discord_ev_timer on_status_changed_cb, void *data, int64_t delay)
 creates a one shot timer that automatically deletes itself upon completion More...
 
unsigned discord_timer_interval (struct discord *client, discord_ev_timer on_tick_cb, discord_ev_timer on_status_changed_cb, void *data, int64_t delay, int64_t interval, int64_t repeat)
 creates a repeating timer that automatically deletes itself upon completion More...
 
bool discord_timer_get (struct discord *client, unsigned id, struct discord_timer *timer)
 get the data associated with the timer More...
 
bool discord_timer_start (struct discord *client, unsigned id)
 starts a timer More...
 
bool discord_timer_stop (struct discord *client, unsigned id)
 stops a timer More...
 
bool discord_timer_cancel (struct discord *client, unsigned id)
 cancels a timer, this will delete the timer if DISCORD_TIMER_DELETE_AUTO is enabled More...
 
bool discord_timer_delete (struct discord *client, unsigned id)
 deletes a timer More...
 
bool discord_timer_cancel_and_delete (struct discord *client, unsigned id)
 cancels, and deletes a timer More...
 

Detailed Description

Public functions and datatypes.

Author
Cogmasters

These symbols are organized in a intuitive fashion to be easily matched to the official Discord API docs

See also
https://discord.com/developers/docs/intro

Macro Definition Documentation

◆ LOGMOD_HEADER

#define LOGMOD_HEADER

◆ DISCORD_VERSION

#define DISCORD_VERSION   "10"

The Discord API version to use.

Warning
only change this if you know what you are doing!

◆ DISCORD_API_BASE_URL

#define DISCORD_API_BASE_URL   "https://discord.com/api/v" DISCORD_VERSION

◆ DISCORD_GATEWAY_URL_SUFFIX

#define DISCORD_GATEWAY_URL_SUFFIX   "?v=" DISCORD_VERSION "&encoding=json"

Function Documentation

◆ discord_get_registry()

struct reflectc * discord_get_registry ( struct discord client)

Get the reflectc registry from a Discord client.

Parameters
clientthe client created with discord_from_json() or discord_from_token()
Returns
the reflectc registry used by the client