mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
#nullable enable
|
|
|
|
using System.Threading.Tasks;
|
|
using Castle.Core.Internal;
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
using Telegram.Bot;
|
|
|
|
namespace West.TelegramBot.ChatManagement.Handler.Fun
|
|
{
|
|
public abstract class AbstractAnimationReply : ManagementHandler
|
|
{
|
|
protected abstract string GetAnimationName();
|
|
|
|
protected async Task HandleSetAnimation()
|
|
{
|
|
var animation = Message?.ReplyToMessage?.Animation;
|
|
if (await CanPunish() || animation == null) return;
|
|
|
|
var animationFileOption = await GetAnimationFileOption();
|
|
animationFileOption.SetValue(animation.FileId);
|
|
Db.MarkAsModified(animationFileOption);
|
|
}
|
|
|
|
protected async Task<bool> HandleAnimation(int? replyToMessageId = null)
|
|
{
|
|
var anumationFileId = (await GetAnimationFileOption()).GetValue(string.Empty);
|
|
if (anumationFileId.IsNullOrEmpty()) return false;
|
|
|
|
await Bot.SendAnimationAsync(Chat.Id, anumationFileId,
|
|
replyToMessageId: replyToMessageId ?? Message?.MessageId);
|
|
return true;
|
|
}
|
|
|
|
private async Task<BotUserValue> GetAnimationFileOption()
|
|
{
|
|
return await Db.UserValues.FindOrCreateOption(Chat.Id, $"{GetAnimationName()}File");
|
|
}
|
|
|
|
protected AbstractAnimationReply(CoreContext db) : base(db) {}
|
|
}
|
|
} |