Dont shadow json module in message constructor also.

This commit is contained in:
SeanOMik 2020-05-31 01:15:16 -05:00
parent ec8e41fa84
commit 55b10c0593
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
1 changed files with 35 additions and 36 deletions

View File

@ -63,55 +63,54 @@ type
messageReference*: MessageReference messageReference*: MessageReference
flags*: int flags*: int
proc newMessage*(json: json.JsonNode): Message = proc newMessage*(messageJson: JsonNode): Message =
var msg = Message( var msg = Message(
id: getIDFromJson(json["id"].getStr()), id: getIDFromJson(messageJson["id"].getStr()),
channelID: snowflake(json["channel_id"].getBiggestInt()), channelID: snowflake(messageJson["channel_id"].getBiggestInt()),
guildID: snowflake(json{"guild_id"}.getBiggestInt()), guildID: snowflake(messageJson{"guild_id"}.getBiggestInt()),
content: json["content"].getStr(), content: messageJson["content"].getStr(),
timestamp: json["timestamp"].getStr(), timestamp: messageJson["timestamp"].getStr(),
editedTimestamp: json{"edited_timestamp"}.getStr(), editedTimestamp: messageJson{"edited_timestamp"}.getStr(),
tts: json["tts"].getBool(), tts: messageJson["tts"].getBool(),
mentionEveryone: json["mention_everyone"].getBool(), mentionEveryone: messageJson["mention_everyone"].getBool(),
#mentionRoles #mentionRoles
#mentionChannels #mentionChannels?
#attachments #attachments
#embeds #embeds
#reactions #reactions?
pinned: json["pinned"].getBool(), pinned: messageJson["pinned"].getBool(),
webhookID: snowflake(json{"webhook_id"}.getBiggestInt()), webhookID: snowflake(messageJson{"webhook_id"}.getBiggestInt()),
`type`: MessageType(json["type"].getInt()), `type`: MessageType(messageJson["type"].getInt()),
flags: json{"flags"}.getInt() flags: messageJson{"flags"}.getInt()
) )
if (json.contains("author")): if (messageJson.contains("author")):
msg.author = newUser(json["author"]) msg.author = newUser(messageJson["author"])
if (json.contains("member")): if (messageJson.contains("member")):
msg.member = newGuildMember(json["member"]) msg.member = newGuildMember(messageJson["member"])
if (json.contains("mentions")): if (messageJson.contains("mentions")):
var userArray: seq[JsonNode] let mentionsJson = messageJson["mentions"].getElems()
json.getElems(json["mentions"], userArray)
for index, userJson in userArray.pairs: for userJson in mentionsJson.items:
msg.mentions.add(newUser(userJson)) msg.mentions.add(newUser(userJson))
if (json.contains("activity")): if (messageJson.contains("activity")):
msg.activity = MessageActivity(`type`: MessageActivityType(json["activity"]["type"].getInt()), msg.activity = MessageActivity(`type`: MessageActivityType(messageJson["activity"]["type"].getInt()),
partyID: json["activity"]["party_id"].getStr()) partyID: messageJson["activity"]["party_id"].getStr())
if (json.contains("application")): if (messageJson.contains("application")):
msg.application = MessageApplication( msg.application = MessageApplication(
id: getIDFromJson(json["application"]["id"].getStr()), id: getIDFromJson(messageJson["application"]["id"].getStr()),
coverImage: json["application"]{"cover_image"}.getStr(), coverImage: messageJson["application"]{"cover_image"}.getStr(),
description: json["application"]["description"].getStr(), description: messageJson["application"]["description"].getStr(),
icon: json["application"]{"icon"}.getStr(), icon: messageJson["application"]{"icon"}.getStr(),
name: json["application"]["name"].getStr() name: messageJson["application"]["name"].getStr()
) )
if (json.contains("message_reference")): if (messageJson.contains("message_reference")):
msg.messageReference = MessageReference( msg.messageReference = MessageReference(
messageID: getIDFromJson(json["message_reference"]{"message_id"}.getStr()), messageID: getIDFromJson(messageJson["message_reference"]{"message_id"}.getStr()),
channelID: getIDFromJson(json["message_reference"]["channel_id"].getStr()), channelID: getIDFromJson(messageJson["message_reference"]["channel_id"].getStr()),
guildID: getIDFromJson(json["message_reference"]{"guild_id"}.getStr()), guildID: getIDFromJson(messageJson["message_reference"]{"guild_id"}.getStr()),
) )
return msg return msg