From 77ead1cd5c935aa0ed64c4e6ad96b463f6d97af4 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Tue, 27 Feb 2024 23:37:03 +0000 Subject: [PATCH] New coc api error handling --- Bot/Clash/Coc.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Bot/Clash/Coc.cs b/Bot/Clash/Coc.cs index 4e945ce..6043158 100644 --- a/Bot/Clash/Coc.cs +++ b/Bot/Clash/Coc.cs @@ -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? EventMemberJoined; internal static event Action? EventMemberLeft; @@ -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); } } }