diff --git a/modules/Entertainment/Handler/Roll.cs b/modules/Entertainment/Handler/Roll.cs index 5e8c717..f9d93bd 100644 --- a/modules/Entertainment/Handler/Roll.cs +++ b/modules/Entertainment/Handler/Roll.cs @@ -2,16 +2,20 @@ using BotFramework.Enums; using System.Threading.Tasks; using System; +using System.Linq; using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; using Kruzya.TelegramBot.Core.Service; +using Microsoft.Extensions.Logging; namespace West.Entertainment.Handler; public class Roll : CommonHandler { + private readonly ILogger _logger; private readonly IReputation _reputation; + private readonly UserService _userService; [Command(InChat.Public, "roll", CommandParseMode.Both)] public async Task HandleRoll() @@ -34,8 +38,28 @@ public class Roll : CommonHandler Db.AddOrUpdate(cdOption); } - public Roll(CoreContext db, IReputation reputation) : base(db) + [Command(InChat.Public, "reset_roll", CommandParseMode.Both)] + public async Task HandleResetRoll() + { + if (!_userService.IsUserSuper(From)) + { + _logger.LogWarning("{user} attempted to use super-user command", From.ToLog()); + return; + } + + var cooldownList = Db.UserValues + .Where(q => q.BotUser.ChatId == Chat.Id && q.Name == "rollNextUse"); + + Db.UserValues.RemoveRange(cooldownList); + await Db.SaveChangesAsync(); + + await Reply($"Кулдаун /roll сброшен для чата \"{Chat.Title}\"."); + } + + public Roll(CoreContext db, IReputation reputation, UserService userService, ILogger logger) : base(db) { _reputation = reputation; + _userService = userService; + _logger = logger; } } \ No newline at end of file