mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Fixes for cleanup all messages
This commit is contained in:
@@ -11,6 +11,7 @@ using Kruzya.TelegramBot.Core.Data;
|
|||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Kruzya.TelegramBot.Core.Service;
|
using Kruzya.TelegramBot.Core.Service;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
|
||||||
@@ -36,6 +37,14 @@ public class Guess : CommonHandler
|
|||||||
[Command(InChat.Public, "guess", CommandParseMode.Both)]
|
[Command(InChat.Public, "guess", CommandParseMode.Both)]
|
||||||
public async Task HandleGuess()
|
public async Task HandleGuess()
|
||||||
{
|
{
|
||||||
|
// Drop user message.
|
||||||
|
_requests.Add(new DeleteRequest
|
||||||
|
{
|
||||||
|
ChatId = Chat.Id,
|
||||||
|
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||||
|
MessageId = Message.MessageId
|
||||||
|
});
|
||||||
|
|
||||||
var cooldownOption = await _db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "guessCooldown");
|
var cooldownOption = await _db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "guessCooldown");
|
||||||
var cooldown = cooldownOption.GetValue<DateTime>();
|
var cooldown = cooldownOption.GetValue<DateTime>();
|
||||||
if (cooldown > DateTime.Now)
|
if (cooldown > DateTime.Now)
|
||||||
@@ -79,14 +88,6 @@ public class Guess : CommonHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_guessCache.SetValue(Chat.Id, guessDict, -1);
|
_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)]
|
[Update(InChat.Public, UpdateFlag.CallbackQuery)]
|
||||||
@@ -157,4 +158,20 @@ public class Guess : CommonHandler
|
|||||||
MessageId = (int) messageId
|
MessageId = (int) messageId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
_requests.Add(new DeleteRequest
|
||||||
|
{
|
||||||
|
ChatId = Chat.Id,
|
||||||
|
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||||
|
MessageId = message.MessageId
|
||||||
|
});
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,14 @@ public class Roll : CommonHandler
|
|||||||
cd
|
cd
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Drop user message.
|
||||||
|
_requests.Add(new DeleteRequest
|
||||||
|
{
|
||||||
|
ChatId = Chat.Id,
|
||||||
|
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||||
|
MessageId = Message.MessageId
|
||||||
|
});
|
||||||
|
|
||||||
if (cd > DateTime.Now)
|
if (cd > DateTime.Now)
|
||||||
{
|
{
|
||||||
await Reply($"Следующее использование через {cd - DateTime.Now:hh\\:mm\\:ss}.");
|
await Reply($"Следующее использование через {cd - DateTime.Now:hh\\:mm\\:ss}.");
|
||||||
|
|||||||
Reference in New Issue
Block a user