Convert autoproxy timeout to use seconds

This commit is contained in:
Ske
2020-12-08 12:57:17 +01:00
parent ab3ccac60f
commit db4e41a232
6 changed files with 36 additions and 25 deletions

View File

@@ -10,7 +10,7 @@ namespace PluralKit.Bot
public class ProxyMatcher
{
private static readonly char AutoproxyEscapeCharacter = '\\';
public static readonly int DefaultLatchExpiryTime = 6;
public static readonly Duration DefaultLatchExpiryTime = Duration.FromHours(6);
private readonly IClock _clock;
private readonly ProxyTagParser _parser;
@@ -79,8 +79,10 @@ namespace PluralKit.Bot
{
if (ctx.LastMessage == null) return true;
if (ctx.LatchTimeout == 0) return false;
var timeout = Duration.FromHours(ctx.LatchTimeout == -1 ? DefaultLatchExpiryTime : ctx.LatchTimeout);
var timeout = ctx.LatchTimeout.HasValue
? Duration.FromSeconds(ctx.LatchTimeout.Value)
: DefaultLatchExpiryTime;
var timestamp = DiscordUtils.SnowflakeToInstant(ctx.LastMessage.Value);
return _clock.GetCurrentInstant() - timestamp > timeout;