Add Role type to Member.
This commit is contained in:
parent
c8810604ac
commit
3397754545
|
@ -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
|
||||
|
Reference in New Issue