Пример #1
0
    public async Task <Result> ListServerRoleplaysAsync()
    {
        var roleplays = await _discordRoleplays.QueryRoleplaysAsync
                        (
            q => q
            .Where(rp => rp.Server.DiscordID == _context.GuildID.Value)
            .Where(rp => rp.IsPublic)
                        );

        var pages = PaginatedEmbedFactory.SimpleFieldsFromCollection
                    (
            roleplays,
            r => r.Name,
            r => r.GetSummaryOrDefault(),
            "There are no roleplays in the server that you can view."
                    );

        return((Result)await _feedback.SendContextualPaginatedMessageAsync
               (
                   _context.User.ID,
                   pages,
                   ct : this.CancellationToken
               ));
    }
Пример #2
0
    /// <inheritdoc />
    public async Task <Result> RespondAsync(IReady gatewayEvent, CancellationToken ct = default)
    {
        var joinedGuilds = new List <Snowflake>();

        await foreach (var get in GetGuildsAsync(ct))
        {
            if (get.IsSuccess)
            {
                joinedGuilds.Add(get.Entity);
            }
        }

        var activeRoleplays = await _roleplays.QueryRoleplaysAsync
                              (
            q => q
            .Where(rp => rp.IsActive)
            .Where(rp => rp.DedicatedChannelID.HasValue)
            .Where(rp => joinedGuilds.Contains(rp.Server.DiscordID))
                              );

        foreach (var activeRoleplay in activeRoleplays)
        {
            var ensureLogged = await _roleplays.EnsureAllMessagesAreLoggedAsync(activeRoleplay);

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

            var updatedMessages = ensureLogged.Entity;

            if (updatedMessages > 0)
            {
                _log.LogInformation
                (
                    "Added or updated {UpdateCount} missed {Pluralized} in \"{RoleplayName}\"",
                    updatedMessages,
                    updatedMessages > 1 ? "messages" : "message",
                    activeRoleplay.Name
                );
            }
        }

        return(Result.FromSuccess());
    }