Convert member.roles to seq[snowflake] from seq[Role]
This commit is contained in:
parent
60569d6c87
commit
4d135a73c7
|
@ -194,7 +194,7 @@ proc newGuild*(json: JsonNode): Guild {.inline.} =
|
||||||
#TODO: voice_states
|
#TODO: voice_states
|
||||||
if (json.contains("members")):
|
if (json.contains("members")):
|
||||||
for member in json["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")):
|
if (json.contains("channels")):
|
||||||
for channel in json["channels"]:
|
for channel in json["channels"]:
|
||||||
g.channels.insert(newChannel(channel))
|
g.channels.insert(newChannel(channel))
|
||||||
|
@ -491,7 +491,7 @@ proc getGuildMember*(guild: var Guild, memberID: snowflake): GuildMember =
|
||||||
return member
|
return member
|
||||||
|
|
||||||
result = newGuildMember(sendRequest(endpoint(fmt("/guilds/{guild.id}/members/{memberID}")),
|
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)
|
guild.members.add(result)
|
||||||
|
|
||||||
# Would this endpoint be worth adding? https://discord.com/developers/docs/resources/guild#list-guild-members
|
# Would this endpoint be worth adding? https://discord.com/developers/docs/resources/guild#list-guild-members
|
||||||
|
|
|
@ -4,14 +4,14 @@ 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[snowflake] ## 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.
|
||||||
guildID*: snowflake ## The guild this member is in.
|
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.
|
## Construct a GuildMember using json.
|
||||||
result = GuildMember(
|
result = GuildMember(
|
||||||
nick: json{"nick"}.getStr(),
|
nick: json{"nick"}.getStr(),
|
||||||
|
@ -27,14 +27,8 @@ proc newGuildMember*(json: JsonNode, guildRoles: seq[Role], guild: snowflake): G
|
||||||
result.user = newUser(json["user"])
|
result.user = newUser(json["user"])
|
||||||
|
|
||||||
# Add roles
|
# Add roles
|
||||||
if (json.contains("roles") and guildRoles.len > 0):
|
for role in json["roles"]:
|
||||||
var roleIDs: seq[snowflake]
|
result.roles.add(getIDFromJson(role.getStr()))
|
||||||
for role in json["roles"]:
|
|
||||||
roleIDs.add(getIDFromJson(role.getStr()))
|
|
||||||
|
|
||||||
for role in guildRoles:
|
|
||||||
if (roleIDs.contains(role.id)):
|
|
||||||
result.roles.add(role)
|
|
||||||
|
|
||||||
type GuildMemberModify* = ref object
|
type GuildMemberModify* = ref object
|
||||||
nick: Option[string]
|
nick: Option[string]
|
||||||
|
|
|
@ -94,7 +94,7 @@ proc newMessage*(messageJson: JsonNode): Message =
|
||||||
if (messageJson.contains("author")):
|
if (messageJson.contains("author")):
|
||||||
msg.author = newUser(messageJson["author"])
|
msg.author = newUser(messageJson["author"])
|
||||||
if (messageJson.contains("member")):
|
if (messageJson.contains("member")):
|
||||||
msg.member = newGuildMember(messageJson["member"], @[], msg.guildID)
|
msg.member = newGuildMember(messageJson["member"], msg.guildID)
|
||||||
|
|
||||||
if (messageJson.contains("mentions")):
|
if (messageJson.contains("mentions")):
|
||||||
let mentionsJson = messageJson["mentions"].getElems()
|
let mentionsJson = messageJson["mentions"].getElems()
|
||||||
|
|
Reference in New Issue