mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[sticker-tools] init module
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Kruzya.TelegramBot.Core;
|
||||
|
||||
namespace StickerTools;
|
||||
|
||||
public class StickerTools : Module
|
||||
{
|
||||
public StickerTools(Core core) : base(core)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user