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
+41 -2
View File
@@ -4,14 +4,22 @@ using System.Collections.Generic;
using System.Threading.Tasks;
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.Configuration;
using Microsoft.Extensions.Logging;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace West.TelegramBot.ChatManagement.Handler
{
public class Reputation : ManagementHandler
{
private readonly UserService _userService;
private readonly ILogger _logger;
private static readonly List<string> RepUpChars = new()
{
"+",
@@ -22,7 +30,6 @@ namespace West.TelegramBot.ChatManagement.Handler
"👍🏿",
"👍🏻"
};
private static readonly List<string> RepDownChars = new()
{
"-",
@@ -34,7 +41,11 @@ namespace West.TelegramBot.ChatManagement.Handler
"👎🏻"
};
public Reputation(CoreContext db) : base(db) { }
public Reputation(CoreContext db, UserService userService, ILogger<Reputation> logger) : base(db)
{
_userService = userService;
_logger = logger;
}
[Command("whois", CommandParseMode.Both)]
public async Task HandleWhois()
@@ -96,7 +107,35 @@ namespace West.TelegramBot.ChatManagement.Handler
$"{action} репутацию </code>{receiver.ToHtml()}<code>({repCount})</code>");
}
}
[ParametrizedCommand(InChat.Public, "setrep", CommandParseMode.Both)]
public async Task HandleSetRep(int reputation)
{
if (!_userService.IsUserSuper(From))
{
_logger.LogDebug("{User} attempted to call /setrep in {Chat}", From, Chat.Title);
return;
}
if (RepliedUser == null || RepliedUser.IsBot)
{
return;
}
var opt = await GetReputationOption(RepliedUser);
opt.SetValue(reputation);
Db.MarkAsModified(opt);
await Reply(
new HtmlString()
.Code("Пользователю ")
.UserMention(RepliedUser)
.Code($" установлена репутация: {reputation}")
.ToString()
);
}
private async Task<int> GetUserReputation(User user)
{
return (await GetReputationOption(user)).GetValue<int>();