Improve code readability

This commit is contained in:
2024-12-20 23:15:26 +03:30
parent aa2feea611
commit 3c80744b80

View File

@@ -17,16 +17,14 @@ public class HandleDbBackup
logger?.LogInformation("Backup requested"); logger?.LogInformation("Backup requested");
try{ try{
var json = (await _db.Find(new BsonDocument()).ToListAsync()).ToJson(); var json = (await _db.Find(new BsonDocument()).ToListAsync()).ToJson();
var bytes = Encoding.UTF8.GetBytes(json);
var bytes = Encoding.UTF8.GetBytes(json); var stream = new MemoryStream(bytes);
var stream = new MemoryStream(bytes); var postCount = await _db.CountDocumentsAsync(new BsonDocument());
var caption =
await _bot.SendDocument(adminId, InputFile.FromStream(stream, "backup.json"), $"Backup of the database {dbname}<br>Created at {DateTime.Now:yyyy-MM-dd HH:mm:ss}<br>Current post count: {postCount}";
"Backup of your collection\nCreated at " + await _bot.SendDocument(adminId, InputFile.FromStream(stream, "backup.json"), caption, ParseMode.Html);
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss" + "\nCurrent post count: " + _db.CountDocumentsAsync(new BsonDocument())), logger?.LogInformation("Backup sent");
ParseMode.Html);
logger?.LogInformation("Backup sent");
} }
catch(Exception ex){ catch(Exception ex){
logger?.LogError(ex,"Unable to backup database"); logger?.LogError(ex,"Unable to backup database");