Orca
A bot framework that is easy to reason about, easy to debug, and easy to use.
|
Go to the documentation of this file.
8 #ifndef DISCORD_INTERNAL_H
9 #define DISCORD_INTERNAL_H
15 #include "json-scanf.h"
16 #include "json-actor.h"
17 #include "json-actor-boxed.h"
20 #include "user-agent.h"
22 #include "cee-utils.h"
32 struct user_agent *
ua;
72 struct sized_buffer *req_body,
73 enum http_method http_method,
74 char endpoint[], ...);
146 struct websockets *
ws;
214 pthread_mutex_t lock;
290 enum discord_gateway_events event;
293 struct sized_buffer *
data);
297 #endif // DISCORD_INTERNAL_H
channel_pins_update_cb on_channel_pins_update
triggers when a channel pinned messages updates
Definition: discord-internal.h:195
message_cb on_message_create
triggers when a message is created
Definition: discord-internal.h:196
guild_member_remove_cb on_guild_member_remove
triggers when a guild member is removed from a guild
Definition: discord-internal.h:188
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
guild_member_cb on_guild_member_update
triggers when a guild member status is updated (ex: receive role)
Definition: discord-internal.h:189
void * data
space for user arbitrary data
Definition: discord-internal.h:282
void discord_bucket_try_cooldown(struct discord_bucket *bucket)
Check bucket for ratelimit cooldown.
struct discord_user * bot
the bot user structure
Definition: discord-internal.h:216
u64_unix_ms_t reset_tstamp
timestamp of when cooldown timer resets
Definition: discord-internal.h:87
struct sized_buffer sb_bot
Definition: discord-internal.h:217
int remaining
connections this bucket can do before waiting for cooldown
Definition: discord-internal.h:85
The bucket struct that will handle ratelimiting.
Definition: discord-internal.h:81
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
Definition: user-agent.h:49
Definition: user-agent.h:101
struct discord_bucket * buckets
Endpoint/routes discovered, check a endpoint/bucket match with tree search functions.
Definition: discord-internal.h:34
char session_id[512]
the session id (for resuming lost connections)
Definition: discord-internal.h:157
void(* idle_cb)(struct discord *client, const struct discord_user *bot)
Idle callback.
Definition: discord.h:78
void discord_adapter_cleanup(struct discord_adapter *adapter)
Free a Discord Adapter handle.
void discord_adapter_init(struct discord_adapter *adapter, struct logconf *config, struct sized_buffer *token)
Initialize the fields of a Discord Adapter handle.
void discord_buckets_cleanup(struct discord_adapter *adapter)
Free client buckets.
struct discord_gateway * p_gw
the gateway client
Definition: discord-internal.h:289
Definition: discord.h:282
channel_cb on_channel_delete
triggers when a channel is deleted
Definition: discord-internal.h:194
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
Definition: discord-internal.h:285
void discord_gateway_reconnect(struct discord_gateway *gw, bool resume)
Gracefully reconnect a ongoing Discord connection over WebSockets.
message_reaction_add_cb on_message_reaction_add
triggers when a reaction is added to a message
Definition: discord-internal.h:202
message_reaction_remove_cb on_message_reaction_remove
triggers when a reaction is removed from a message
Definition: discord-internal.h:203
The handle used for establishing a Discord Gateway connection via WebSockets.
Definition: discord-internal.h:145
ORCAcode discord_adapter_run(struct discord_adapter *adapter, struct ua_resp_handle *resp_handle, struct sized_buffer *req_body, enum http_method http_method, char endpoint[],...)
Start a HTTP Request to Discord.
guild_role_delete_cb on_guild_role_delete
triggers when a guild role is deleted
Definition: discord-internal.h:186
struct discord_session session
on-going Discord Gateway session
Definition: discord-internal.h:174
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_gateway_init(struct discord_gateway *gw, struct logconf *config, struct sized_buffer *token)
Initialize the fields of Discord Gateway handle.
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
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
struct websockets * ws
the websockets handle that connects to Discord
Definition: discord-internal.h:146
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
The handle used for performing HTTP Requests.
Definition: discord-internal.h:31
Definition: discord-internal.h:132
idle_cb on_idle
triggers on every event loop iteration
Definition: discord-internal.h:181
sb_message_cb sb_on_message_create
Definition: discord-internal.h:197
u64_unix_ms_t interval_ms
fixed interval between heartbeats
Definition: discord-internal.h:170
void discord_gateway_run(struct discord_gateway *gw)
Start a Discord connection over WebSockets.
void(* message_cb)(struct discord *client, const struct discord_user *bot, const struct discord_message *message)
Message Create/Update callback.
Definition: discord.h:156
int seq_number
field 's'
Definition: discord-internal.h:162
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
char route[256]
this bucket 'key'
Definition: discord-internal.h:82
void discord_gateway_cleanup(struct discord_gateway *gw)
Free a Discord Gateway handle.
int ping_ms
latency between client and websockets server, calculated by the interval between HEARTBEAT and HEARTB...
Definition: discord-internal.h:212
message_cb on_message_update
trigger when a message is updated
Definition: discord-internal.h:198
pthread_mutex_t lock
Mutex used when adding to or searching for buckets.
Definition: discord-internal.h:35
discord_event_handling_mode
Definition: discord.h:644
struct discord_bucket * discord_bucket_try_get(struct discord_adapter *adapter, const char route[])
Get existing bucket with route.
guild_member_cb on_guild_member_add
triggers when a guild member joins a guild
Definition: discord-internal.h:187
struct sized_buffer event_data
field 'd'
Definition: discord-internal.h:164
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
Definition: discord-voice-connections.h:69
char event_name[64]
field 't'
Definition: discord-internal.h:163
char hash[128]
the unique hash associated with this bucket
Definition: discord-internal.h:83
struct discord * p_client
pointer to client this struct is part of
Definition: discord-internal.h:219
message_delete_bulk_cb on_message_delete_bulk
triggers when a bulk of messages is deleted
Definition: discord-internal.h:201
uint64_t u64_unix_ms_t
unix time in ms
Definition: discord.h:26
The Discord Client structure.
Definition: discord-internal.h:271
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
message_reaction_remove_emoji_cb on_message_reaction_remove_emoji
triggers when all occurences of a specific reaction is removed from a message
Definition: discord-internal.h:205
UT_hash_handle hh
makes this structure hashable
Definition: discord-internal.h:92
voice_server_update_cb on_voice_server_update
triggers when a voice server is updated
Definition: discord-internal.h:207
bool is_ready
can start sending/receiving additional events to discord
Definition: discord-internal.h:153
struct discord_adapter adapter
the HTTP adapter for performing requests
Definition: discord-internal.h:273
sb_message_cb sb_on_message_update
Definition: discord-internal.h:199
Discord Voice Connection handle, contain information about its active session.
Definition: discord-voice-connections.h:88
guild_ban_cb on_guild_ban_remove
triggers when a ban is removed
Definition: discord-internal.h:191
event_raw_cb on_event_raw
triggers for every event if set, receive its raw JSON string
Definition: discord-internal.h:182
int64_t reset_after_ms
how long until cooldown timer resets
Definition: discord-internal.h:86
struct discord_gateway gw
the WebSockets handle for establishing a connection to Discord
Definition: discord-internal.h:274
u64_unix_ms_t update_tstamp
timestamp of the most recent request
Definition: discord-internal.h:88
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
pthread_mutex_t lock
synchronize buckets between threads
Definition: discord-internal.h:90
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
message_delete_cb on_message_delete
triggers when a message is deleted
Definition: discord-internal.h:200
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
int threshold
max amount of reconnects before giving up
Definition: discord-internal.h:150
channel_cb on_channel_update
triggers when a channel is updated
Definition: discord-internal.h:193
guild_role_cb on_guild_role_create
triggers when a guild role is created
Definition: discord-internal.h:184
pthread_t tid
the thread id
Definition: discord-internal.h:287
int busy
amount of busy connections that have not yet finished its requests
Definition: discord-internal.h:84
u64_unix_ms_t tstamp
start pulse timestamp in milliseconds
Definition: discord-internal.h:171
guild_ban_cb on_guild_ban_add
triggers when a ban occurs
Definition: discord-internal.h:190
File containing internal functions and datatypes for Voice Connections.
bool enable
will attempt reconnecting if true
Definition: discord-internal.h:148
guild_role_cb on_guild_role_update
triggers when a guild role is updated
Definition: discord-internal.h:185
struct discord_gateway_identify * id
this info sent expecting a connection authentication
Definition: discord-internal.h:156
File containing internal functions and datatypes for WebSockets client.
struct sized_buffer prefix
the prefix expected before every command
Definition: discord-internal.h:176
enum discord_gateway_opcodes opcode
field 'op'
Definition: discord-internal.h:161
User Structure.
Definition: user.h:45
int attempt
current reconnect attempt (resets to 0 when succesful)
Definition: discord-internal.h:149
message_reaction_remove_all_cb on_message_reaction_remove_all
triggers when all reactions are removed from a message
Definition: discord-internal.h:204
channel_cb on_channel_create
triggers when a channel is created
Definition: discord-internal.h:192
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
idle_cb on_ready
triggers when connection first establishes
Definition: discord-internal.h:183
Identify Structure.
Definition: gateway.h:120
struct user_agent * ua
The user agent handle for performing requests.
Definition: discord-internal.h:32
struct logconf config
store bot.config file contents and sync logging between adapter/gw
Definition: discord-internal.h:276
struct discord * p_client
pointer to client this struct is part of
Definition: discord-internal.h:37
bool is_resumable
will attempt to resume session if connection shutsdowns
Definition: discord-internal.h:152
struct sized_buffer data
a copy of payload data
Definition: discord-internal.h:288
void discord_bucket_build(struct discord_adapter *adapter, struct discord_bucket *bucket, const char route[], struct ua_info *info)
Update the bucket with response header data.
struct discord_gateway_cmd_cbs on_default_cmd * on_cmd
user's command/callback pair and amount of callback pairs
Definition: discord-internal.h:177
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
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
bool shutdown
if true shutdown websockets connection as soon as possible
Definition: discord-internal.h:154
voice_state_update_cb on_voice_state_update
triggers when a voice state is updated
Definition: discord-internal.h:206
void discord_gateway_shutdown(struct discord_gateway *gw)
Gracefully exits a ongoing Discord connection over WebSockets.