Concord - C Discord API library
A Discord API wrapper library written in C
discord.h
Go to the documentation of this file.
1
11#ifndef DISCORD_H
12#define DISCORD_H
13
14#ifdef __cplusplus
15extern "C" {
16#endif /* __cplusplus */
17
18#include <inttypes.h>
19#include <stdbool.h>
20
21#include "error.h"
22#include "types.h"
23#include "concord-once.h"
24#include "io_poller.h"
25
26#ifndef DISCORD_VERSION
31#define DISCORD_VERSION "10"
32#endif
33
34#define DISCORD_API_BASE_URL "https://discord.com/api/v" DISCORD_VERSION
35#define DISCORD_GATEWAY_URL_SUFFIX "?v=" DISCORD_VERSION "&encoding=json"
36
37/* forward declaration */
38struct discord;
39
40
41#include "discord_codecs.h"
42#ifdef CCORD_VOICE
43#include "discord-voice.h"
44#endif /* CCORD_VOICE */
45#include "discord-response.h"
46
58#define DISCORD_MAX_NAME_LEN 4 * 100 + 1
59#define DISCORD_MAX_TOPIC_LEN 4 * 1024 + 1
60#define DISCORD_MAX_DESCRIPTION_LEN 4 * 2048 + 1
61#define DISCORD_MAX_USERNAME_LEN 4 * 32 + 1
62#define DISCORD_MAX_DISCRIMINATOR_LEN 4 + 1
63#define DISCORD_MAX_REASON_LEN 4 * 512 + 1
64#define DISCORD_MAX_MESSAGE_LEN 4 * 2000 + 1
65#define DISCORD_MAX_PAYLOAD_LEN 4 * 4096 + 1
71#define DISCORD_EMBED_TITLE_LEN 4 * 256 + 1
72#define DISCORD_EMBED_DESCRIPTION_LEN 4 * 4096 + 1
73#define DISCORD_EMBED_MAX_FIELDS 25
74#define DISCORD_EMBED_FIELD_NAME_LEN 4 * 256 + 1
75#define DISCORD_EMBED_FIELD_VALUE_LEN 4 * 1024 + 1
76#define DISCORD_EMBED_FOOTER_TEXT_LEN 4 * 2048 + 1
77#define DISCORD_EMBED_AUTHOR_NAME_LEN 4 * 256 + 1
83#define DISCORD_WEBHOOK_NAME_LEN 4 * 80 + 1
101 const char error[],
102 CCORDcode code);
103
111const char *discord_strerror(CCORDcode code, struct discord *client);
112
119#include "audit_log.h"
120#include "auto_moderation.h"
121#include "invite.h"
122#include "channel.h"
123#include "emoji.h"
124#include "guild.h"
126#include "guild_template.h"
127#include "stage_instance.h"
128#include "sticker.h"
129#include "user.h"
130#include "voice.h"
131#include "webhook.h"
132#include "gateway.h"
133#include "oauth2.h"
137#include "application_command.h"
138#include "interaction.h"
149#include "discord-cache.h"
150#include "discord-events.h"
151
160#define discord_claim(client, data) (__discord_claim(client, data), data)
161void __discord_claim(struct discord *client, const void *data);
162
173void discord_unclaim(struct discord *client, const void *data);
174
182struct discord *discord_init(const char token[]);
183
190struct discord *discord_config_init(const char config_file[]);
191
221 char *const path[],
222 unsigned depth);
223
233struct discord *discord_clone(const struct discord *orig);
234
241void discord_cleanup(struct discord *client);
242
250const struct discord_user *discord_get_self(struct discord *client);
251
259
265void discord_shutdown(struct discord *client);
266
274void discord_reconnect(struct discord *client, bool resume);
275
285void *discord_set_data(struct discord *client, void *data);
286
295void *discord_get_data(struct discord *client);
296
305int discord_get_ping(struct discord *client);
306
313uint64_t discord_timestamp(struct discord *client);
314
321uint64_t discord_timestamp_us(struct discord *client);
322
330struct logconf *discord_get_logconf(struct discord *client);
331
338struct io_poller *discord_get_io_poller(struct discord *client);
339
344/* forward declaration */
345struct discord_timer;
346
347
349typedef void (*discord_ev_timer)(struct discord *client,
350 struct discord_timer *ev);
351
370};
371
375 unsigned id;
384 void *data;
386 int64_t delay;
388 int64_t interval;
390 int64_t repeat;
391};
392
400unsigned discord_timer_ctl(struct discord *client,
401 struct discord_timer *timer);
402
416unsigned discord_timer(struct discord *client,
417 discord_ev_timer on_tick_cb,
418 discord_ev_timer on_status_changed_cb,
419 void *data,
420 int64_t delay);
421
437unsigned discord_timer_interval(struct discord *client,
438 discord_ev_timer on_tick_cb,
439 discord_ev_timer on_status_changed_cb,
440 void *data,
441 int64_t delay,
442 int64_t interval,
443 int64_t repeat);
444
453bool discord_timer_get(struct discord *client,
454 unsigned id,
455 struct discord_timer *timer);
456
464bool discord_timer_start(struct discord *client, unsigned id);
465
473bool discord_timer_stop(struct discord *client, unsigned id);
474
483bool discord_timer_cancel(struct discord *client, unsigned id);
484
492bool discord_timer_delete(struct discord *client, unsigned id);
493
501bool discord_timer_cancel_and_delete(struct discord *client, unsigned id);
502
509#ifdef __cplusplus
510}
511#endif /* __cplusplus */
512
513#endif /* DISCORD_H */
Application Command public functions and datatypes.
Initialized once.
Caching of Discord resources.
Listen, react and trigger Discord Gateway events.
Generic macros for initializing a discord_response and return handles.
CCORDcode
Definition: error.h:12
CCORDcode discord_return_error(struct discord *client, const char error[], CCORDcode code)
Return a Concord's error.
const char * discord_strerror(CCORDcode code, struct discord *client)
Return the meaning of CCORDcode.
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
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_clone(const struct discord *orig)
Clone a discord client.
void discord_shutdown(struct discord *client)
Gracefully shutdown an ongoing Discord connection.
struct logconf * discord_get_logconf(struct discord *client)
Retrieve client's logging module for configuration purposes.
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()
struct discord * discord_config_init(const char config_file[])
Create a Discord Client handle by a config.json file.
int discord_get_ping(struct discord *client)
Get the client WebSockets ping.
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.
struct discord * discord_init(const char token[])
Create a Discord Client handle by its token.
void __discord_claim(struct discord *client, const void *data)
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:353
void(* discord_ev_timer)(struct discord *client, struct discord_timer *ev)
callback to be used with struct discord_timer
Definition: discord.h:349
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:365
@ DISCORD_TIMER_MILLISECONDS
Definition: discord.h:355
@ DISCORD_TIMER_INTERVAL_FIXED
Definition: discord.h:369
@ DISCORD_TIMER_DELETE_AUTO
Definition: discord.h:361
@ DISCORD_TIMER_CANCELED
Definition: discord.h:363
@ DISCORD_TIMER_DELETE
Definition: discord.h:359
@ DISCORD_TIMER_MICROSECONDS
Definition: discord.h:357
@ DISCORD_TIMER_GET
Definition: discord.h:367
Audit Log public functions and datatypes.
Auto Moderation public functions and datatypes.
Channel public functions and datatypes.
Emoji public functions and datatypes.
Gateway public functions and datatypes.
Guild public functions and datatypes.
Guild Scheduled Event public functions and datatypes.
Guild Template public functions and datatypes.
Invite public functions and datatypes.
OAuth2 public functions and datatypes.
Stage Instance public functions and datatypes.
Sticker public functions and datatypes.
User public functions and datatypes.
Voice public functions and datatypes.
Webhook public functions and datatypes.
Interaciton public functions and datatypes.
Read-only generic sized buffer.
Definition: types.h:55
struct used for modifying, and getting info about a timer
Definition: discord.h:373
discord_ev_timer on_status_changed
Definition: discord.h:382
void * data
Definition: discord.h:384
enum discord_timer_flags flags
Definition: discord.h:377
unsigned id
Definition: discord.h:375
int64_t interval
Definition: discord.h:388
discord_ev_timer on_tick
Definition: discord.h:379
int64_t repeat
Definition: discord.h:390
int64_t delay
Definition: discord.h:386
Definition: user.h:69
The Discord client handler.
Definition: discord-internal.h:1182
void * data
Definition: discord-internal.h:1225
char * token
Definition: discord-internal.h:1188
A stackful and modularized wrapper over the popular 'log.c' facilities.
Definition: logconf.h:217