#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 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 GetAnimationFileOption() { return await Db.UserValues.FindOrCreateOption(Chat.Id, $"{GetAnimationName()}File"); } protected AbstractAnimationReply(CoreContext db) : base(db) {} } }