Exemple #1
0
        public async Task ProcessReactionAsync(GatewayPayload reaction)
        {
            if (reaction.EventName == "MESSAGE_REACTION_ADD")
            {
                var reactionAdd = JsonConvert.DeserializeObject <MessageReactionAdd>(
                    reaction.EventData.ToString());

                // Bot sometimes adds reactions to help user interaction so we skip handling
                if (!_commandValidator.IsBotAnAuthor(reactionAdd.UserId))
                {
                    var trackedMessage = await _trackedMessageRepository
                                         .GetTrackedMessageAsync(reactionAdd.MessageId);

                    if (trackedMessage is null)
                    {
                        return;
                    }

                    await _commandDispatcher.DispatchAsync(new Reaction(reactionAdd), trackedMessage);
                }
            }
            else // MESSAGE_REACTION_REMOVE
            {
                var reactionRemove = JsonConvert.DeserializeObject <MessageReactionRemove>(
                    reaction.EventData.ToString());

                if (!_commandValidator.IsBotAnAuthor(reactionRemove.UserId))
                {
                    var trackedMessage = await _trackedMessageRepository
                                         .GetTrackedMessageAsync(reactionRemove.MessageId);

                    if (trackedMessage is null)
                    {
                        return;
                    }

                    await _commandDispatcher.DispatchAsync(new Reaction(reactionRemove), trackedMessage);
                }
            }
        }