Browse Source

Implemented permission_overwrites and recipients fields

master
Alexander Memer 1 year ago
parent
commit
9e5fe3104c
2 changed files with 67 additions and 15 deletions
  1. 21
    13
      include/discord.h
  2. 46
    2
      lib/rest.c

+ 21
- 13
include/discord.h View File

@@ -90,6 +90,25 @@ enum {
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;
@@ -97,12 +116,12 @@ typedef struct guild_channel {
int type;
int position;
bool nsfw;
// TODO: permission_overwrites
overwrite_t *permission_overwrites;
char *topic;
char *last_message_id;
int bitrate;
int user_limit;
// TODO: recipients
user_t *recipients;
char *icon;
char *owner_id;
char *application_id;
@@ -170,17 +189,6 @@ typedef struct embed {
field_t fields;
} embed_t;

typedef struct user {
char* id;
char* username;
char* discriminator;
char* avatar;
int bot;
int mfa_enabled;
int verified;
char* email;
} user_t;

typedef struct dm_channel {
char *id;
int is_private;

+ 46
- 2
lib/rest.c View File

@@ -248,7 +248,26 @@ int ld_get_channel(struct ld_context *ctx, char *channel_id, guild_channel_t *ch
channel->guild_id = strdup(json_string_value(guild_id));
json_decref(guild_id);

// TODO: permission_overwrites
json_t *permission_overwrites = json_object_get(res, "permission_overwrites");
size_t osize = json_array_size(permission_overwrites);

channel->permission_overwrites = calloc(osize, sizeof(overwrite_t));

size_t index;
json_t *value;

json_array_foreach(permission_overwrites, index, value)
{
overwrite_t temp;

temp.id = (char*)json_string_value(json_object_get(value, "id"));
temp.type = (char*)json_string_value(json_object_get(value, "type"));
temp.deny = (int)json_integer_value(json_object_get(value, "deny"));
temp.allow = (int)json_integer_value(json_object_get(value, "allow"));
channel->permission_overwrites[index] = temp;
}

json_decref(permission_overwrites);

json_t *name = json_object_get(res, "name");
channel->name = strdup(json_string_value(name));
@@ -298,7 +317,32 @@ int ld_get_channel(struct ld_context *ctx, char *channel_id, guild_channel_t *ch
}
else if (channel->type == DM || channel->type == GROUP_DM)
{
// TODO: recipients

json_t *recipients = json_object_get(res, "recipients");
size_t rsize = json_array_size(recipients);

channel->recipients = calloc(rsize, sizeof(user_t));

size_t index;
json_t *value;

json_array_foreach(recipients, index, value)
{
user_t temp;
// TODO: Create function for converting json user objects to structs
temp.id = (char*)json_string_value(json_object_get(value, "id"));
temp.username = (char*)json_string_value(json_object_get(value, "username"));
temp.discriminator = (char*)json_string_value(json_object_get(value, "discriminator"));
json_t *avatar = json_object_get(value, "avatar");
if (avatar)
{
temp.avatar = (char*)json_string_value(avatar);
json_decref(avatar);
}

channel->recipients[index] = temp;
}

json_t *icon = json_object_get(res, "icon");
if (icon)
{

Loading…
Cancel
Save