feat(bot): query updated signature parameters of expired discord attachments

This commit is contained in:
alyssa 2024-03-09 15:08:30 -05:00 committed by Iris System
parent caff9c50aa
commit 64c1939d71
4 changed files with 25 additions and 1 deletions

View file

@ -45,13 +45,20 @@ public class ImportExport
try
{
var response = await _client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
if (content == "This content is no longer available.")
{
var refreshed = await ctx.Rest.RefreshUrls(new[] { url.ToString() });
response = await _client.GetAsync(new Uri(refreshed.RefreshedUrls[0].Refreshed));
content = await response.Content.ReadAsStringAsync();
}
if (!response.IsSuccessStatusCode)
throw Errors.InvalidImportFile;
// hacky fix for discord api returning nonsense charsets sometimes
response.Content.Headers.Remove("content-type");
response.Content.Headers.Add("content-type", "application/json; charset=UTF-8");
data = JsonConvert.DeserializeObject<JObject>(
await response.Content.ReadAsStringAsync(),
content,
_settings
);
if (data == null)