Skip to content

Commit

Permalink
Fix anime subscription spamming 403
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Nov 13, 2024
1 parent 88d0b39 commit 9678f67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Sanara/Module/Utility/AniList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Quickenshtein;
using System.Net;
using System.Text;

namespace Sanara.Module.Utility;
Expand Down Expand Up @@ -77,6 +78,11 @@ public static async Task<AiringSchedule[]> GetAnimeFeedAsync(HttpClient client)
});

var answer = await client.PostAsync("https://graphql.anilist.co", new StringContent(json, Encoding.UTF8, "application/json"));

if (answer.StatusCode == HttpStatusCode.Forbidden) // When API is down, it'll return a 403
{
return Array.Empty<AiringSchedule>();
}
answer.EnsureSuccessStatusCode();

var str = await answer.Content.ReadAsStringAsync();
Expand Down
15 changes: 0 additions & 15 deletions Sanara/Subscription/Impl/AnimeSubscription.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Discord;
using Sanara.Module.Utility;
using System.Xml;

namespace Sanara.Subscription.Impl
{
Expand Down Expand Up @@ -45,20 +44,6 @@ public async Task<FeedItem[]> GetFeedAsync(HttpClient client, int current, bool
public string GetName()
=> "anime";

private static string? GetAttribute(XmlNode node, string name, string? attribute = null)
{
foreach (XmlNode elem in node)
{
if (elem.Name == name)
{
if (attribute == null)
return elem.InnerText;
return elem.Attributes?.GetNamedItem(attribute)?.InnerText;
}
}
return null;
}

private async Task<AiringSchedule[]> GetFeedInternalAsync(HttpClient client)
{
return await AniList.GetAnimeFeedAsync(client);
Expand Down

0 comments on commit 9678f67

Please sign in to comment.