[entertainment] add /reset_roll command

This commit is contained in:
Andriy
2022-12-14 12:31:53 +02:00
parent 2aa54c79d0
commit 82129d8006
+25 -1
View File
@@ -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<Roll> _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<Roll> logger) : base(db)
{
_reputation = reputation;
_userService = userService;
_logger = logger;
}
}