Orca
A bot framework that is easy to reason about, easy to debug, and easy to use.
|
Go to the documentation of this file.
16 #include "json-actor-boxed.h"
20 #define DISCORD_API_BASE_URL "https://discord.com/api/v9"
21 #define DISCORD_GATEWAY_URL_SUFFIX "?v=9&encoding=json"
22 #define DISCORD_VOICE_CONNECTIONS_URL_SUFFIX "?v=4"
33 #define SNOWFLAKE_INCREMENT 12
34 #define SNOWFLAKE_PROCESS_ID 17
35 #define SNOWFLAKE_INTERNAL_WORKER_ID 22
36 #define SNOWFLAKE_TIMESTAMP 64
39 #define MAX_NAME_LEN 100 + 1
40 #define MAX_TOPIC_LEN 1024 + 1
41 #define MAX_DESCRIPTION_LEN 2048 + 1
42 #define MAX_USERNAME_LEN 32 + 1
43 #define MAX_DISCRIMINATOR_LEN 4 + 1
44 #define MAX_SHA256_LEN 1024 + 1
45 #define MAX_LOCALE_LEN 16 + 1
46 #define MAX_EMAIL_LEN 254 + 1
47 #define MAX_REGION_LEN 16 + 1
48 #define MAX_REASON_LEN 512 + 1
49 #define MAX_MESSAGE_LEN 4000 + 1
50 #define MAX_PAYLOAD_LEN 4096 + 1
54 #define EMBED_TITLE_LEN 256 + 1
55 #define EMBED_DESCRIPTION_LEN 2048 + 1
56 #define EMBED_MAX_FIELDS 25
57 #define EMBED_FIELD_NAME_LEN 256 + 1
58 #define EMBED_FIELD_VALUE_LEN 1024 + 1
59 #define EMBED_FOOTER_TEXT_LEN 2048 + 1
60 #define EMBED_AUTHOR_NAME_LEN 256 + 1
64 #define WEBHOOK_NAME_LEN 80 + 1
67 #include "specs-code/discord/all_opaque_struct.h"
68 #include "specs-code/discord/all_enums.h"
69 #include "specs-code/discord/all_structs.h"
70 #include "specs-code/discord/all_functions.h"
89 enum discord_gateway_events event,
90 struct sized_buffer *sb_bot,
91 struct sized_buffer *event_data);
159 typedef void (*sb_message_cb)(
161 struct sized_buffer *sb_bot,
163 struct sized_buffer *msg_payload);
184 const NTL_T(ja_u64) ids,
275 const char *endpoint);
341 enum discord_message_flags_code *flags;
554 void discord_set_on_sb_message_create(
struct discord *client, sb_message_cb callback);
563 void discord_set_on_sb_message_update(
struct discord *client, sb_message_cb callback);
770 ORCAcode discord_modify_current_user_nick(
struct discord *client,
const u64_snowflake_t guild_id,
const char nick[]);
786 ORCAcode discord_delete_invite(
struct discord *client,
char *invite_code,
struct discord_invite *p_invite);
792 ORCAcode sb_discord_get_current_user(
struct discord *client,
struct sized_buffer *p_sb_user);
793 ORCAcode discord_get_current_user_guilds(
struct discord *client, NTL_T(
struct discord_guild) *p_guilds);
811 void discord_embed_set_thumbnail(
struct discord_embed *embed,
char url[],
char proxy_url[],
int height,
int width);
812 void discord_embed_set_image(
struct discord_embed *embed,
char url[],
char proxy_url[],
int height,
int width);
813 void discord_embed_set_video(
struct discord_embed *embed,
char url[],
char proxy_url[],
int height,
int width);
814 void discord_embed_set_footer(
struct discord_embed *embed,
char text[],
char icon_url[],
char proxy_icon_url[]);
815 void discord_embed_set_provider(
struct discord_embed *embed,
char name[],
char url[]);
816 void discord_embed_set_author(
struct discord_embed *embed,
char name[],
char url[],
char icon_url[],
char proxy_icon_url[]);
817 void discord_embed_add_field(
struct discord_embed *embed,
char name[],
char value[],
bool Inline);
820 void discord_overwrite_append(NTL_T(
struct discord_channel_overwrite) *permission_overwrites,
u64_snowflake_t id,
int type,
enum discord_permissions_bitwise_flags allow,
enum discord_permissions_bitwise_flags deny);
821 ORCAcode discord_get_channel_at_pos(
struct discord *client,
const u64_snowflake_t guild_id,
const enum discord_channel_types type,
const size_t position,
struct discord_channel *p_channel);
828 #ifdef _DISCORD_ADD_ONS
Edit Channel Permissions.
Definition: channel.endpoints-params.h:173
void discord_global_init()
Initialize resources of globals used by discord.h.
bool tts
enable/disable text-to-speech
Definition: discord.h:318
void(* voice_state_update_cb)(struct discord *client, const struct discord_user *bot, const struct discord_voice_state *voice_state)
Voice State Update callback.
Definition: discord.h:263
void discord_add_intents(struct discord *client, enum discord_gateway_intents code)
Subscribe to Discord Gateway events.
void * data
space for user arbitrary data
Definition: discord-internal.h:282
Connection Structure.
Definition: user.h:148
void discord_replace_presence(struct discord *client, struct discord_gateway_status_update *presence)
Replace the Client presence with a struct discord_gateway_status_update.
void discord_set_on_ready(struct discord *client, idle_cb callback)
Set a callback that triggers when the client is ready.
u64_unix_ms_t identify_tstamp
timestamp of last succesful identify request
Definition: discord.h:292
struct discord * discord_config_init(const char config_file[])
Create a Discord Client handle by a bot.config file.
Create Guild Role.
Definition: guild.endpoints-params.h:535
Modify Guild Role Positions.
Definition: guild.endpoints-params.h:597
Modify Channel.
Definition: channel.endpoints-params.h:17
Definition: discord.h:348
void discord_set_on_guild_role_update(struct discord *client, guild_role_cb callback)
Set a callback that triggers when a guild role is updated.
void(* channel_cb)(struct discord *client, const struct discord_user *bot, const struct discord_channel *channel)
Channel Create/Update/Delete callback.
Definition: discord.h:196
void discord_set_on_message_create(struct discord *client, message_cb callback)
Set a callback that triggers when a message is created.
void(* idle_cb)(struct discord *client, const struct discord_user *bot)
Idle callback.
Definition: discord.h:78
void discord_set_on_message_reaction_remove(struct discord *client, message_reaction_remove_cb callback)
Set a callback that triggers when a message reaction is removed.
Role Structure.
Definition: permissions.h:56
Ban Structure.
Definition: guild.h:820
void discord_set_on_guild_role_create(struct discord *client, guild_role_cb callback)
Set a callback that triggers when a guild role is created.
Modify Current User.
Definition: user.endpoints-params.h:17
Gateway Status Update Structure.
Definition: gateway.h:194
Allowed Mentions Structure.
Definition: channel.h:1024
void discord_set_presence(struct discord *client, struct discord_gateway_activity *activity, char status[], bool afk)
Modify the Client presence state.
Definition: discord.h:282
void(* message_reaction_remove_emoji_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id, const struct discord_emoji *emoji)
Message Reaction Remove Emoji callback.
Definition: discord.h:251
char * nonce
the nonce of the message being sent
Definition: discord.h:317
Voice State Structure.
Definition: voice.h:17
void discord_set_on_idle(struct discord *client, idle_cb callback)
Set a callback that triggers at every event-loop iteration.
void discord_set_on_voice_state_update(struct discord *client, voice_state_update_cb callback)
Set a callback that triggers when a voice state is updated.
void discord_set_on_message_reaction_remove_emoji(struct discord *client, message_reaction_remove_emoji_cb callback)
Set a callback that triggers when all instances of a particular reaction from some message is removed...
void discord_set_on_guild_ban_remove(struct discord *client, guild_ban_cb callback)
Set a callback that triggers when a guild ban is removed.
void * discord_set_data(struct discord *client, void *data)
Keep some user arbitrary data, by associating it to the client.
int shards
The recommended number of shards to use when connecting.
Definition: discord.h:284
int reset_after
the number of milliseconds after which the limit resets
Definition: discord.h:288
void discord_set_on_voice_server_update(struct discord *client, voice_server_update_cb callback)
Set a callback that triggers when a voice server is updated.
void(* event_raw_cb)(struct discord *client, enum discord_gateway_events event, struct sized_buffer *sb_bot, struct sized_buffer *event_data)
Raw Event callback.
Definition: discord.h:87
void discord_set_on_guild_member_add(struct discord *client, guild_member_cb callback)
Set a callback that triggers when a guild member is added.
struct discord * discord_init(const char token[])
Create a Discord Client handle by its token.
void discord_set_on_message_reaction_add(struct discord *client, message_reaction_add_cb callback)
Set a callback that triggers when a message reaction is added.
Follow News Channel.
Definition: channel.endpoints-params.h:227
size_t size
the size of the file being sent (if content is set)
Definition: discord.h:330
void discord_global_cleanup()
Free resources of globals used by discord.h.
void(* guild_member_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_guild_member *member)
Guild Member Add/Update callback.
Definition: discord.h:122
struct sized_buffer token
the bot token
Definition: discord-internal.h:272
u64_unix_ms_t event_tstamp
timestamp of last succesful event timestamp in ms (resets every 60s)
Definition: discord.h:294
char url[1024]
The WSS URL that can be used for connecting to the gateway.
Definition: discord.h:283
Group DM Add Recipient.
Definition: channel.endpoints-params.h:343
void discord_set_on_message_update(struct discord *client, message_cb callback)
Set a callback that triggers when a message is updated.
void(* message_reaction_remove_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t user_id, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id, const struct discord_emoji *emoji)
Message Reaction Remove callback.
Definition: discord.h:229
void discord_set_on_guild_member_update(struct discord *client, guild_member_cb callback)
Set a callback that triggers when a guild member is updated.
void(* message_delete_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t id, const u64_snowflake_t channel_id, const u64_snowflake_t guild_id)
Message Delete callback.
Definition: discord.h:171
Definition: discord.h:314
@ EVENT_WILL_BE_HANDLED_IN_CHILD_THREAD
handle this event in a child thread
Definition: discord.h:647
Guild Preview Object.
Definition: guild.h:383
Guild Structure.
Definition: guild.h:17
Overwrite Structure.
Definition: channel.h:716
Activity Structure.
Definition: gateway.h:308
Get Reactions.
Definition: channel.endpoints-params.h:123
Audit Log Structure.
Definition: audit_log.h:17
void * discord_get_data(struct discord *client)
Received user arbitrary data associated to the client.
Modify Guild Role.
Definition: guild.endpoints-params.h:647
void discord_set_on_message_reaction_remove_all(struct discord *client, message_reaction_remove_all_cb callback)
Set a callback that triggers when all reaction from some message is removed.
void discord_set_on_guild_role_delete(struct discord *client, guild_role_delete_cb callback)
Set a callback that triggers when a guild role is deleted.
void discord_set_on_command(struct discord *client, char *command, message_cb callback)
Set command/callback pair, the callback is triggered if someone types command in chat.
void(* message_cb)(struct discord *client, const struct discord_user *bot, const struct discord_message *message)
Message Create/Update callback.
Definition: discord.h:156
Voice Region Structure.
Definition: voice.h:107
void(* guild_role_delete_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const u64_snowflake_t role_id)
Guild Role Delete callback.
Definition: discord.h:110
Thread Member Object.
Definition: channel.h:838
u64_snowflake_t after
the highest user id in the previous page
Definition: discord.h:350
int total
the total number of session starts the current user is allowed
Definition: discord.h:286
char * content
the content of the message being sent
Definition: discord.h:316
discord_event_handling_mode
Definition: discord.h:644
void discord_run(struct discord *client)
Start a connection to the Discord Gateway.
void discord_set_on_channel_delete(struct discord *client, channel_cb callback)
Set a callback that triggers when a channel is deleted.
void discord_set_on_guild_ban_add(struct discord *client, guild_ban_cb callback)
Set a callback that triggers when a guild ban is added.
Search Guild Members.
Definition: guild.endpoints-params.h:361
Definition: discord.h:338
void discord_remove_intents(struct discord *client, enum discord_gateway_intents code)
Unsubscribe from Discord Gateway events.
void(* guild_role_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_permissions_role *role)
Guild Role Create/Update callback.
Definition: discord.h:100
@ EVENT_IS_HANDLED
this event has been handled
Definition: discord.h:645
Definition: discord-voice-connections.h:69
Message Reference Structure.
Definition: channel.h:259
uint64_t u64_unix_ms_t
unix time in ms
Definition: discord.h:26
int max_concurrency
the number of identify requests allowed per 5 seconds
Definition: discord.h:289
The Discord Client structure.
Definition: discord-internal.h:271
void discord_set_on_channel_create(struct discord *client, channel_cb callback)
Set a callback that triggers when a channel is created.
void(* guild_ban_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_user *user)
Guild Ban Add/Remove callback.
Definition: discord.h:144
Create Guild Emoji.
Definition: emoji.endpoints-params.h:17
uint64_t u64_snowflake_t
snowflake datatype
Definition: discord.h:32
Get Invite.
Definition: invite.endpoints-params.h:17
int concurrent
active concurrent sessions
Definition: discord.h:291
int remaining
the remaining number of session starts the current user is allowed
Definition: discord.h:287
void discord_set_prefix(struct discord *client, char *prefix)
Set a mandatory prefix before commands.
Create Channel Invite.
Definition: channel.endpoints-params.h:273
List Active Threads.
Definition: channel.endpoints-params.h:493
Message Structure.
Definition: channel.h:465
Create Group DM.
Definition: user.endpoints-params.h:67
void(* voice_server_update_cb)(struct discord *client, const struct discord_user *bot, const char *token, const u64_snowflake_t guild_id, const char *endpoint)
Voice Server Update callback.
Definition: discord.h:271
int event_count
event counter to avoid reaching limit of 120 events per 60 sec
Definition: discord.h:296
Start Thread without Message.
Definition: channel.endpoints-params.h:443
void(* message_reaction_add_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t user_id, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id, const struct discord_guild_member *member, const struct discord_emoji *emoji)
Message Reaction Add callback.
Definition: discord.h:216
Guild Member Structure.
Definition: guild.h:515
void(* guild_member_remove_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_user *user)
Guild Member Remove callback.
Definition: discord.h:132
Modify Guild Member.
Definition: guild.endpoints-params.h:473
Channel Structure.
Definition: channel.h:31
Modify Guild Emoji.
Definition: emoji.endpoints-params.h:71
Emoji Structure.
Definition: emoji.h:17
File containing internal functions and datatypes for Voice Connections.
void discord_set_on_guild_member_remove(struct discord *client, guild_member_remove_cb callback)
Set a callback that triggers when a guild member is removed.
Invite Structure.
Definition: invite.h:25
Start Thread with Message.
Definition: channel.endpoints-params.h:393
Create Guild Channel.
Definition: guild.endpoints-params.h:221
void discord_set_voice_cbs(struct discord *client, struct discord_voice_cbs *callbacks)
Helper to quickly set voice callbacks.
Add Guild Member.
Definition: guild.endpoints-params.h:411
Modify Guild Channel Positions.
Definition: guild.endpoints-params.h:303
void discord_set_on_channel_pins_update(struct discord *client, channel_pins_update_cb callback)
Set a callback that triggers when some channel pins are updated.
User Structure.
Definition: user.h:45
char * name
the name of the file being sent
Definition: discord.h:328
void(* message_reaction_remove_all_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id)
Message Reaction Remove All callback.
Definition: discord.h:241
@ EVENT_WILL_BE_HANDLED_IN_MAIN_THREAD
handle this event in main thread
Definition: discord.h:646
Definition: audit_log.endpoints-params.h:15
Definition: discord.h:302
void discord_set_on_channel_update(struct discord *client, channel_cb callback)
Set a callback that triggers when a channel is updated.
int limit
the number of members to return (1-1000)
Definition: discord.h:349
Create Guild.
Definition: guild.endpoints-params.h:17
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
void(* message_delete_bulk_cb)(struct discord *client, const struct discord_user *bot, const ja_u64 **ids, const u64_snowflake_t channel_id, const u64_snowflake_t guild_id)
Message Delete Bulk callback.
Definition: discord.h:182
Embed Structure.
Definition: channel.h:1082
void(* channel_pins_update_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const u64_snowflake_t channel_id, const u64_unix_ms_t last_pin_timestamp)
Channel Pins Update callback.
Definition: discord.h:205
void discord_set_on_event_raw(struct discord *client, event_raw_cb callback)
Set a callback that triggers on any event the client is subscribed to.
void discord_set_on_message_delete(struct discord *client, message_delete_cb callback)
Set a callback that triggers when a message is deleted.
Modify Guild.
Definition: guild.endpoints-params.h:103