mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2024-10-02 20:13:13 +00:00
- 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:
parent
ed039977c2
commit
d2d0cb9e03
4 changed files with 40 additions and 11 deletions
|
@ -4,7 +4,11 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
|||
|
||||
## 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
|
||||
|
||||
|
|
|
@ -183,7 +183,9 @@ namespace NadekoBot.Modules.Utility
|
|||
private string GetRepeaterInfoString(RunningRepeater runner)
|
||||
{
|
||||
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 message = Format.Sanitize(runner.Repeater.Message.TrimTo(50));
|
||||
|
||||
|
|
|
@ -76,7 +76,9 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
|||
// because repeaters might've been modified meanwhile
|
||||
if (timeout > TimeSpan.Zero)
|
||||
{
|
||||
await Task.Delay(timeout);
|
||||
await Task.Delay(timeout > TimeSpan.FromMinutes(1)
|
||||
? TimeSpan.FromMinutes(1)
|
||||
: timeout);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -84,16 +86,17 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
|||
var now = DateTime.UtcNow + TimeSpan.FromSeconds(3);
|
||||
|
||||
var toExecute = new List<RunningRepeater>();
|
||||
while (true)
|
||||
lock (_repeaterQueue)
|
||||
{
|
||||
lock (_repeaterQueue)
|
||||
var current = _repeaterQueue.First;
|
||||
while (true)
|
||||
{
|
||||
var current = _repeaterQueue.First;
|
||||
|
||||
if (current is null || current.Value.NextTime > now)
|
||||
break;
|
||||
|
||||
toExecute.Add(current.Value);
|
||||
_repeaterQueue.RemoveFirst();
|
||||
current = current.Next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,14 +124,24 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
|||
{
|
||||
if (rep.ErrorCount >= 10)
|
||||
{
|
||||
RemoveFromQueue(rep.Repeater.Id);
|
||||
await RemoveRepeaterInternal(rep.Repeater);
|
||||
return;
|
||||
}
|
||||
|
||||
rep.UpdateNextTime();
|
||||
AddToQueue(rep);
|
||||
|
||||
UpdatePosition(rep);
|
||||
}
|
||||
|
||||
|
||||
private void UpdatePosition(RunningRepeater rep)
|
||||
{
|
||||
lock (_queueLocker)
|
||||
{
|
||||
rep.UpdateNextTime();
|
||||
_repeaterQueue.Remove(rep);
|
||||
AddToQueue(rep);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> TriggerExternal(ulong guildId, int index)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
|
|
@ -92,5 +92,15 @@ namespace NadekoBot.Modules.Utility.Services
|
|||
var initialIntervalMultiplier = 1 - (triggerCount - Math.Truncate(triggerCount));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue