Orca
A bot framework that is easy to reason about, easy to debug, and easy to use.
Classes | Macros | Functions
discord-internal.h File Reference

File containing internal functions and datatypes. More...

#include <inttypes.h>
#include <pthread.h>
#include "uthash.h"
#include "json-scanf.h"
#include "json-actor.h"
#include "json-actor-boxed.h"
#include "logconf.h"
#include "user-agent.h"
#include "websockets.h"
#include "cee-utils.h"
#include "discord-voice-connections.h"
Include dependency graph for discord-internal.h:

Go to the source code of this file.

Classes

struct  discord_adapter
 The handle used for performing HTTP Requests. More...
 
struct  discord_bucket
 The bucket struct that will handle ratelimiting. More...
 
struct  discord_gateway_cmd_cbs
 
struct  discord_gateway
 The handle used for establishing a Discord Gateway connection via WebSockets. More...
 
struct  discord
 The Discord Client structure. More...
 
struct  discord_event_cxt
 

Macros

#define NUM_VCS   512
 

Functions

void discord_adapter_init (struct discord_adapter *adapter, struct logconf *config, struct sized_buffer *token)
 Initialize the fields of a Discord Adapter handle. More...
 
void discord_adapter_cleanup (struct discord_adapter *adapter)
 Free a Discord Adapter handle. More...
 
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. More...
 
void discord_buckets_cleanup (struct discord_adapter *adapter)
 Free client buckets. More...
 
void discord_bucket_try_cooldown (struct discord_bucket *bucket)
 Check bucket for ratelimit cooldown. More...
 
struct discord_bucketdiscord_bucket_try_get (struct discord_adapter *adapter, const char route[])
 Get existing bucket with route. More...
 
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. More...
 
void discord_gateway_init (struct discord_gateway *gw, struct logconf *config, struct sized_buffer *token)
 Initialize the fields of Discord Gateway handle. More...
 
void discord_gateway_cleanup (struct discord_gateway *gw)
 Free a Discord Gateway handle. More...
 
void discord_gateway_run (struct discord_gateway *gw)
 Start a Discord connection over WebSockets. More...
 
void discord_gateway_shutdown (struct discord_gateway *gw)
 Gracefully exits a ongoing Discord connection over WebSockets. More...
 
void discord_gateway_reconnect (struct discord_gateway *gw, bool resume)
 Gracefully reconnect a ongoing Discord connection over WebSockets. More...
 

Detailed Description

File containing internal functions and datatypes.

Author
cee-studio
Date
18 Jun 2021

Function Documentation

◆ discord_adapter_cleanup()

void discord_adapter_cleanup ( struct discord_adapter adapter)

Free a Discord Adapter handle.

Parameters
adaptera pointer to the adapter handle

◆ discord_adapter_init()

void discord_adapter_init ( struct discord_adapter adapter,
struct logconf *  config,
struct sized_buffer *  token 
)

Initialize the fields of a Discord Adapter handle.

Parameters
adaptera pointer to the allocated handle
configoptional pointer to a pre-initialized logconf
tokenthe bot token
See also
logconf.h

◆ discord_adapter_run()

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.

Parameters
adapterthe handle initialized with discord_adapter_init()
resp_handlethe callbacks that will be triggered should the request fail or succeed
req_bodythe body sent for methods that require (ex: POST), leave as NULL if unecessary
http_methodthe method in opcode format of the request being sent
endpointthe format endpoint that be appended to base_url when performing a request, same behavior as printf()
Returns
a code for checking on how the transfer went ORCA_OK means the transfer was succesful
Note
Helper over ua_run()
See also
user-agent.h

◆ discord_bucket_build()

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.

Parameters
adapterthe handle created with discord_adapter_init()
bucketNULL when bucket is first discovered
routethe route associated with the bucket
infoinformation struct regarding the current transfer
Note
If the bucket was just discovered it will be created here.

◆ discord_bucket_try_cooldown()

void discord_bucket_try_cooldown ( struct discord_bucket bucket)

Check bucket for ratelimit cooldown.

Check if connections from a bucket hit its threshold, and lock every connection associated with the bucket until cooldown time elapses

Parameters
bucketcheck if a cooldown is necessary

◆ discord_bucket_try_get()

struct discord_bucket* discord_bucket_try_get ( struct discord_adapter adapter,
const char  route[] 
)

Get existing bucket with route.

Check if bucket associated with route has already been discovered

Parameters
adapterthe handle created with discord_adapter_init()
routethat will be checked for a bucket match
Returns
bucket associated with route or NULL if no match found

◆ discord_buckets_cleanup()

void discord_buckets_cleanup ( struct discord_adapter adapter)

Free client buckets.

Parameters
adapterthe client adapter containinig every bucket found

◆ discord_gateway_cleanup()

void discord_gateway_cleanup ( struct discord_gateway gw)

Free a Discord Gateway handle.

Parameters
gwa pointer to the gateway handle

◆ discord_gateway_init()

void discord_gateway_init ( struct discord_gateway gw,
struct logconf *  config,
struct sized_buffer *  token 
)

Initialize the fields of Discord Gateway handle.

Parameters
gwa pointer to the allocated handle
configoptional pointer to a initialized logconf
tokenthe bot token
See also
logconf.h

◆ discord_gateway_reconnect()

void discord_gateway_reconnect ( struct discord_gateway gw,
bool  resume 
)

Gracefully reconnect a ongoing Discord connection over WebSockets.

Parameters
gwthe handle initialized with discord_gateway_init()
resumetrue to attempt to resume to previous session, false restart a fresh session
See also
websockets.h

◆ discord_gateway_run()

void discord_gateway_run ( struct discord_gateway gw)

Start a Discord connection over WebSockets.

Parameters
gwthe handle initialized with discord_gateway_init()
See also
websockets.h

◆ discord_gateway_shutdown()

void discord_gateway_shutdown ( struct discord_gateway gw)

Gracefully exits a ongoing Discord connection over WebSockets.

Parameters
gwthe handle initialized with discord_gateway_init()
See also
websockets.h