mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Add autocleanup for Guess and Roll handlers
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.AutoDelete;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Kruzya.TelegramBot.Core.Service;
|
||||
@@ -21,13 +22,15 @@ public class Guess : CommonHandler
|
||||
private readonly ThreadSafeRandom _rng;
|
||||
private readonly IReputation _reputationService;
|
||||
private readonly CoreContext _db;
|
||||
private readonly ConcurrentBag<DeleteRequest> _requests;
|
||||
|
||||
public Guess(IGuessCache guessCache, ThreadSafeRandom rng, IReputation reputationService, CoreContext db) : base(db)
|
||||
public Guess(IGuessCache guessCache, ThreadSafeRandom rng, IReputation reputationService, CoreContext db, ConcurrentBag<DeleteRequest> requests) : base(db)
|
||||
{
|
||||
_guessCache = guessCache;
|
||||
_rng = rng;
|
||||
_reputationService = reputationService;
|
||||
_db = db;
|
||||
_requests = requests;
|
||||
}
|
||||
|
||||
[Command(InChat.Public, "guess", CommandParseMode.Both)]
|
||||
@@ -76,6 +79,14 @@ public class Guess : CommonHandler
|
||||
return;
|
||||
}
|
||||
_guessCache.SetValue(Chat.Id, guessDict, -1);
|
||||
|
||||
// Drop user message.
|
||||
_requests.Add(new DeleteRequest
|
||||
{
|
||||
ChatId = Chat.Id,
|
||||
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||
MessageId = messageId
|
||||
});
|
||||
}
|
||||
|
||||
[Update(InChat.Public, UpdateFlag.CallbackQuery)]
|
||||
@@ -137,5 +148,13 @@ public class Guess : CommonHandler
|
||||
_db.AddOrUpdate(cooldownOption);
|
||||
|
||||
await Bot.EditMessageTextAsync(Chat, (int) messageId, message + postFix, parseMode: ParseMode.Html);
|
||||
|
||||
// Drop bot message.
|
||||
_requests.Add(new DeleteRequest
|
||||
{
|
||||
ChatId = Chat.Id,
|
||||
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||
MessageId = (int) messageId
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user