mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Add cooldown logging.
This commit is contained in:
@@ -7,6 +7,7 @@ using BotFramework;
|
|||||||
using Castle.Core.Internal;
|
using Castle.Core.Internal;
|
||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
{
|
{
|
||||||
private readonly CoreContext _db;
|
private readonly CoreContext _db;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private const int Cooldown = 30;
|
private const int Cooldown = 30;
|
||||||
|
|
||||||
protected Message? Message => RawUpdate.Message;
|
protected Message? Message => RawUpdate.Message;
|
||||||
@@ -27,9 +30,10 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractAnimationReply(CoreContext db)
|
protected AbstractAnimationReply(CoreContext db, ILogger logger)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract string GetAnimationName();
|
protected abstract string GetAnimationName();
|
||||||
@@ -54,9 +58,15 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
|
|
||||||
if (animationFileId.IsNullOrEmpty()
|
if (animationFileId.IsNullOrEmpty()
|
||||||
|| !AnimationMatch.IsMatch(Message!.Text!.ToLower())
|
|| !AnimationMatch.IsMatch(Message!.Text!.ToLower())
|
||||||
|| !CanHandle()
|
|| !CanHandle()) return false;
|
||||||
|| lastUseOption.GetValue<DateTime>() > DateTime.Now) return false;
|
|
||||||
|
|
||||||
|
if (lastUseOption.GetValue<DateTime>() > DateTime.Now)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("{Name} is on cooldown for Chat {ChatTitle}. Will be available at {Time}",
|
||||||
|
GetAnimationName(), Chat.Title, lastUseOption.GetValue<DateTime>());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
await Bot.SendAnimationAsync(Chat.Id, animationFileId,
|
await Bot.SendAnimationAsync(Chat.Id, animationFileId,
|
||||||
replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
|
replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ using System.Threading.Tasks;
|
|||||||
using BotFramework.Attributes;
|
using BotFramework.Attributes;
|
||||||
using BotFramework.Enums;
|
using BotFramework.Enums;
|
||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler.Fun
|
namespace West.Entertainment.Handler.Fun
|
||||||
{
|
{
|
||||||
public class Bayan : AbstractAnimationReply
|
public class Bayan : AbstractAnimationReply
|
||||||
{
|
{
|
||||||
public Bayan(CoreContext db) : base(db) { }
|
public Bayan(CoreContext db, ILogger<Bayan> logger) : base(db, logger) { }
|
||||||
|
|
||||||
protected override Regex AnimationMatch
|
protected override Regex AnimationMatch
|
||||||
=> new("^баян$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
=> new("^баян$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
|||||||
using BotFramework.Attributes;
|
using BotFramework.Attributes;
|
||||||
using BotFramework.Enums;
|
using BotFramework.Enums;
|
||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler.Fun
|
namespace West.Entertainment.Handler.Fun
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,6 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
=> await base.HandleAnimation();
|
=> await base.HandleAnimation();
|
||||||
|
|
||||||
|
|
||||||
public Python(CoreContext db) : base(db) { }
|
public Python(CoreContext db, ILogger<Python> logger) : base(db, logger) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user