123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- //
- // Created by Memer on 24.08.18.
- //
-
- #ifndef _DISCORD_H
- #define _DISCORD_H
-
- #include <stdbool.h>
-
- #include <curl/curl.h>
- #include <jansson.h>
-
- #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
|