mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
f1c4375613
Co-authored-by: voed <voed@i.ua>
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using BotFramework;
|
|
using BotFramework.Attributes;
|
|
using BotFramework.Enums;
|
|
using SixLabors.ImageSharp;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Types;
|
|
using Telegram.Bot.Types.Enums;
|
|
|
|
namespace West.TelegramBot.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);
|
|
}
|
|
} |