Convert member.roles to seq[snowflake] from seq[Role]

This commit is contained in:
SeanOMik 2020-06-19 16:10:39 -05:00
parent 60569d6c87
commit 4d135a73c7
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
3 changed files with 8 additions and 14 deletions

View File

@ -194,7 +194,7 @@ proc newGuild*(json: JsonNode): Guild {.inline.} =
#TODO: voice_states
if (json.contains("members")):
for member in json["members"]:
g.members.insert(newGuildMember(member, g.roles, g.id))
g.members.insert(newGuildMember(member, g.id))
if (json.contains("channels")):
for channel in json["channels"]:
g.channels.insert(newChannel(channel))
@ -491,7 +491,7 @@ proc getGuildMember*(guild: var Guild, memberID: snowflake): GuildMember =
return member
result = newGuildMember(sendRequest(endpoint(fmt("/guilds/{guild.id}/members/{memberID}")),
HttpPatch, defaultHeaders(), guild.id, RateLimitBucketType.guild), guild.roles, guild.id)
HttpPatch, defaultHeaders(), guild.id, RateLimitBucketType.guild), guild.id)
guild.members.add(result)
# Would this endpoint be worth adding? https://discord.com/developers/docs/resources/guild#list-guild-members

View File

@ -4,14 +4,14 @@ 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[snowflake] ## 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.
guildID*: snowflake ## The guild this member is in.
proc newGuildMember*(json: JsonNode, guildRoles: seq[Role], guild: snowflake): GuildMember {.inline.} =
proc newGuildMember*(json: JsonNode, guild: snowflake): GuildMember {.inline.} =
## Construct a GuildMember using json.
result = GuildMember(
nick: json{"nick"}.getStr(),
@ -27,15 +27,9 @@ proc newGuildMember*(json: JsonNode, guildRoles: seq[Role], guild: snowflake): G
result.user = newUser(json["user"])
# Add roles
if (json.contains("roles") and guildRoles.len > 0):
var roleIDs: seq[snowflake]
for role in json["roles"]:
roleIDs.add(getIDFromJson(role.getStr()))
for role in guildRoles:
if (roleIDs.contains(role.id)):
result.roles.add(role)
for role in json["roles"]:
result.roles.add(getIDFromJson(role.getStr()))
type GuildMemberModify* = ref object
nick: Option[string]
roles: Option[seq[snowflake]]

View File

@ -94,7 +94,7 @@ proc newMessage*(messageJson: JsonNode): Message =
if (messageJson.contains("author")):
msg.author = newUser(messageJson["author"])
if (messageJson.contains("member")):
msg.member = newGuildMember(messageJson["member"], @[], msg.guildID)
msg.member = newGuildMember(messageJson["member"], msg.guildID)
if (messageJson.contains("mentions")):
let mentionsJson = messageJson["mentions"].getElems()