Esempio n. 1
0
        private async Task TryCheckMessageAsync(IMessage message)
        {
            if (!(message.Author is IGuildUser author) ||
                (author.Guild is null) ||
                !(message.Channel is IGuildChannel channel) ||
                (channel.Guild is null))
            {
                Log.Debug(
                    "Message {MessageId} was not in an IGuildChannel & IMessageChannel, or Author {Author} was not an IGuildUser",
                    message.Id, message.Author.Id);
                return;
            }

            if (author.Id == _discordSocketClient.CurrentUser.Id)
            {
                return;
            }

            var isContentBlocked = await IsContentBlocked(channel, message);

            if (!isContentBlocked)
            {
                return;
            }

            if (await _designatedChannelService.ChannelHasDesignationAsync(channel.Guild,
                                                                           channel, DesignatedChannelType.Unmoderated, default))
            {
                return;
            }

            if (await _authorizationService.HasClaimsAsync(author, AuthorizationClaim.BypassMessageContentPatternCheck))
            {
                Log.Debug("Message {MessageId} was skipped because the author {Author} has the {Claim} claim",
                          message.Id, message.Author.Id, AuthorizationClaim.BypassMessageContentPatternCheck);
                return;
            }

            Log.Debug("Message {MessageId} is going to be deleted", message.Id);

            await _moderationService.DeleteMessageAsync(message, "Unauthorized Message Content",
                                                        _discordSocketClient.CurrentUser.Id, default);

            Log.Debug("Message {MessageId} was deleted because it contains blocked content", message.Id);

            await message.Channel.SendMessageAsync(
                $"Sorry {author.Mention} your message contained blocked content and has been removed!");
        }
Esempio n. 2
0
        private async Task HandleReactionAsync(ICacheable <IUserMessage, ulong> cachedMessage, IReaction reaction)
        {
            var emote = reaction.Emote;

            if (!_starboardService.IsStarEmote(emote))
            {
                return;
            }

            var message = await cachedMessage.GetOrDownloadAsync();

            if (!(message.Channel is IGuildChannel channel))
            {
                return;
            }

            var isIgnoredFromStarboard = await _designatedChannelService
                                         .ChannelHasDesignationAsync(channel.Guild, channel, DesignatedChannelType.IgnoredFromStarboard);

            var starboardExists = await _designatedChannelService
                                  .AnyDesignatedChannelAsync(channel.GuildId, DesignatedChannelType.Starboard);

            if (isIgnoredFromStarboard || !starboardExists)
            {
                return;
            }

            var reactionCount = await _starboardService.GetReactionCount(message, emote);

            if (await _starboardService.ExistsOnStarboard(message))
            {
                if (_starboardService.IsAboveReactionThreshold(reactionCount))
                {
                    await _starboardService.ModifyEntry(channel.Guild, message, FormatContent(reactionCount), GetEmbedColor(reactionCount));
                }
                else
                {
                    await _starboardService.RemoveFromStarboard(channel.Guild, message);
                }
            }
            else if (_starboardService.IsAboveReactionThreshold(reactionCount))
            {
                var embed = GetStarEmbed(message, GetEmbedColor(reactionCount));
                await _starboardService.AddToStarboard(channel.Guild, message, FormatContent(reactionCount), embed);
            }
        }
Esempio n. 3
0
        public async Task AutoConfigureChannelAsync(IChannel channel)
        {
            _authorizationService.RequireAuthenticatedUser();
            _authorizationService.RequireClaims(AuthorizationClaim.DesignatedRoleMappingCreate);

            if (channel is IGuildChannel guildChannel)
            {
                var isUnmoderated = await _designatedChannelService.ChannelHasDesignationAsync(guildChannel.Guild.Id,
                                                                                               channel.Id, DesignatedChannelType.Unmoderated, default);

                if (isUnmoderated)
                {
                    return;
                }

                var muteRole =
                    await GetOrCreateDesignatedMuteRoleAsync(guildChannel.Guild,
                                                             _authorizationService.CurrentUserId.Value);

                await ConfigureChannelMuteRolePermissionsAsync(guildChannel, muteRole);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Determines whether or not to skip a message event, based on unmoderated channel designations
 /// </summary>
 /// <param name="guild">The guild designations should be looked up for</param>
 /// <param name="channel">The channel designations should be looked up for</param>
 /// <returns>True if the channel is designated as Unmoderated, false if not</returns>
 private async Task <bool> IsChannelModeratedAsync(IGuild guild, IMessageChannel channel)
 {
     return(await _designatedChannelService.ChannelHasDesignationAsync(guild, channel, DesignatedChannelType.Unmoderated));
 }
Esempio n. 5
0
        private async Task TryCheckMessageAsync(IPartialMessage message, CancellationToken ct = default)
        {
            var channelId = message.ChannelID.Value;

            var isThreadChannel = await _threadSvc.IsThreadChannelAsync(channelId, ct);

            if (!isThreadChannel)
            {
                return;
            }

            if (!message.GuildID.HasValue)
            {
                return;
            }

            if (!message.Author.HasValue)
            {
                return;
            }

            var author    = message.Author.Value;
            var authorId  = author.ID;
            var messageId = message.ID.Value;
            var guildId   = message.GuildID.Value;

            if ((author.IsBot.HasValue && author.IsBot.Value) ||
                (author.IsSystem.HasValue && author.IsSystem.Value))
            {
                return;
            }

            if (!message.Content.HasValue)
            {
                return;
            }

            var isContentBlocked = await IsContentBlockedAsync(message);

            if (!isContentBlocked)
            {
                return;
            }

            if (await _designatedChannelService.ChannelHasDesignationAsync(guildId.Value, channelId.Value, DesignatedChannelType.Unmoderated, default))
            {
                return;
            }

            var roles = message.Member.Value.Roles.Value.Select(a => a.Value).ToList();

            roles.Add(guildId.Value);

            await _remoraAuthService.SetCurrentAuthenticatedUserAsync(guildId, authorId);

            if (await _authService.HasClaimsAsync(authorId.Value, messageId.Value, roles, AuthorizationClaim.BypassMessageContentPatternCheck))
            {
                Log.Debug("Message {MessageId} was skipped because the author {Author} has the {Claim} claim",
                          messageId, authorId, AuthorizationClaim.BypassMessageContentPatternCheck);
                return;
            }
            Log.Debug("Message {MessageId} is going to be deleted", message.ID);

            using var transaction = await _deletedMessageRepository.BeginCreateTransactionAsync(ct);

            var reason = "Unauthorized Message Content";
            await _channelApi.DeleteMessageAsync(channelId, messageId, reason, ct);

            var self = await _userApi.GetCurrentUserAsync(ct);

            await _deletedMessageRepository.CreateAsync(
                new DeletedMessageCreationData()
            {
                GuildId     = guildId.Value,
                ChannelId   = channelId.Value,
                MessageId   = messageId.Value,
                AuthorId    = authorId.Value,
                Content     = message.Content.Value,
                Reason      = reason,
                CreatedById = self.Entity !.ID.Value
            }, ct);