Add Role type to Member.

This commit is contained in:
SeanOMik 2020-06-18 18:34:13 -05:00
parent c8810604ac
commit 3397754545
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
1 changed files with 14 additions and 10 deletions

View File

@ -1,28 +1,32 @@
import discordobject, user, json import discordobject, user, json, role
type GuildMember* = ref object of DiscordObject type GuildMember* = ref object of DiscordObject
## This type is a guild member. ## This type is a guild member.
user*: User ## The user this guild member represents. user*: User ## The user this guild member represents.
nick*: string ## This users guild nickname. 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. joinedAt*: string ## When the user joined the guild.
premiumSince*: string ## When the user started boosting the guild. premiumSince*: string ## When the user started boosting the guild.
deaf*: bool ## Whether the user is deafened in voice channels. deaf*: bool ## Whether the user is deafened in voice channels.
mute*: bool ## Whether the user is muted 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( var member = GuildMember(
nick: memberJson{"nick"}.getStr(), nick: json{"nick"}.getStr(),
#roles: seq[Role] #roles: seq[Role]
joinedAt: memberJson["joined_at"].getStr(), joinedAt: json["joined_at"].getStr(),
premiumSince: memberJson{"premium_since"}.getStr(), premiumSince: json{"premium_since"}.getStr(),
deaf: memberJson["deaf"].getBool(), deaf: json["deaf"].getBool(),
mute: memberJson["mute"].getBool() mute: json["mute"].getBool()
) )
if (memberJson.contains("user")): if (json.contains("user")):
member.user = newUser(memberJson["user"]) member.user = newUser(json["user"])
for role in json:
member.roles.add(newRole(role))
return member return member