From c90ced6bb9c05a6ff60fcd881754e196e15f9331 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Sun, 29 Sep 2024 02:40:37 +0800 Subject: [PATCH] [Bot] Add interval for trying to send new exception log --- Bot/Clash/Coc.cs | 2 +- Bot/Discord/Dc.cs | 3 ++- Bot/Program.cs | 5 ++++- Bot/Sql/Raid.cs | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Bot/Clash/Coc.cs b/Bot/Clash/Coc.cs index 3ef09a8..b5d4f9a 100644 --- a/Bot/Clash/Coc.cs +++ b/Bot/Clash/Coc.cs @@ -191,10 +191,10 @@ static async Task WaitRaidAsync() // Raid ended Raid[] raids = new Raid[s_raidSeason.Members!.Count]; + long timestamp = ((DateTimeOffset)s_raidSeason.EndTime).ToUnixTimeSeconds(); for (int i = 0; i < s_raidSeason.Members.Count; i++) { ClanCapitalRaidSeasonMember attacker = s_raidSeason.Members[i]; - long timestamp = ((DateTimeOffset)s_raidSeason.EndTime).ToUnixTimeSeconds(); raids[i] = new(timestamp, attacker.Tag, attacker.Attacks); } diff --git a/Bot/Discord/Dc.cs b/Bot/Discord/Dc.cs index 52d118c..46dfc4b 100644 --- a/Bot/Discord/Dc.cs +++ b/Bot/Discord/Dc.cs @@ -129,7 +129,8 @@ internal static async Task NewExceptionLogAsync(Exception ex) // Always waits until the exception is actually sent return await Program.TryUntilAsync( - async () => await s_botLog.SendMessageAsync(s_botApp.Owner.Mention, embed: emb.Build()) + async () => await s_botLog.SendMessageAsync(s_botApp.Owner.Mention, embed: emb.Build()), + msRetryWaitInterval: 5000 ); } diff --git a/Bot/Program.cs b/Bot/Program.cs index 9de5afc..16d5b00 100644 --- a/Bot/Program.cs +++ b/Bot/Program.cs @@ -48,7 +48,8 @@ internal static string GetExceptionStackTraceString(Exception ex) return msg; } - internal static async Task TryUntilAsync(Func> tryFunc, Func? repeatFunc = null) + internal static async Task TryUntilAsync(Func> tryFunc, Func? repeatFunc = null, + int msRetryWaitInterval = 0) { while (true) { @@ -66,6 +67,8 @@ internal static async Task TryUntilAsync(Func> tryFunc, Func { [PrimaryKey, NotNull] public long EndTime { get; set; } = endTime;