2023-01-13 00:58:12 +02:00
|
|
|
using BotFramework;
|
|
|
|
|
using BotFramework.Attributes;
|
|
|
|
|
using BotFramework.Enums;
|
|
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
|
using Telegram.Bot;
|
|
|
|
|
using Telegram.Bot.Types;
|
2023-01-13 01:28:34 +02:00
|
|
|
using Telegram.Bot.Types.Enums;
|
2023-01-13 00:58:12 +02:00
|
|
|
|
2023-01-13 01:28:34 +02:00
|
|
|
namespace West.TelegramBot.StickerTools;
|
2023-01-13 00:58:12 +02:00
|
|
|
|
|
|
|
|
public class Handler : BotEventHandler
|
|
|
|
|
{
|
2023-07-29 01:50:28 +03:00
|
|
|
[Command("png", CommandParseMode.Both)]
|
2023-01-13 00:58:12 +02:00
|
|
|
public async Task Sticker2Png()
|
|
|
|
|
{
|
|
|
|
|
var sticker = RawUpdate.Message?.ReplyToMessage?.Sticker;
|
|
|
|
|
if (sticker == null || sticker.IsAnimated || sticker.IsVideo)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-13 01:28:34 +02:00
|
|
|
|
2025-02-09 17:40:03 +02:00
|
|
|
await Bot.SendChatAction(Chat.Id, ChatAction.UploadDocument);
|
2023-01-13 00:58:12 +02:00
|
|
|
using var file = new MemoryStream();
|
2025-02-09 17:40:03 +02:00
|
|
|
await Bot.GetInfoAndDownloadFile(sticker.FileId, file);
|
2023-01-13 00:58:12 +02:00
|
|
|
file.Position = 0;
|
2023-01-13 01:28:34 +02:00
|
|
|
|
2023-01-13 00:58:12 +02:00
|
|
|
using var img = await Image.LoadAsync(file);
|
|
|
|
|
await file.DisposeAsync();
|
2023-01-13 01:28:34 +02:00
|
|
|
|
2023-01-13 00:58:12 +02:00
|
|
|
using var outfile = new MemoryStream();
|
|
|
|
|
await img.SaveAsPngAsync(outfile);
|
|
|
|
|
outfile.Position = 0;
|
2025-02-09 17:40:03 +02:00
|
|
|
await Bot.SendDocument(Chat.Id, new InputFileStream(outfile, "sticker.png"),
|
|
|
|
|
replyParameters: RawUpdate?.Message?.MessageId);
|
2023-01-13 00:58:12 +02:00
|
|
|
}
|
|
|
|
|
}
|