// // Created by Memer on 24.08.18. // #ifndef _DISCORD_H #define _DISCORD_H #include #include #include #define LD_API_ENDPOINT "https://discordapp.com/api" enum { LD_REST_UNAUTHORIZED = 401, LD_REST_BAD_REQUEST = 400, LD_REST_FORBIDDEN = 403, LD_REST_NOT_FOUND = 404, LD_REST_METHOD_NOT_ALLOWED = 405, LD_REST_TOO_MANY_REQUESTS = 429, LD_REST_GATEWAY_UNAVAILABLE = 502, LD_REST_SERVER_ERROR = 500, LD_REST_UNKNOWN = 1 }; struct ld_context { // TODO: Websocket stuff char *bot_token; char *session_id; bool hello_triggered; int heartbeat_interval; int heartbeat_acks; int sequence; struct ld_rest_error *last_rest_status; CURL *curl_handle; // ld_user_t self; }; struct ld_context_info { char *bot_token; int log_level; }; struct ld_gateway_bot_resp { char *url; int shards; }; struct ld_rest_error { int what; char *text; }; enum game_types { GAME = 0, STREAMING = 1 }; enum channel_types { GUILD_TEXT, DM, GUILD_VOICE, GROUP_DM, GUILD_CATEGORY }; enum { DISPATCH, HEARTBEAT, IDENTIFY, PRESENCE, VOICE_STATE, VOICE_PING, RESUME, RECONNECT, REQUEST_MEMBERS, INVALIDATE_SESSION, HELLO, HEARTBEAT_ACK }; typedef struct user { char* id; char* username; char* discriminator; char* avatar; int bot; int mfa_enabled; int verified; char* email; } user_t; typedef struct overwrite { char *id; char *type; int deny; int allow; } overwrite_t; typedef struct guild_channel { char *id; char *guild_id; char *name; int type; int position; bool nsfw; overwrite_t *permission_overwrites; char *topic; char *last_message_id; int bitrate; int user_limit; user_t *recipients; char *icon; char *owner_id; char *application_id; char *parent_id; char *last_pin_timestamp; } guild_channel_t; typedef struct thumbnail { char* url; char* proxy_url; int height; int width; } thumbnail_t; typedef struct video { char* url; int height; int width; } video_t; typedef struct image { char* url; char* proxy_url; int height; int width; } image_t; typedef struct provider { char* name; char* url; } provider_t; typedef struct author { char* name; char* url; char* icon_url; char* proxy_icon_url; } author_t; typedef struct footer { char* text; char* icon_url; char* proxy_icon_url; } footer_t; typedef struct field { char* name; char* value; int _inline; } field_t; typedef struct embed { char* title; char* type; char* description; char* url; char* timestamp; int color; footer_t footer; image_t image; thumbnail_t thumbnail; video_t video; provider_t provider; author_t author; field_t fields; } embed_t; typedef struct dm_channel { char *id; int is_private; user_t recipient; char *last_message_id; } dm_channel_t; typedef struct game { char *name; int type; char *url; // Only if type is STREAMING (1) } game_t; typedef struct presence_update { user_t user; // Can be partial game_t game; // May be null char *guild_id; char *status; char *roles[200]; } presence_update_t; typedef struct emoji { char* id; char* name; } emoji_t; typedef struct reaction { int counter; int me; emoji_t _emoji; } reaction_t; typedef struct message { char* id; char* channel_id; user_t author; char* content; char* timestamp; char* edited_timestamp; int tts; int mention_everyone; user_t mentions[1024]; /* TODO: mention_roles attachments embeds nonce */ embed_t embeds[1024]; reaction_t reactions[1024]; int pinned; char* webhook_id; } message_t; struct ld_modify_channel_obj { char *name; int position; char *topic; int nsfw; int bitrate; int user_limit; overwrite_t *permission_overwrites; size_t overwrites_size; char *parent_id; }; struct ld_context *ld_create_context(struct ld_context_info *info); char *ld_get_gateway(struct ld_context *ctx); struct ld_gateway_bot_resp *ld_get_gateway_bot(struct ld_context *ctx); int ld_create_message(struct ld_context *ctx, char *channel_id, char *content); int ld_get_channel(struct ld_context *ctx, char *channel_id, guild_channel_t *target); int ld_modify_channel_result(struct ld_context *ctx, char *channel_id, struct ld_modify_channel_obj *modify, guild_channel_t *result); int ld_modify_channel(struct ld_context *ctx, char *channel_id, struct ld_modify_channel_obj *modify); int ld_delete_channel(struct ld_context *ctx, char *channel_id); void ld_channel_obj_to_type(json_t *src, guild_channel_t *channel); #endif // _DISCORD_H