Exemplo n.º 1
0
        public async Task Handle(ReactionAddedNotification notification, CancellationToken cancellationToken)
        {
            var isChannel = notification.Reaction.Channel.Id == RulesChannelId;
            var isMessage = notification.Message.Id == ReactionRoleMessageId;

            if (!isChannel || !isMessage)
            {
                return;
            }

            if (!(notification.Reaction.User.Value is IGuildUser user))
            {
                _logger.LogWarning("Received a reaction event {0} but could not cast user {1} to IGuildUser",
                                   notification.Reaction, notification.Reaction.User);
                return;
            }

            if (notification.Reaction.Emote is Emote emote &&
                emote.Id == FlowerId)
            {
                if (!(notification.Channel is IGuildChannel guildChannel))
                {
                    _logger.LogWarning("Could not cast {0} to IGuildChannel", notification.Channel);
                    return;
                }

                var guild = guildChannel.Guild;
                await user.AddRolesAsync(_reactRoles.Select(r => guild.GetRole(r)));

                _logger.LogInformation("Added roles {0} to user {1}", _reactRoles, user);
            }
        }
        public void Constructor_Always_PropertiesAreGiven()
        {
            var mockMessage  = new Mock <ICacheable <IUserMessage, ulong> >();
            var mockChannel  = new Mock <IISocketMessageChannel>();
            var mockReaction = new Mock <ISocketReaction>();

            var uut = new ReactionAddedNotification(mockMessage.Object, mockChannel.Object, mockReaction.Object);

            uut.Message.ShouldBeSameAs(mockMessage.Object);
            uut.Channel.ShouldBeSameAs(mockChannel.Object);
            uut.Reaction.ShouldBeSameAs(mockReaction.Object);
        }