mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): query updated signature parameters of expired discord attachments
This commit is contained in:
parent
caff9c50aa
commit
64c1939d71
4 changed files with 25 additions and 1 deletions
|
|
@ -159,6 +159,9 @@ public class DiscordApiClient
|
|||
public Task<Channel> CreateDm(ulong recipientId) =>
|
||||
_client.Post<Channel>("/users/@me/channels", ("CreateDM", default), new CreateDmRequest(recipientId))!;
|
||||
|
||||
public Task<RefreshedUrlsResponse> RefreshUrls(string[] urls) =>
|
||||
_client.Post<RefreshedUrlsResponse>("/attachments/refresh-urls", ("RefreshUrls", default), new RefreshUrlsRequest(urls));
|
||||
|
||||
private static string EncodeEmoji(Emoji emoji) =>
|
||||
WebUtility.UrlEncode(emoji.Id != null ? $"{emoji.Name}:{emoji.Id}" : emoji.Name) ??
|
||||
throw new ArgumentException("Could not encode emoji");
|
||||
|
|
|
|||
3
Myriad/Rest/Types/Requests/RefreshUrlsRequest.cs
Normal file
3
Myriad/Rest/Types/Requests/RefreshUrlsRequest.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
namespace Myriad.Rest.Types.Requests;
|
||||
|
||||
public record RefreshUrlsRequest(string[] AttachmentUrls);
|
||||
11
Myriad/Types/RefreshedUrl.cs
Normal file
11
Myriad/Types/RefreshedUrl.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
namespace Myriad.Types;
|
||||
|
||||
public record RefreshedUrlsResponse
|
||||
{
|
||||
public record RefreshedUrl
|
||||
{
|
||||
public string Original;
|
||||
public string Refreshed;
|
||||
}
|
||||
public RefreshedUrl[] RefreshedUrls;
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue