public async Task <Result <FeedbackMessage> > ContactUserAsync(IUser discordUser)
    {
        var getSelf = await _userAPI.GetCurrentUserAsync();

        if (!getSelf.IsSuccess)
        {
            return(Result <FeedbackMessage> .FromError(getSelf));
        }

        var self = getSelf.Entity;

        if (discordUser.ID == self.ID)
        {
            return(new UserError
                   (
                       "That's a splendid idea - at least then, I'd get an intelligent reply."
                   ));
        }

        if (discordUser.IsBot.IsDefined(out var isBot) && isBot)
        {
            return(new UserError("I could do that, but I doubt I'd get a reply."));
        }

        var contactMessage = $"Hello there, <@{discordUser.ID}>. I've been instructed to initiate... " +
                             "negotiations... with you. \nA good place to start would be the \"!help <topic>\" " +
                             "command.";

        var sendPrivate = await _feedback.SendPrivateNeutralAsync
                          (
            discordUser.ID,
            contactMessage,
            ct : this.CancellationToken
                          );

        return(!sendPrivate.IsSuccess
            ? Result <FeedbackMessage> .FromError(sendPrivate)
            : new FeedbackMessage("User contacted.", _feedback.Theme.Secondary));
    }
    /// <summary>
    /// Posts a notification that a user was unbanned.
    /// </summary>
    /// <param name="ban">The ban.</param>
    /// <param name="rescinderID">The person who rescinded the ban.</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task <Result> NotifyUserUnbannedAsync(UserBan ban, Snowflake rescinderID)
    {
        var getChannel = await GetModerationLogChannelAsync(ban.Server.DiscordID);

        if (!getChannel.IsSuccess)
        {
            return(Result.FromError(getChannel));
        }

        var getSelf = await _userAPI.GetCurrentUserAsync();

        if (!getSelf.IsSuccess)
        {
            return(Result.FromError(getSelf));
        }

        var self    = getSelf.Entity;
        var channel = getChannel.Entity;

        var whoDidIt = rescinderID == self.ID
            ? "(expired)"
            : $"by <@{rescinderID}>";

        var eb = new Embed
        {
            Colour      = _feedback.Theme.Success,
            Title       = $"User Unbanned (#{ban.ID})",
            Description = $"<@{ban.User.DiscordID}> (ID {ban.User.DiscordID}) was unbanned {whoDidIt}."
        };

        var sendResult = await _feedback.SendEmbedAsync(channel, eb);

        return(sendResult.IsSuccess
            ? Result.FromSuccess()
            : Result.FromError(sendResult));
    }
Beispiel #3
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);