mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
More PeriodicTimer's instead of System.Threading.Timers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable disable
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
using NadekoBot.Modules.Games.Common.Acrophobia;
|
||||
using NadekoBot.Modules.Games.Common.Nunchi;
|
||||
@@ -8,7 +9,7 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Services;
|
||||
|
||||
public class GamesService : INService
|
||||
public class GamesService : INService, IReadyExecutor
|
||||
{
|
||||
private const string TYPING_ARTICLES_PATH = "data/typing_articles3.json";
|
||||
|
||||
@@ -29,7 +30,6 @@ public class GamesService : INService
|
||||
public AsyncLazy<RatingTexts> Ratings { get; }
|
||||
private readonly GamesConfigService _gamesConfig;
|
||||
|
||||
private readonly Timer _t;
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly IMemoryCache _8BallCache;
|
||||
private readonly Random _rng;
|
||||
@@ -46,15 +46,6 @@ public class GamesService : INService
|
||||
Ratings = new(GetRatingTexts);
|
||||
_rng = new NadekoRandom();
|
||||
|
||||
//girl ratings
|
||||
_t = new(_ =>
|
||||
{
|
||||
GirlRatings.Clear();
|
||||
},
|
||||
null,
|
||||
TimeSpan.FromDays(1),
|
||||
TimeSpan.FromDays(1));
|
||||
|
||||
try
|
||||
{
|
||||
TypingArticles = JsonConvert.DeserializeObject<List<TypingArticle>>(File.ReadAllText(TYPING_ARTICLES_PATH));
|
||||
@@ -66,6 +57,16 @@ public class GamesService : INService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
// reset rating once a day
|
||||
using var timer = new PeriodicTimer(TimeSpan.FromDays(1));
|
||||
while (await timer.WaitForNextTickAsync())
|
||||
{
|
||||
GirlRatings.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<RatingTexts> GetRatingTexts()
|
||||
{
|
||||
using var http = _httpFactory.CreateClient();
|
||||
|
Reference in New Issue
Block a user