private async Task <OperationResult> ArchiveRoleplayAsync
        (
            SocketGuild guild,
            ServerService serverService,
            RoleplayDiscordService roleplayService,
            DedicatedChannelService dedicatedChannels,
            RoleplayServerSettingsService serverSettings,
            Roleplay roleplay
        )
        {
            if (roleplay.DedicatedChannelID is null)
            {
                return(OperationResult.FromError("The roleplay doesn't have a dedicated channel."));
            }

            if (roleplay.IsPublic)
            {
                var postResult = await PostArchivedRoleplayAsync(guild, serverService, serverSettings, roleplay);

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

            var dedicatedChannel = guild.GetTextChannel((ulong)roleplay.DedicatedChannelID);

            if (dedicatedChannel is null)
            {
                // Something's gone wrong in the database. Who the f**k knows why. We'll do an extra delete to be
                // on the safe side.
                await dedicatedChannels.DeleteChannelAsync(guild, roleplay);

                return(OperationResult.FromSuccess());
            }

            // Ensure the messages are all caught up
            foreach (var message in await dedicatedChannel.GetMessagesAsync().FlattenAsync())
            {
                if (!(message is IUserMessage userMessage))
                {
                    continue;
                }

                // We don't care about the results here.
                await roleplayService.ConsumeMessageAsync(userMessage);
            }

            await dedicatedChannels.DeleteChannelAsync(guild, roleplay);

            return(OperationResult.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));
    }
Beispiel #3
0
    /// <summary>
    /// Deletes a roleplay and its associated channel, if any.
    /// </summary>
    /// <param name="roleplay">The roleplay.</param>
    /// <returns>A deletion result which may or may not have succeeded.</returns>
    public async Task <Result> DeleteRoleplayAsync(Roleplay roleplay)
    {
        if (!roleplay.DedicatedChannelID.HasValue)
        {
            return(await _roleplays.DeleteRoleplayAsync(roleplay));
        }

        var deleteChannel = await _dedicatedChannels.DeleteChannelAsync(roleplay);

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

        return(await _roleplays.DeleteRoleplayAsync(roleplay));
    }