protected async Task UploadDatabaseBackupAsync(IMessageChannel channel, string databaseFilePath)
        {
            bool backupInProgress = GetDatabaseStatus(databaseFilePath).BackupInProgress;

            if (backupInProgress)
            {
                await DiscordUtilities.ReplyErrorAsync(channel, "A backup is already in progress. Please wait until it has completed.");
            }
            else
            {
                GetDatabaseStatus(databaseFilePath).BackupInProgress = true;

                if (System.IO.File.Exists(databaseFilePath))
                {
                    try {
                        await DiscordUtilities.ReplyInfoAsync(channel,
                                                              string.Format("Uploading database backup ({0:0.##} MB).\nThe backup will be posted in this channel when it is complete.",
                                                                            new System.IO.FileInfo(databaseFilePath).Length / 1024000.0));

                        await channel.SendFileAsync(databaseFilePath, string.Format("`Database backup ({0})`", DateUtilities.GetCurrentDateUtc()));
                    }
                    catch (Exception) {
                        await DiscordUtilities.ReplyErrorAsync(channel, "Database file cannot be accessed.");
                    }
                }
                else
                {
                    await DiscordUtilities.ReplyErrorAsync(channel, "Database file does not exist at the specified path.");
                }

                GetDatabaseStatus(databaseFilePath).BackupInProgress = false;
            }
        }
示例#2
0
        // Status replies

        public async Task ReplyInfoAsync(string message) => await DiscordUtilities.ReplyInfoAsync(Context.Channel, message);