Assorted improvements.

- Add UserService.
- Add "setrep" command.
- Rename confusing methods and variables in AbstractAnimationHandler.
- Change Bayan cooldown to Zero.
- Add crappy "cooldowns" command.
This commit is contained in:
West14
2022-01-04 17:45:06 +02:00
parent 8717ef9db9
commit 740527d827
7 changed files with 144 additions and 12 deletions
+60
View File
@@ -0,0 +1,60 @@
#nullable enable
using System;
using System.Threading.Tasks;
using BotFramework;
using BotFramework.Attributes;
using BotFramework.Enums;
using BotFramework.Utils;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Kruzya.TelegramBot.Core.Service;
using Microsoft.Extensions.Logging;
using Telegram.Bot;
using Telegram.Bot.Types.Enums;
namespace West.Entertainment.Handler
{
public class Common : BotEventHandler
{
private readonly UserService _userService;
private readonly ILogger _logger;
private readonly CoreContext _db;
public Common(CoreContext db, ILogger<Common> logger, UserService userService)
{
_db = db;
_logger = logger;
_userService = userService;
}
[Command(InChat.Public, "cooldowns", CommandParseMode.Both)]
public async Task HandleCooldowns()
{
if (!_userService.IsUserSuper(From))
{
_logger.LogDebug("{User} attempted to call /cooldowns in \"{Chat}\"", From, Chat.Title);
return;
}
var cds = new[] { "python", "javascript" };
var msg = new HtmlString().Bold("Кулдауны:").Br();
foreach (var cd in cds)
{
var opt = await _db.UserValues.FindOption(Chat.Id, $"{cd}NextUse");
var val = opt.GetValue<DateTime>();
if (val == default)
{
continue;
}
msg.Text($"{cd}: ")
.Code((val - DateTime.Now).Duration().ToString())
.Br();
}
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), ParseMode.Html);
}
}
}