Files
telegram-bot/modules/StickerTools/Handler.cs
T
2023-01-13 00:58:12 +02:00

36 lines
1.1 KiB
C#

using BotFramework;
using BotFramework.Attributes;
using BotFramework.Enums;
using SixLabors.ImageSharp;
using Telegram.Bot.Types.Enums;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace StickerTools;
public class Handler : BotEventHandler
{
[Command(InChat.All, "png", CommandParseMode.Both)]
public async Task Sticker2Png()
{
var sticker = RawUpdate.Message?.ReplyToMessage?.Sticker;
if (sticker == null || sticker.IsAnimated || sticker.IsVideo)
{
return;
}
await Bot.SendChatActionAsync(Chat.Id, ChatAction.UploadDocument);
using var file = new MemoryStream();
await Bot.GetInfoAndDownloadFileAsync(sticker.FileId, file);
file.Position = 0;
using var img = await Image.LoadAsync(file);
await file.DisposeAsync();
using var outfile = new MemoryStream();
await img.SaveAsPngAsync(outfile);
outfile.Position = 0;
await Bot.SendDocumentAsync(Chat.Id, new InputFile(outfile, "sticker.png"), replyToMessageId: RawUpdate?.Message?.MessageId);
}
}