[sticker-tools] init module

This commit is contained in:
Andriy
2023-01-13 00:58:12 +02:00
parent 55a4569a4a
commit 7598f77637
4 changed files with 71 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
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);
}
}