More PeriodicTimer's instead of System.Threading.Timers

This commit is contained in:
Kwoth
2022-02-02 06:28:33 +01:00
parent b4a493971a
commit 41653a317b
10 changed files with 124 additions and 110 deletions

View File

@@ -29,7 +29,7 @@ public sealed class PlayingRotateService : INService, IReadyExecutor
public async Task OnReadyAsync()
{
var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
using var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
var index = 0;
while (await timer.WaitForNextTickAsync())
{

View File

@@ -21,8 +21,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
private readonly GuildTimezoneService _tz;
private readonly IEmbedBuilderService _eb;
private readonly IMemoryCache _memoryCache;
private readonly Timer _clearTimer;
private readonly ConcurrentHashSet<ulong> _ignoreMessageIds = new();
public LogCommandService(
@@ -80,21 +79,25 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
_prot.OnAntiProtectionTriggered += TriggeredAntiProtection;
_clearTimer = new(_ =>
{
_ignoreMessageIds.Clear();
},
null,
TimeSpan.FromHours(1),
TimeSpan.FromHours(1));
#endif
}
public async Task OnReadyAsync()
public Task OnReadyAsync()
=> Task.WhenAll(PresenceUpdateTask(), IgnoreMessageIdsClearTask());
private async Task IgnoreMessageIdsClearTask()
{
using var timer = new PeriodicTimer(TimeSpan.FromHours(1));
while (await timer.WaitForNextTickAsync())
{
_ignoreMessageIds.Clear();
}
}
private async Task PresenceUpdateTask()
{
#if !GLOBAL_NADEKO
var timer = new PeriodicTimer(TimeSpan.FromSeconds(15));
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(15));
while (await timer.WaitForNextTickAsync())
{
try
@@ -105,6 +108,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
{
if (!((SocketGuild)key.Guild).CurrentUser.GetPermissions(key).SendMessages)
return Task.CompletedTask;
if (PresenceUpdates.TryRemove(key, out var msgs))
{
var title = GetText(key.Guild, strs.presence_updates);

View File

@@ -36,7 +36,7 @@ public class UserPunishService : INService, IReadyExecutor
if (_client.ShardId != 0)
return;
var expiryTimer = new PeriodicTimer(TimeSpan.FromHours(12));
using var expiryTimer = new PeriodicTimer(TimeSpan.FromHours(12));
do
{
try