Make sure a presence update payload is valid

This commit is contained in:
SeanOMik 2020-08-30 22:41:22 -05:00
parent 2ff89d9e18
commit 611ac34389
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
1 changed files with 12 additions and 11 deletions

View File

@ -410,20 +410,21 @@ proc messageReactionRemoveEmoji(shard: Shard, json: JsonNode) =
proc presenceUpdate(shard: Shard, json: JsonNode) =
# This proc doesn't actually dispatch any events,
# it just updates member.presence
var g = shard.client.cache.getGuild(getIDFromJson(json["guild_id"].getStr()))
var member = g.getGuildMember(getIDFromJson(json["user"]["id"].getStr()))
if json.contains("guild_id"): # Make sure that json contains a guild_id
var g = shard.client.cache.getGuild(getIDFromJson(json["guild_id"].getStr()))
var member = g.getGuildMember(getIDFromJson(json["user"]["id"].getStr()))
# Make sure some member fields are upto date.
member.roles = @[]
for role in json["roles"]:
member.roles.add(getIDFromJson(role.getStr()))
# Make sure some member fields are upto date.
member.roles = @[]
for role in json["roles"]:
member.roles.add(getIDFromJson(role.getStr()))
if json.contains("premium_since"):
member.premiumSince = json["premium_since"].getStr()
if json.contains("nick"):
member.nick = json["nick"].getStr()
if json.contains("premium_since"):
member.premiumSince = json["premium_since"].getStr()
if json.contains("nick"):
member.nick = json["nick"].getStr()
member.presence = newPresence(json)
member.presence = newPresence(json)
proc typingStart(shard: Shard, json: JsonNode) =
var event = TypingStartEvent(shard: shard, name: $EventType.evtTypingStart)