2020-05-31 05:08:44 +00:00
|
|
|
import json, discordobject, nimcordutils, user, member
|
|
|
|
|
|
|
|
type
|
|
|
|
MessageType* = enum
|
|
|
|
default = 0,
|
|
|
|
recipientAdd = 1,
|
|
|
|
recipientRemove = 2,
|
|
|
|
call = 3,
|
|
|
|
channelNameChange = 4,
|
|
|
|
channelIconChange = 5,
|
|
|
|
channelPinnedMessage = 6,
|
|
|
|
guildMemberJoin = 7,
|
|
|
|
userPremiumGuildSubscription = 8,
|
|
|
|
userPremiumGuildSubscriptionTier1 = 9,
|
|
|
|
userPremiumGuildSubscriptionTier2 = 10,
|
|
|
|
userPremiumGuildSubscriptionTier3 = 11,
|
|
|
|
channelFollowAdd = 12,
|
|
|
|
guildDiscoveryDisqualified = 14,
|
|
|
|
guildDiscoveryRequalified = 15
|
|
|
|
|
|
|
|
MessageActivityType* = enum
|
|
|
|
join = 1,
|
|
|
|
spectate = 2,
|
|
|
|
listen = 3,
|
|
|
|
joinRequest = 5
|
|
|
|
|
|
|
|
MessageActivity* = object
|
|
|
|
`type`*: MessageActivityType
|
|
|
|
partyID*: string
|
|
|
|
|
|
|
|
MessageApplication* = object of DiscordObject
|
|
|
|
coverImage: string
|
|
|
|
description: string
|
|
|
|
icon: string
|
|
|
|
name: string
|
|
|
|
|
|
|
|
MessageReference* = object
|
|
|
|
messageID: snowflake
|
|
|
|
channelID: snowflake
|
|
|
|
guildID: snowflake
|
|
|
|
|
|
|
|
Message* = object of DiscordObject
|
|
|
|
channelID*: snowflake
|
|
|
|
guildID*: snowflake
|
|
|
|
author*: User
|
|
|
|
member*: GuildMember
|
|
|
|
content*: string
|
|
|
|
timestamp*: string
|
|
|
|
editedTimestamp*: string
|
|
|
|
tts*: bool
|
|
|
|
mentionEveryone*: bool
|
|
|
|
mentions*: seq[User]
|
|
|
|
#mentionRoles*: seq[Role]
|
|
|
|
#mentionChannels*: seq[ChannelMention]
|
|
|
|
#attachments*: seq[Attachment]
|
|
|
|
#embeds*: seq[Embed]
|
|
|
|
#reactions*: seq[Reaction]
|
|
|
|
pinned*: bool
|
|
|
|
webhookID*: snowflake
|
|
|
|
`type`*: MessageType
|
|
|
|
activity*: MessageActivity
|
|
|
|
application*: MessageApplication
|
|
|
|
messageReference*: MessageReference
|
|
|
|
flags*: int
|
|
|
|
|
2020-05-31 06:15:16 +00:00
|
|
|
proc newMessage*(messageJson: JsonNode): Message =
|
2020-05-31 05:08:44 +00:00
|
|
|
var msg = Message(
|
2020-05-31 06:15:16 +00:00
|
|
|
id: getIDFromJson(messageJson["id"].getStr()),
|
2020-06-18 03:16:08 +00:00
|
|
|
channelID: getIDFromJson(messageJson["channel_id"].getStr()),
|
|
|
|
guildID: getIDFromJson(messageJson{"guild_id"}.getStr()),
|
2020-05-31 06:15:16 +00:00
|
|
|
content: messageJson["content"].getStr(),
|
|
|
|
timestamp: messageJson["timestamp"].getStr(),
|
|
|
|
editedTimestamp: messageJson{"edited_timestamp"}.getStr(),
|
|
|
|
tts: messageJson["tts"].getBool(),
|
|
|
|
mentionEveryone: messageJson["mention_everyone"].getBool(),
|
2020-05-31 05:08:44 +00:00
|
|
|
#mentionRoles
|
2020-05-31 06:15:16 +00:00
|
|
|
#mentionChannels?
|
2020-05-31 05:08:44 +00:00
|
|
|
#attachments
|
|
|
|
#embeds
|
2020-05-31 06:15:16 +00:00
|
|
|
#reactions?
|
|
|
|
pinned: messageJson["pinned"].getBool(),
|
2020-06-18 03:16:08 +00:00
|
|
|
webhookID: getIDFromJson(messageJson{"webhook_id"}.getStr()),
|
2020-05-31 06:15:16 +00:00
|
|
|
`type`: MessageType(messageJson["type"].getInt()),
|
|
|
|
flags: messageJson{"flags"}.getInt()
|
2020-05-31 05:08:44 +00:00
|
|
|
)
|
|
|
|
|
2020-05-31 06:15:16 +00:00
|
|
|
if (messageJson.contains("author")):
|
|
|
|
msg.author = newUser(messageJson["author"])
|
|
|
|
if (messageJson.contains("member")):
|
|
|
|
msg.member = newGuildMember(messageJson["member"])
|
2020-05-31 05:08:44 +00:00
|
|
|
|
2020-05-31 06:15:16 +00:00
|
|
|
if (messageJson.contains("mentions")):
|
|
|
|
let mentionsJson = messageJson["mentions"].getElems()
|
2020-05-31 05:08:44 +00:00
|
|
|
|
2020-05-31 06:15:16 +00:00
|
|
|
for userJson in mentionsJson.items:
|
2020-05-31 05:08:44 +00:00
|
|
|
msg.mentions.add(newUser(userJson))
|
|
|
|
|
2020-05-31 06:15:16 +00:00
|
|
|
if (messageJson.contains("activity")):
|
|
|
|
msg.activity = MessageActivity(`type`: MessageActivityType(messageJson["activity"]["type"].getInt()),
|
|
|
|
partyID: messageJson["activity"]["party_id"].getStr())
|
|
|
|
if (messageJson.contains("application")):
|
2020-05-31 05:08:44 +00:00
|
|
|
msg.application = MessageApplication(
|
2020-05-31 06:15:16 +00:00
|
|
|
id: getIDFromJson(messageJson["application"]["id"].getStr()),
|
|
|
|
coverImage: messageJson["application"]{"cover_image"}.getStr(),
|
|
|
|
description: messageJson["application"]["description"].getStr(),
|
|
|
|
icon: messageJson["application"]{"icon"}.getStr(),
|
|
|
|
name: messageJson["application"]["name"].getStr()
|
2020-05-31 05:08:44 +00:00
|
|
|
)
|
2020-05-31 06:15:16 +00:00
|
|
|
if (messageJson.contains("message_reference")):
|
2020-05-31 05:08:44 +00:00
|
|
|
msg.messageReference = MessageReference(
|
2020-05-31 06:15:16 +00:00
|
|
|
messageID: getIDFromJson(messageJson["message_reference"]{"message_id"}.getStr()),
|
|
|
|
channelID: getIDFromJson(messageJson["message_reference"]["channel_id"].getStr()),
|
|
|
|
guildID: getIDFromJson(messageJson["message_reference"]{"guild_id"}.getStr()),
|
2020-05-31 05:08:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return msg
|