mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user