mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
Make TimeoutManager exit early on messaged user
This commit is contained in:
parent
a4f94428ce
commit
a354305334
@ -98,9 +98,10 @@ namespace JetKarmaBot
|
|||||||
void InitChain(IContainer c)
|
void InitChain(IContainer c)
|
||||||
{
|
{
|
||||||
Chain = new RequestChain();
|
Chain = new RequestChain();
|
||||||
|
Chain.Add(c.GetInstance<TimeoutManager.PreDbThrowout>());
|
||||||
Chain.Add(c.GetInstance<DatabaseHandler>());
|
Chain.Add(c.GetInstance<DatabaseHandler>());
|
||||||
Chain.Add(Timeout);
|
Chain.Add(Timeout);
|
||||||
Chain.Add(new SaveData());
|
Chain.Add(c.GetInstance<SaveData>());
|
||||||
Chain.Add(Commands);
|
Chain.Add(Commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,26 @@ namespace JetKarmaBot.Services.Handling
|
|||||||
[Singleton]
|
[Singleton]
|
||||||
public class TimeoutManager : IRequestHandler
|
public class TimeoutManager : IRequestHandler
|
||||||
{
|
{
|
||||||
|
public class PreDbThrowout : IRequestHandler
|
||||||
|
{
|
||||||
|
public TimeoutManager Timeout { get; }
|
||||||
|
public PreDbThrowout(TimeoutManager timeout)
|
||||||
|
{
|
||||||
|
Timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next)
|
||||||
|
{
|
||||||
|
int uid = ctx.EventArgs.Message.From.Id;
|
||||||
|
if (Timeout.TimeoutCache.TryGetValue(uid, out var stats))
|
||||||
|
{
|
||||||
|
DateTime debtLimit = DateTime.Now.AddSeconds(Timeout.cfg.Timeout.DebtLimitSeconds);
|
||||||
|
if (debtLimit < stats.CooldownDate && stats.TimeoutMessaged)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await next(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
public struct TimeoutStats
|
public struct TimeoutStats
|
||||||
{
|
{
|
||||||
public DateTime CooldownDate;
|
public DateTime CooldownDate;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user