public async Task ReactionRemoved(ICacheable <IUserMessage, ulong> cachedMessage, IISocketMessageChannel channel, ISocketReaction reaction)
        {
            //Bugfix for NRE?
            if (reaction is null || reaction.User.Value is null)
            {
                return;
            }

            //Don't trigger if the emoji is wrong, or if the user is bot
            if (reaction.User.IsSpecified && reaction.User.Value.IsBot)
            {
                return;
            }

            if (reaction.Emote.Name != _emoji)
            {
                return;
            }

            //If there's an error reply when the reaction is removed, delete that reply,
            //remove the cached error, remove it from the cached replies, and remove
            //the reactions from the original message
            if (ErrorReplies.TryGetValue(cachedMessage.Id, out var botReplyId) == false)
            {
                return;
            }

            await channel.DeleteMessageAsync(botReplyId);

            if
            (
                AssociatedErrors.TryRemove(cachedMessage.Id, out _) &&
                ErrorReplies.TryRemove(cachedMessage.Id, out _)
            )
            {
                var originalMessage = await cachedMessage.GetOrDownloadAsync();

                //If we know what user added the reaction, remove their and our reaction
                //Otherwise just remove ours

                if (reaction.User.IsSpecified)
                {
                    await originalMessage.RemoveReactionAsync(_emote, reaction.User.Value);
                }

                await originalMessage.RemoveReactionAsync(_emote, await _selfUserProvider.GetSelfUserAsync());
            }
        }
Exemple #2
0
        /// <summary>
        /// Mutes the user if they have an active mute infraction in the guild.
        /// </summary>
        /// <param name="guild">The guild that the user joined.</param>
        /// <param name="user">The user who joined the guild.</param>
        /// <returns>
        /// A <see cref="Task"/> that will complete when the operation completes.
        /// </returns>
        private async Task TryMuteUserAsync(ISocketGuildUser guildUser)
        {
            var userHasActiveMuteInfraction = await _moderationService.AnyInfractionsAsync(new InfractionSearchCriteria()
            {
                GuildId     = guildUser.GuildId,
                IsDeleted   = false,
                IsRescinded = false,
                SubjectId   = guildUser.Id,
                Types       = new[] { InfractionType.Mute },
            });

            if (!userHasActiveMuteInfraction)
            {
                Log.Debug("User {0} was not muted, because they do not have any active mute infractions.", guildUser.Id);
                return;
            }

            var muteRole = await _moderationService.GetOrCreateDesignatedMuteRoleAsync(guildUser.Guild, (await _selfUserProvider.GetSelfUserAsync()).Id);

            Log.Debug("User {0} was muted, because they have an active mute infraction.", guildUser.Id);

            await guildUser.AddRoleAsync(muteRole);
        }