Skip to content

Commit

Permalink
New coc api error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Feb 27, 2024
1 parent 61ad3cc commit 77ead1c
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions Bot/Clash/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class Coc
{
private const string ClanId = "#2QU2UCJJC"; // 2G8LP8PVV
private static readonly ClashOfClansClient s_client = new(Secrets.s_coc);
private static bool s_inMaintenance;
private static ClashOfClansException? s_exception;
internal static ClanUtil Clan { get; private set; } = new();
internal static event Action<ClanMember, Main>? EventMemberJoined;
internal static event Action<ClanMember, string?>? EventMemberLeft;
Expand All @@ -26,28 +26,22 @@ private static async Task BotReadyAsync()
try
{
await PollAsync();
s_inMaintenance = false;
s_exception = null;
await Task.Delay(10000);
}
catch (ClashOfClansException ex)
{
if (ex.Error.Reason == "inMaintenance")
{
if (!s_inMaintenance)
{
s_inMaintenance = true;
await Dc.SendLogAsync(ex.Error.Message);
}
await Task.Delay(60000);
}
else
if (s_exception == null || s_exception.Error.Reason != ex.Error.Reason || s_exception.Error.Message != ex.Error.Message)
{
s_exception = ex;
await Dc.ExceptionAsync(ex);
}
await Task.Delay(60000);
}
catch (Exception ex)
{
await Dc.ExceptionAsync(ex);
await Task.Delay(60000);
}
}
}
Expand Down

0 comments on commit 77ead1c

Please sign in to comment.