Animation trigger refactoring. BAYAN.

This commit is contained in:
West14
2021-12-29 00:57:37 +02:00
parent df11e1d327
commit ae5d8ade8c
3 changed files with 101 additions and 15 deletions
+21 -15
View File
@@ -3,33 +3,39 @@
using System.Threading.Tasks;
using BotFramework.Attributes;
using BotFramework.Enums;
using Castle.Core.Internal;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot;
namespace West.TelegramBot.ChatManagement.Handler.Fun
{
public class Python : ManagementHandler
public class Python : AbstractAnimationReply
{
[Command(InChat.Public, "setpython", CommandParseMode.Both)]
public async Task HandleSetpython()
protected override string GetAnimationName()
{
var animation = Message?.ReplyToMessage?.Animation;
if (await CanPunish() || animation == null) return;
var pythonFile = await GetPythonFileOption();
pythonFile.SetValue(animation.FileId);
Db.MarkAsModified(pythonFile);
return "python";
}
[Command(InChat.Public, "setpython", CommandParseMode.Both)]
public async Task HandleSetPython()
{
await HandleSetAnimation();
}
[Message(InChat.Public, "(?i)питон|пайтон|python|путхон", MessageFlag.HasText, true)]
public async Task HandlePython()
{
var pythonFileId = (await GetPythonFileOption()).GetValue(string.Empty);
if (pythonFileId.IsNullOrEmpty()) return;
// var cmdEntity = Message?.Entities?.Find(e => e.Type == MessageEntityType.BotCommand);
// if (cmdEntity is { Length: > 0 })
// {
// return;
// }
await Bot.SendAnimationAsync(Chat.Id, pythonFileId, replyToMessageId: Message?.MessageId);
if (Message!.Text!.Contains("/setpython"))
{
return;
}
await HandleAnimation();
}
private async Task<BotUserValue> GetPythonFileOption()