From 84d010bbbeee3012f3ada553a6ead02daa21cd4f Mon Sep 17 00:00:00 2001 From: 13xforever Date: Fri, 3 Apr 2020 21:24:57 +0500 Subject: [PATCH] hotfix for the import --- CompatBot/Commands/CompatList.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/CompatBot/Commands/CompatList.cs b/CompatBot/Commands/CompatList.cs index 1ea75168..146adedb 100644 --- a/CompatBot/Commands/CompatList.cs +++ b/CompatBot/Commands/CompatList.cs @@ -4,10 +4,12 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using CompatApiClient; +using CompatApiClient.Compression; using CompatApiClient.POCOs; using CompatApiClient.Utils; using CompatBot.Commands.Attributes; @@ -536,13 +538,24 @@ namespace CompatBot.Commands public static async Task ImportMetacriticScoresAsync() { var scoreJson = "metacritic_ps3.json"; - if (!File.Exists(scoreJson)) + string json; + if (File.Exists(scoreJson)) + json = File.ReadAllText(scoreJson); + else { - Config.Log.Warn($"Missing {scoreJson}"); - return; + Config.Log.Warn($"Missing {scoreJson}, trying to get an online copy..."); + using var httpClient = HttpClientFactory.Create(new CompressionMessageHandler()); + try + { + json = await httpClient.GetStringAsync($"https://raw.githubusercontent.com/RPCS3/discord-bot/master/{scoreJson}").ConfigureAwait(false); + } + catch (Exception e) + { + Config.Log.Warn(e, $"Failed to get online copy of {scoreJson}"); + return; + } } - var json = File.ReadAllText(scoreJson); var scoreList = JsonConvert.DeserializeObject>(json); Config.Log.Debug($"Importing {scoreList.Count} Metacritic items"); var duplicates = new List();