Skip to content

Commit

Permalink
Adds basic support for message replies (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
SinisterRectus authored May 26, 2021
1 parent 2475fc9 commit eb66206
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libs/containers/Message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ function Message:_loadMore(data)
self._attachments = #data.attachments > 0 and data.attachments or nil
end

if data.referenced_message and data.referenced_message ~= null then
self._referencedMessage = self._parent._messages:_insert(data.referenced_message)
end

end

function Message:_addReaction(d)
Expand Down Expand Up @@ -123,11 +127,11 @@ function Message:_removeReaction(d)

local reactions = self._reactions
if not reactions then return nil end

local emoji = d.emoji
local k = emoji.id ~= null and emoji.id or emoji.name
local reaction = reactions:get(k) or nil

if not reaction then return nil end -- uncached reaction?

reaction._count = reaction._count - 1
Expand Down Expand Up @@ -566,6 +570,12 @@ function get.member(self)
return guild and guild._members:get(self._author._id)
end

--[=[@p referencedMessage Message/nil If available, the previous message that
this current message references as seen in replies.]=]
function get.referencedMessage(self)
return self._referencedMessage
end

--[=[@p link string URL that can be used to jump-to the message in the Discord client.]=]
function get.link(self)
local guild = self.guild
Expand Down
8 changes: 8 additions & 0 deletions libs/containers/abstract/TextChannel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,19 @@ function TextChannel:send(content)
end
end

local refMessage, refMention
if tbl.reference then
refMessage = {message_id = Resolver.messageId(tbl.reference.message)}
refMention = {replied_user = not not tbl.reference.mention}
end

data, err = self.client._api:createMessage(self._id, {
content = content,
tts = tbl.tts,
nonce = tbl.nonce,
embed = tbl.embed,
message_reference = refMessage,
allowed_mentions = refMention,
}, files)

else
Expand Down

0 comments on commit eb66206

Please sign in to comment.