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:
@@ -10,6 +10,11 @@ using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Kruzya.TelegramBot.Core.Service;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot;
|
||||
using Kruzya.TelegramBot.Core.AutoDelete;
|
||||
using System.Collections.Concurrent;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Types;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
namespace West.Entertainment.Handler;
|
||||
|
||||
@@ -19,6 +24,7 @@ public class Roll : CommonHandler
|
||||
private readonly ThreadSafeRandom _rng;
|
||||
private readonly IReputation _reputation;
|
||||
private readonly UserService _userService;
|
||||
private readonly ConcurrentBag<DeleteRequest> _requests;
|
||||
|
||||
[Command(InChat.Public, "roll", CommandParseMode.Both)]
|
||||
public async Task HandleRoll()
|
||||
@@ -115,12 +121,28 @@ public class Roll : CommonHandler
|
||||
|
||||
await Bot.SendTextMessageAsync(Chat, $"Positive: {positive}.\nNegative: {negative}");
|
||||
}
|
||||
protected override async Task<Message> Reply(string text)
|
||||
{
|
||||
// TODO: move feature with autocleaning to Core CommonHandler.
|
||||
var message = await Bot.SendTextMessageAsync(Chat.Id, text,
|
||||
replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html);
|
||||
|
||||
public Roll(CoreContext db, IReputation reputation, UserService userService, ILogger<Roll> logger, ThreadSafeRandom rng) : base(db)
|
||||
_requests.Add(new DeleteRequest
|
||||
{
|
||||
ChatId = Chat.Id,
|
||||
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||
MessageId = message.MessageId
|
||||
});
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public Roll(CoreContext db, IReputation reputation, UserService userService, ILogger<Roll> logger, ThreadSafeRandom rng, ConcurrentBag<DeleteRequest> requests) : base(db)
|
||||
{
|
||||
_reputation = reputation;
|
||||
_userService = userService;
|
||||
_logger = logger;
|
||||
_rng = rng;
|
||||
_requests = requests;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user