Parse more json fields in message constructor.
This commit is contained in:
parent
91f848208a
commit
b29e282300
|
@ -1,4 +1,4 @@
|
||||||
import json, discordobject, nimcordutils, user, member, httpcore, asyncdispatch, emoji, options
|
import json, discordobject, nimcordutils, user, member, httpcore, asyncdispatch, emoji, options, embed, role, emoji
|
||||||
|
|
||||||
type
|
type
|
||||||
MessageType* = enum
|
MessageType* = enum
|
||||||
|
@ -46,6 +46,27 @@ type
|
||||||
msgFlagSourceMsgDeleted = 3,
|
msgFlagSourceMsgDeleted = 3,
|
||||||
msgFlagUrgent = 4
|
msgFlagUrgent = 4
|
||||||
|
|
||||||
|
Reaction* = ref object
|
||||||
|
count*: uint
|
||||||
|
me*: bool ## Whether the current user has reacted using this emoji.
|
||||||
|
emoji*: Emoji
|
||||||
|
|
||||||
|
ChannelMention* = ref object
|
||||||
|
## Represents a channel mention inside of a message.
|
||||||
|
channelID*: snowflake
|
||||||
|
guildID*: snowflake
|
||||||
|
channelType*: int
|
||||||
|
name*: string
|
||||||
|
|
||||||
|
MessageAttachment* = ref object of DiscordObject
|
||||||
|
## Represents a message attachment
|
||||||
|
filename*: string
|
||||||
|
size*: uint
|
||||||
|
url*: string
|
||||||
|
proxyURL*: string
|
||||||
|
height*: int
|
||||||
|
width*: int
|
||||||
|
|
||||||
Message* = ref object of DiscordObject
|
Message* = ref object of DiscordObject
|
||||||
channelID*: snowflake
|
channelID*: snowflake
|
||||||
guildID*: snowflake
|
guildID*: snowflake
|
||||||
|
@ -57,11 +78,11 @@ type
|
||||||
tts*: bool
|
tts*: bool
|
||||||
mentionEveryone*: bool
|
mentionEveryone*: bool
|
||||||
mentions*: seq[User]
|
mentions*: seq[User]
|
||||||
#mentionRoles*: seq[Role]
|
mentionRoles*: seq[snowflake]
|
||||||
#mentionChannels*: seq[ChannelMention]
|
mentionChannels*: seq[ChannelMention]
|
||||||
#attachments*: seq[Attachment]
|
attachments*: seq[MessageAttachment]
|
||||||
#embeds*: seq[Embed]
|
embeds*: seq[Embed]
|
||||||
#reactions*: seq[Reaction]
|
reactions*: seq[Reaction]
|
||||||
pinned*: bool
|
pinned*: bool
|
||||||
webhookID*: snowflake
|
webhookID*: snowflake
|
||||||
`type`*: MessageType
|
`type`*: MessageType
|
||||||
|
@ -80,11 +101,6 @@ proc newMessage*(messageJson: JsonNode): Message =
|
||||||
editedTimestamp: messageJson{"edited_timestamp"}.getStr(),
|
editedTimestamp: messageJson{"edited_timestamp"}.getStr(),
|
||||||
tts: messageJson["tts"].getBool(),
|
tts: messageJson["tts"].getBool(),
|
||||||
mentionEveryone: messageJson["mention_everyone"].getBool(),
|
mentionEveryone: messageJson["mention_everyone"].getBool(),
|
||||||
#mentionRoles
|
|
||||||
#mentionChannels?
|
|
||||||
#attachments
|
|
||||||
#embeds
|
|
||||||
#reactions?
|
|
||||||
pinned: messageJson["pinned"].getBool(),
|
pinned: messageJson["pinned"].getBool(),
|
||||||
webhookID: getIDFromJson(messageJson{"webhook_id"}.getStr()),
|
webhookID: getIDFromJson(messageJson{"webhook_id"}.getStr()),
|
||||||
`type`: MessageType(messageJson["type"].getInt()),
|
`type`: MessageType(messageJson["type"].getInt()),
|
||||||
|
@ -97,11 +113,43 @@ proc newMessage*(messageJson: JsonNode): Message =
|
||||||
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()
|
for userJson in messageJson["mentions"]:
|
||||||
|
|
||||||
for userJson in mentionsJson.items:
|
|
||||||
msg.mentions.add(newUser(userJson))
|
msg.mentions.add(newUser(userJson))
|
||||||
|
|
||||||
|
for role in messageJson["mention_roles"]:
|
||||||
|
msg.mentionRoles.add(getIDFromJson(role.getStr()))
|
||||||
|
|
||||||
|
if (messageJson.contains("mention_channels")):
|
||||||
|
for channel in messageJson["mention_channels"]:
|
||||||
|
msg.mentionChannels.add(ChannelMention(
|
||||||
|
channelID: getIDFromJson(channel["id"].getStr()),
|
||||||
|
guildID: getIDFromJson(channel["guild_id"].getStr()),
|
||||||
|
channelType: channel["type"].getInt(),
|
||||||
|
name: channel["tyoe"].getStr()
|
||||||
|
))
|
||||||
|
|
||||||
|
for attachment in messageJson["attachments"]:
|
||||||
|
msg.attachments.add(MessageAttachment(
|
||||||
|
id: getIDFromJson(attachment["id"].getStr()),
|
||||||
|
filename: attachment["filename"].getStr(),
|
||||||
|
size: uint(attachment["size"].getInt()),
|
||||||
|
url: attachment["url"].getStr(),
|
||||||
|
proxyURL: attachment["proxy_url"].getStr(),
|
||||||
|
height: attachment["height"].getInt(),
|
||||||
|
width: attachment["width"].getInt()
|
||||||
|
))
|
||||||
|
|
||||||
|
for embed in messageJson["embeds"]:
|
||||||
|
msg.embeds.add(Embed(embedJson: embed))
|
||||||
|
|
||||||
|
if (messageJson.contains("reactions")):
|
||||||
|
for reaction in messageJson["reactions"]:
|
||||||
|
msg.reactions.add(Reaction(
|
||||||
|
count: uint(reaction["count"].getInt()),
|
||||||
|
me: reaction["me"].getBool(),
|
||||||
|
emoji: newEmoji(reaction["emoji"], msg.guildID)
|
||||||
|
))
|
||||||
|
|
||||||
if (messageJson.contains("activity")):
|
if (messageJson.contains("activity")):
|
||||||
msg.activity = MessageActivity(`type`: MessageActivityType(messageJson["activity"]["type"].getInt()),
|
msg.activity = MessageActivity(`type`: MessageActivityType(messageJson["activity"]["type"].getInt()),
|
||||||
partyID: messageJson["activity"]["party_id"].getStr())
|
partyID: messageJson["activity"]["party_id"].getStr())
|
||||||
|
|
Reference in New Issue