From 82129d8006571beb0c7da8477d28b76b54bbf319 Mon Sep 17 00:00:00 2001 From: Andriy <30056636+West14@users.noreply.github.com> Date: Wed, 14 Dec 2022 12:31:53 +0200 Subject: [PATCH] [entertainment] add /reset_roll command --- modules/Entertainment/Handler/Roll.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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