- Possible fix for .repeat bug

- Slight adjustment for repeater logic
  - Timer should no longer increase on some repeaters
  - Repeaters should no longer have periods when they're missing from the list
This commit is contained in:
Kwoth
2021-09-15 23:18:08 +02:00
parent ed039977c2
commit d2d0cb9e03
4 changed files with 40 additions and 11 deletions

View File

@@ -4,7 +4,11 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
## Unreleased ## Unreleased
### Fixed
- Possible fix for `.repeat` bug
- Slight adjustment for repeater logic
- Timer should no longer increase on some repeaters
- Repeaters should no longer have periods when they're missing from the list
## [3.0.3] - 15.09.2021 ## [3.0.3] - 15.09.2021

View File

@@ -183,7 +183,9 @@ namespace NadekoBot.Modules.Utility
private string GetRepeaterInfoString(RunningRepeater runner) private string GetRepeaterInfoString(RunningRepeater runner)
{ {
var intervalString = Format.Bold(runner.Repeater.Interval.ToPrettyStringHM()); var intervalString = Format.Bold(runner.Repeater.Interval.ToPrettyStringHM());
var executesIn = runner.NextTime - DateTime.UtcNow; var executesIn = runner.NextTime < DateTime.UtcNow
? TimeSpan.Zero
: runner.NextTime - DateTime.UtcNow;
var executesInString = Format.Bold(executesIn.ToPrettyStringHM()); var executesInString = Format.Bold(executesIn.ToPrettyStringHM());
var message = Format.Sanitize(runner.Repeater.Message.TrimTo(50)); var message = Format.Sanitize(runner.Repeater.Message.TrimTo(50));

View File

@@ -76,7 +76,9 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
// because repeaters might've been modified meanwhile // because repeaters might've been modified meanwhile
if (timeout > TimeSpan.Zero) if (timeout > TimeSpan.Zero)
{ {
await Task.Delay(timeout); await Task.Delay(timeout > TimeSpan.FromMinutes(1)
? TimeSpan.FromMinutes(1)
: timeout);
continue; continue;
} }
@@ -84,16 +86,17 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
var now = DateTime.UtcNow + TimeSpan.FromSeconds(3); var now = DateTime.UtcNow + TimeSpan.FromSeconds(3);
var toExecute = new List<RunningRepeater>(); var toExecute = new List<RunningRepeater>();
while (true)
{
lock (_repeaterQueue) lock (_repeaterQueue)
{ {
var current = _repeaterQueue.First; var current = _repeaterQueue.First;
while (true)
{
if (current is null || current.Value.NextTime > now) if (current is null || current.Value.NextTime > now)
break; break;
toExecute.Add(current.Value); toExecute.Add(current.Value);
_repeaterQueue.RemoveFirst(); current = current.Next;
} }
} }
@@ -121,13 +124,23 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
{ {
if (rep.ErrorCount >= 10) if (rep.ErrorCount >= 10)
{ {
RemoveFromQueue(rep.Repeater.Id);
await RemoveRepeaterInternal(rep.Repeater); await RemoveRepeaterInternal(rep.Repeater);
return; return;
} }
UpdatePosition(rep);
}
private void UpdatePosition(RunningRepeater rep)
{
lock (_queueLocker)
{
rep.UpdateNextTime(); rep.UpdateNextTime();
_repeaterQueue.Remove(rep);
AddToQueue(rep); AddToQueue(rep);
} }
}
public async Task<bool> TriggerExternal(ulong guildId, int index) public async Task<bool> TriggerExternal(ulong guildId, int index)
{ {

View File

@@ -92,5 +92,15 @@ namespace NadekoBot.Modules.Utility.Services
var initialIntervalMultiplier = 1 - (triggerCount - Math.Truncate(triggerCount)); var initialIntervalMultiplier = 1 - (triggerCount - Math.Truncate(triggerCount));
return DateTime.UtcNow + (Repeater.Interval * initialIntervalMultiplier); return DateTime.UtcNow + (Repeater.Interval * initialIntervalMultiplier);
} }
public override bool Equals(object? obj)
{
return obj is RunningRepeater rr && rr.Repeater.Id == this.Repeater.Id;
}
public override int GetHashCode()
{
return this.Repeater.Id;
}
} }
} }