Skip to content

Commit

Permalink
Only check each 12h if the discord channel permissions are set (#210)
Browse files Browse the repository at this point in the history
* Update TimerServiceHost.cs

* Also set the timestamp correctly
  • Loading branch information
Sella-GH authored Nov 3, 2024
1 parent 86a3dd2 commit 4ffa963
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/AzzyBot.Bot/Services/TimerServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class TimerServiceHost(ILogger<TimerServiceHost> logger, AzuraChec
private readonly Task _completedTask = Task.CompletedTask;
private DateTime _lastAzzyBotUpdateCheck = DateTime.MinValue;
private DateTime _lastCleanup = DateTime.MinValue;
private DateTime _lastChannelPermissionCheck = DateTime.MinValue;
private Timer? _timer;
private bool _firstRun = true;

Expand Down Expand Up @@ -70,19 +71,19 @@ private async void TimerTimeoutAsync(object? o)
if (now - _lastAzzyBotUpdateCheck >= TimeSpan.FromHours(5.98))
{
_logger.GlobalTimerCheckForUpdates();
_lastAzzyBotUpdateCheck = now;

await _updaterService.CheckForAzzyUpdatesAsync();
_lastAzzyBotUpdateCheck = now;
}

IAsyncEnumerable<GuildEntity> guilds = _dbActions.GetGuildsAsync(loadEverything: true);
int guildCount = _discordBotService.GetDiscordGuilds.Count;
int delay = 5 + guildCount;

if (!_firstRun)
if (!_firstRun && now - _lastChannelPermissionCheck >= TimeSpan.FromHours(11.98))
{
_logger.GlobalTimerCheckForChannelPermissions(guildCount);
await _discordBotService.CheckPermissionsAsync(guilds);
_lastChannelPermissionCheck = now;
}

await _azuraChecksBackgroundService.QueueInstancePingAsync(guilds, now);
Expand Down

0 comments on commit 4ffa963

Please sign in to comment.