Esempio n. 1
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());
    }
    private static async Task <Result> ArchiveRoleplayAsync
    (
        IServiceProvider services,
        FeedbackService feedback,
        RoleplayDiscordService roleplayService,
        DedicatedChannelService dedicatedChannels,
        RoleplayServerSettingsService serverSettings,
        Roleplay roleplay
    )
    {
        if (roleplay.DedicatedChannelID is null)
        {
            return(new UserError("The roleplay doesn't have a dedicated channel."));
        }

        var ensureLogged = await roleplayService.EnsureAllMessagesAreLoggedAsync(roleplay);

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

        if (!roleplay.IsPublic)
        {
            return(await dedicatedChannels.DeleteChannelAsync(roleplay));
        }

        var postResult = await PostArchivedRoleplayAsync(services, feedback, serverSettings, roleplay);

        if (!postResult.IsSuccess)
        {
            return(postResult);
        }

        return(await dedicatedChannels.DeleteChannelAsync(roleplay));
    }