Exemple #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!");
        }
Exemple #2
0
        /// <summary>
        /// Deletes the message if it contains an invite link.
        /// </summary>
        /// <param name="message">The message to possibly purge.</param>
        /// <returns></returns>
        private async Task TryPurgeInviteLink(IMessage message)
        {
            if
            (
                !(message.Author is IGuildUser author) ||
                !(message.Channel is IGuildChannel guildChannel) ||
                !(message.Channel is IMessageChannel msgChannel)
            )
            {
                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 == _botUser.Id)
            {
                Log.Debug("Message {MessageId} was skipped because the author was Modix", message.Id);
                return;
            }

            if (await IsChannelModeratedAsync(guildChannel.Guild, msgChannel))
            {
                Log.Debug("Message {MessageId} was skipped because the channel {Channel} was designated as Unmoderated",
                          message.Id, msgChannel.Id);
                return;
            }

            var matches = _inviteLinkMatcher.Matches(message.Content);

            if (!matches.Any())
            {
                Log.Debug("Message {MessageId} was skipped because the content did not contain an invite link: \"{Content}\"",
                          message.Id, message.Content);
                return;
            }

            // TODO: Booooooo for non-abstractable dependencies
            if (author.Guild is SocketGuild socketGuild)
            {
                // Allow invites to the guild in which the message was posted
                var newInvites = matches
                                 .Select(x => x.Value)
                                 .Except((await socketGuild
                                          .GetInvitesAsync())
                                         .Select(x => x.Url));

                if (!newInvites.Any())
                {
                    Log.Debug("Message {MessageId} was skipped because the invite was to this server", message.Id);
                    return;
                }
            }

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

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

            await _moderationService.DeleteMessageAsync(message, "Unauthorized Invite Link");

            Log.Debug("Message {MessageId} was deleted because it contains an invite link", message.Id);

            await msgChannel.SendMessageAsync($"Sorry {author.Mention} your invite link has been removed - please don't post links to other guilds");
        }