Discordia icon indicating copy to clipboard operation
Discordia copied to clipboard

Resolve Emoji hashes in Resolvers.emojiId

Open Mehgugs opened this issue 6 years ago • 6 comments

Resolvers.emojiId should be able to resolve a custom emoji's hash since it contains an id. This would make emoji functions work for both emoji types when called with data from uncached events, i.e manipulating a reaction after reactionAddUncached.

Mehgugs avatar Sep 26 '18 21:09 Mehgugs

Can you give examples? Users generally don't need to deal with name:id, since they shouldn't be making API calls or mentionStrings directly.

SinisterRectus avatar Sep 26 '18 21:09 SinisterRectus

https://discordapp.com/channels/81384788765712384/381890411414683648/494619294055923713

myFunction takes an argument which is passed to add reaction and the issue arrises when uncached is called; vanilla emoji still work but custom do not.

Mehgugs avatar Sep 26 '18 22:09 Mehgugs

Oh I see. Resolver, by design, does not have the ability to get objects by ID. It only ever returns primitive types. We probably should have different events for custom vs unicode emojis or different parameters passed for the emoji id and name. For now, I think the solution is for the user to do a little leg work:

client:on("reactionAddUncached", function(channel, messageId, hash, userId)
  local message = channel:getMessage(messageId)
  if message and tonumber(hash) then
    local emoji = client:getEmoji(hash)
    if emoji then
      message:addReaction(emoji)
    end
  end
end)

Reactions are one of Discordia's weak points. I'm not sure if I can fix this in 2.x without breaking things.

SinisterRectus avatar Sep 26 '18 22:09 SinisterRectus

Yeah, and you can extract an id from a custom hash (afaik) so it's not really an problem for users, but Resolver could in theory reduce a hash to just the id part.

Mehgugs avatar Sep 26 '18 22:09 Mehgugs

This will almost certainly not change until the next major version of Discordia.

SinisterRectus avatar Oct 31 '18 20:10 SinisterRectus

In 3.0, I have eliminated "uncached" events and we are now left with just reactionAdd.

In the new ReactionEmoji class, there is now a hash property that handles custom and default emojis:

function get:hash()
	if self._id then
		return self._name .. ':' .. self._id
	else
		return self._name
	end
end

Although, I have not yet wrapped the event's emoji with ReactionEmoji. I still need to figure out how to clean up event payloads.

Additionally, as mentioned in #139, I've added a hash property to the Reaction class:

function get:hash()
	return self.emoji.id or self.emoji.name
end

I think this solves the issue at hand.

SinisterRectus avatar Jul 06 '21 14:07 SinisterRectus