mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04: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:
@@ -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
|
||||||
|
|
||||||
|
@@ -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));
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
var current = _repeaterQueue.First;
|
|
||||||
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,14 +124,24 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
rep.UpdateNextTime();
|
UpdatePosition(rep);
|
||||||
AddToQueue(rep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdatePosition(RunningRepeater rep)
|
||||||
|
{
|
||||||
|
lock (_queueLocker)
|
||||||
|
{
|
||||||
|
rep.UpdateNextTime();
|
||||||
|
_repeaterQueue.Remove(rep);
|
||||||
|
AddToQueue(rep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> TriggerExternal(ulong guildId, int index)
|
public async Task<bool> TriggerExternal(ulong guildId, int index)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
using var uow = _db.GetDbContext();
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user