-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPoll.cs
44 lines (41 loc) · 1.3 KB
/
Poll.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Discord.Rest;
using Hyperstellar.Discord;
namespace Hyperstellar;
internal sealed class Poll(int msTryInterval, int msExceptionInterval, Func<Task> tryFunc)
{
private Exception? _exception;
private RestUserMessage? _msg;
private int _repeatCount;
internal async Task RunAsync()
{
while (true)
{
try
{
await tryFunc();
_exception = null;
_msg = null;
_repeatCount = 0;
await Task.Delay(msTryInterval);
}
catch (Exception ex)
{
if (_exception == null || _exception.Message != ex.Message || _exception.StackTrace != ex.StackTrace)
{
_exception = ex;
_repeatCount = 0;
_msg = await Dc.NewExceptionLogAsync(ex);
}
else if (_repeatCount < 10)
{
_repeatCount++;
await Program.TryUntilAsync(async () =>
{
await _msg!.ModifyAsync(mp => mp.Content = _msg.Content + "\n" + DateTime.Now.ToString("HH:mm:ss"));
});
}
await Task.Delay(msExceptionInterval);
}
}
}
}