From 3397754545525442b6ebe27dc474f2330ab6a120 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Thu, 18 Jun 2020 18:34:13 -0500 Subject: [PATCH] Add Role type to Member. --- src/member.nim | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/member.nim b/src/member.nim index 1629fc3..80fa40e 100644 --- a/src/member.nim +++ b/src/member.nim @@ -1,28 +1,32 @@ -import discordobject, user, json +import discordobject, user, json, role type GuildMember* = ref object of DiscordObject ## This type is a guild member. user*: User ## The user this guild member represents. nick*: string ## This users guild nickname. - #roles*: seq[Role] ## Array of roles. + roles*: seq[Role] ## Array of roles. joinedAt*: string ## When the user joined the guild. premiumSince*: string ## When the user started boosting the guild. deaf*: bool ## Whether the user is deafened in voice channels. mute*: bool ## Whether the user is muted in voice channels. -proc newGuildMember*(memberJson: JsonNode): GuildMember {.inline.} = +proc newGuildMember*(json: JsonNode): GuildMember {.inline.} = + ## Construct a GuildMember using json. var member = GuildMember( - nick: memberJson{"nick"}.getStr(), + nick: json{"nick"}.getStr(), #roles: seq[Role] - joinedAt: memberJson["joined_at"].getStr(), - premiumSince: memberJson{"premium_since"}.getStr(), - deaf: memberJson["deaf"].getBool(), - mute: memberJson["mute"].getBool() + joinedAt: json["joined_at"].getStr(), + premiumSince: json{"premium_since"}.getStr(), + deaf: json["deaf"].getBool(), + mute: json["mute"].getBool() ) - if (memberJson.contains("user")): - member.user = newUser(memberJson["user"]) + if (json.contains("user")): + member.user = newUser(json["user"]) + + for role in json: + member.roles.add(newRole(role)) return member \ No newline at end of file