27#ifndef DISCORD_VERSION
32#define DISCORD_VERSION "10"
35#define DISCORD_API_BASE_URL "https://discord.com/api/v" DISCORD_VERSION
36#define DISCORD_GATEWAY_URL_SUFFIX "?v=" DISCORD_VERSION "&encoding=json"
51#include "discord_codecs.h"
65#define DISCORD_MAX_NAME_LEN 4 * 100 + 1
66#define DISCORD_MAX_TOPIC_LEN 4 * 1024 + 1
67#define DISCORD_MAX_DESCRIPTION_LEN 4 * 2048 + 1
68#define DISCORD_MAX_USERNAME_LEN 4 * 32 + 1
69#define DISCORD_MAX_DISCRIMINATOR_LEN 4 + 1
70#define DISCORD_MAX_REASON_LEN 4 * 512 + 1
71#define DISCORD_MAX_MESSAGE_LEN 4 * 2000 + 1
72#define DISCORD_MAX_PAYLOAD_LEN 4 * 4096 + 1
78#define DISCORD_EMBED_TITLE_LEN 4 * 256 + 1
79#define DISCORD_EMBED_DESCRIPTION_LEN 4 * 4096 + 1
80#define DISCORD_EMBED_MAX_FIELDS 25
81#define DISCORD_EMBED_FIELD_NAME_LEN 4 * 256 + 1
82#define DISCORD_EMBED_FIELD_VALUE_LEN 4 * 1024 + 1
83#define DISCORD_EMBED_FOOTER_TEXT_LEN 4 * 2048 + 1
84#define DISCORD_EMBED_AUTHOR_NAME_LEN 4 * 256 + 1
90#define DISCORD_WEBHOOK_NAME_LEN 4 * 80 + 1
105#define CCORD_DISCORD_OK CCORD_OK
108#define CCORD_PENDING 1
110#define CCORD_DISCORD_JSON_CODE 100
112#define CCORD_DISCORD_BAD_AUTH 101
114#define CCORD_DISCORD_RATELIMIT 102
116#define CCORD_DISCORD_CONNECTION 103
184#define discord_claim(client, data) (__discord_claim(client, data), data)
200#define ccord_global_init()
203#define ccord_global_cleanup()
225#define ccord_shutdown_async() discord_shutdown_all()
298#define discord_init discord_from_token
304#define discord_config_init discord_from_json
458#define __CAT(_a, _b) _a##_b
459#define _CAT(_a, _b) __CAT(_a, _b)
460#define _EXPECT_CONTAINER__struct
461#define _EXPECT_CONTAINER__union
462#define _DISCORD_SYMBOL_WITHOUT_CONTAINER(_symbol) \
463 _CAT(_EXPECT_CONTAINER__, _symbol)
470#define discord_data_wrap reflectc_wrap
480#define discord_data_wrap_from(_symbol, _client, _data) \
481 _CAT(reflectc_from_, _DISCORD_SYMBOL_WITHOUT_CONTAINER(_symbol))( \
482 discord_get_registry((_client)), _data, NULL)
496#define discord_data_cleanup(_client, _data) \
497 discord_data_free(discord_get_registry((_client)), (_data))
515#define discord_data_unwrap(_client, _data) \
516 discord_data_release(discord_get_registry((_client)), (_data))
551#define discord_data_to_json(_symbol, _client, _data, _p_buf, _p_bufsize) \
552 discord_data_wrap_to_json( \
553 discord_data_wrap_from(_symbol, _client, _data), _p_buf, _p_bufsize)
580#define discord_data_to_jsonb(_symbol, _client, _jb, _data, _p_buf, \
582 discord_data_wrap_to_jsonb( \
583 _jb, discord_data_wrap_from(_symbol, _client, _data), _p_buf, \
608#define discord_data_from_json(_symbol, _client, _json, _len, _data) \
609 discord_data_wrap_from_json( \
610 _json, _len, discord_data_wrap_from(_symbol, _client, _data))
637#define discord_data_from_jsmnf(_client, _p, _json, _length, _type, _data) \
638 discord_data_wrap_from_jsmnf( \
639 _p, _json, _length, discord_data_wrap_from(_type, _client, _data))
Application Command public functions and datatypes.
Audit Log public functions and datatypes.
Auto Moderation public functions and datatypes.
Channel public functions and datatypes.
Caching of Discord resources.
Listen, react and trigger Discord Gateway events.
Generic macros for initializing a discord_response and return handles.
struct reflectc * discord_get_registry(struct discord *client)
Get the reflectc registry from a Discord client.
Emoji public functions and datatypes.
Gateway public functions and datatypes.
int CCORDcode
Concord error codes.
Definition: concord-error.h:11
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
bool discord_shutdown_all_ongoing(void)
Check if all Discord connections shutting down is in progress.
CCORDcode discord_run(struct discord *client)
Start a connection to the Discord Gateway.
uint64_t discord_timestamp(struct discord *client)
Get the current timestamp (in milliseconds)
const struct discord_user * discord_get_self(struct discord *client)
Get the client's cached user.
void discord_unclaim(struct discord *client, const void *data)
Unclaim ownership of a resource provided by Concord.
struct discord * discord_from_token(const char token[])
Creates a Discord Client handle from a token.
struct logmod * discord_get_logmod(struct discord *client)
Retrieve client's logging module for configuration purposes.
struct discord * discord_clone(const struct discord *orig)
Clone a discord client.
void discord_shutdown_all(void)
Gracefully notify all Discord connections for shutting down.
void discord_shutdown(struct discord *client)
Gracefully shutdown an ongoing Discord connection.
void discord_reconnect(struct discord *client, bool resume)
Gracefully reconnects an ongoing Discord connection.
void * discord_get_data(struct discord *client)
Receive user arbitrary data stored with discord_set_data()
int discord_get_ping(struct discord *client)
Get the client WebSockets ping.
struct discord * discord_from_config(const struct discord_config *config)
Creates a Discord Client handle from a discord_config structure.
struct discord * discord_from_json(const char config_file[])
Creates a Discord Client handle from a config.json file.
void * discord_set_data(struct discord *client, void *data)
Store user arbitrary data that can be retrieved by discord_get_data()
struct io_poller * discord_get_io_poller(struct discord *client)
get the io_poller used by the discord client
uint64_t discord_timestamp_us(struct discord *client)
Get the current timestamp (in microseconds)
struct ccord_szbuf_readonly discord_config_get_field(struct discord *client, char *const path[], unsigned depth)
Get the contents from the config file field.
void __discord_claim(struct discord *client, const 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.
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.
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.
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.
void discord_data_free(struct reflectc *registry, void *data)
#define discord_data_wrap
The Discord data wrap structure.
Definition: discord.h:470
void discord_data_release(struct reflectc *registry, void *data)
const char * discord_code_as_string(CCORDcode code)
Return the value of CCORDcode as a string.
const char * discord_strerror(CCORDcode code, struct discord *client)
Return the meaning of CCORDcode.
unsigned discord_timer_ctl(struct discord *client, struct discord_timer *timer)
modifies or creates a timer
bool discord_timer_cancel(struct discord *client, unsigned id)
cancels a timer, this will delete the timer if DISCORD_TIMER_DELETE_AUTO is enabled
bool discord_timer_start(struct discord *client, unsigned id)
starts a timer
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
discord_timer_flags
flags used to change behaviour of timer
Definition: discord.h:658
void(* discord_ev_timer)(struct discord *client, struct discord_timer *ev)
callback to be used with struct discord_timer
Definition: discord.h:654
bool discord_timer_get(struct discord *client, unsigned id, struct discord_timer *timer)
get the data associated with the timer
bool discord_timer_stop(struct discord *client, unsigned id)
stops a timer
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
bool discord_timer_cancel_and_delete(struct discord *client, unsigned id)
cancels, and deletes a timer
bool discord_timer_delete(struct discord *client, unsigned id)
deletes a timer
@ DISCORD_TIMER_TICK
Definition: discord.h:670
@ DISCORD_TIMER_MILLISECONDS
Definition: discord.h:660
@ DISCORD_TIMER_INTERVAL_FIXED
Definition: discord.h:674
@ DISCORD_TIMER_DELETE_AUTO
Definition: discord.h:666
@ DISCORD_TIMER_CANCELED
Definition: discord.h:668
@ DISCORD_TIMER_DELETE
Definition: discord.h:664
@ DISCORD_TIMER_MICROSECONDS
Definition: discord.h:662
@ DISCORD_TIMER_GET
Definition: discord.h:672
Guild public functions and datatypes.
Guild Scheduled Event public functions and datatypes.
Guild Template public functions and datatypes.
Interaciton public functions and datatypes.
Invite public functions and datatypes.
logmod_levels
Log levels supported by LogMod.
Definition: logmod.h:64
OAuth2 public functions and datatypes.
Stage Instance public functions and datatypes.
Sticker public functions and datatypes.
Read-only generic sized buffer.
Definition: types.h:57
The Discord configuration handler.
Definition: discord.h:250
FILE * trace
Definition: discord.h:272
char * token
Definition: discord.h:252
struct discord_config::@0::@1 disable
FILE * http
Definition: discord.h:274
FILE * ws
Definition: discord.h:276
bool color
Definition: discord.h:268
char ** ids
Definition: discord.h:279
bool quiet
Definition: discord.h:266
enum logmod_levels level
Definition: discord.h:264
size_t size
Definition: discord.h:278
struct discord_config::@0 log
char * base_url
Definition: discord.h:261
bool overwrite
Definition: discord.h:270
struct used for modifying, and getting info about a timer
Definition: discord.h:678
discord_ev_timer on_status_changed
Definition: discord.h:687
void * data
Definition: discord.h:689
enum discord_timer_flags flags
Definition: discord.h:682
unsigned id
Definition: discord.h:680
int64_t interval
Definition: discord.h:693
discord_ev_timer on_tick
Definition: discord.h:684
int64_t repeat
Definition: discord.h:695
int64_t delay
Definition: discord.h:691
The Discord client handler.
Definition: discord-internal.h:1206
struct discord_config config
Definition: discord-internal.h:1220
Handle for building a JSON string.
Definition: json-build.h:63
Main logging context structure.
Definition: logmod.h:240
User public functions and datatypes.
Voice public functions and datatypes.
Webhook public functions and datatypes.