private string GetCoronaReport(Action <ProgressHandlers> progress) { var handlers = new ProgressHandlers(); progress.Invoke(handlers); return($"**:rotating_light: Corona virus pandemic is ongoing :rotating_light:** {GenerateRelevantCountryReport(handlers)}"); }
private string GenerateRelevantCountryReport(ProgressHandlers progressHandlers) { var relevantCountries = GetRelevantCountries(); var flags = _flags; var sb = new StringBuilder(); sb.AppendLine(); void AppendErrorRow(StringBuilder builder, string country, string errorReason) { string flag = flags.Get <string>(country); flag = flag == null ? string.Empty : flag + " "; builder.AppendLine($"**{flag}{country}**"); builder.AppendLine($"❌ Failed to get data from the data source: {errorReason}"); builder.AppendLine(); }; var distinctCountries = relevantCountries.Distinct().ToList(); foreach (var country in distinctCountries.Select((country, index) => new { Name = country, index })) { progressHandlers.OnStepCompleted?.Invoke($"`⌛ Checking {country.index + 1}/{distinctCountries.Count}: {country.Name}...`"); var stats = GetCountryStats(country.Name, out var error); if (stats != null) { AppendRow(sb, stats); } else { AppendErrorRow(sb, country.Name, error); } } var neonInfected = GetStat("guildInfected") ?? 0; var neonRecovered = GetStat("guildRecovered") ?? 0; AppendRow(sb, new CoronaCountryStats { Name = "Neon", Cases = neonInfected, TodayCases = 0, Deaths = 0, TodayDeaths = 0, Recovered = neonRecovered }); return(sb.ToString()); }