Merge pull request #24 from Bubuni-Team/feature/sticker2png

Feature/sticker2png
This commit is contained in:
Andriy
2023-01-14 15:35:46 +02:00
committed by GitHub
5 changed files with 78 additions and 1 deletions
+1
View File
@@ -18,6 +18,7 @@ COPY ./modules/Reputation/*.csproj ./modules/Reputation/
COPY ./modules/ContentStore/*.csproj ./modules/ContentStore/
COPY ./modules/DebugTools/*.csproj ./modules/DebugTools/
COPY ./modules/CodeWatcher/*.csproj ./modules/CodeWatcher/
COPY ./modules/StickerTools/*.csproj ./modules/StickerTools/
RUN dotnet restore Kruzya.TelegramBot.sln
# Copy all project files
+8 -1
View File
@@ -31,7 +31,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContentStore", "modules\Con
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DebugTools", "modules\DebugTools\DebugTools.csproj", "{B95C9180-4893-4A33-BF43-AB2EE998650C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeWatcher", "modules\CodeWatcher\CodeWatcher.csproj", "{DEF70068-93E5-4198-8CED-4B3D8AE65162}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeWatcher", "modules\CodeWatcher\CodeWatcher.csproj", "{DEF70068-93E5-4198-8CED-4B3D8AE65162}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StickerTools", "modules\StickerTools\StickerTools.csproj", "{1D4FE1FA-F7FB-4F9E-95A3-EE761F29B159}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -95,6 +97,10 @@ Global
{DEF70068-93E5-4198-8CED-4B3D8AE65162}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEF70068-93E5-4198-8CED-4B3D8AE65162}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEF70068-93E5-4198-8CED-4B3D8AE65162}.Release|Any CPU.Build.0 = Release|Any CPU
{1D4FE1FA-F7FB-4F9E-95A3-EE761F29B159}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D4FE1FA-F7FB-4F9E-95A3-EE761F29B159}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D4FE1FA-F7FB-4F9E-95A3-EE761F29B159}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D4FE1FA-F7FB-4F9E-95A3-EE761F29B159}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -112,6 +118,7 @@ Global
{4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
{B95C9180-4893-4A33-BF43-AB2EE998650C} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
{DEF70068-93E5-4198-8CED-4B3D8AE65162} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
{1D4FE1FA-F7FB-4F9E-95A3-EE761F29B159} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5BA73C3B-D5FC-4942-9091-504325CDC308}
+36
View File
@@ -0,0 +1,36 @@
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);
}
}
+10
View File
@@ -0,0 +1,10 @@
using Kruzya.TelegramBot.Core;
namespace West.TelegramBot.StickerTools;
public class StickerTools : Module
{
public StickerTools(Core core) : base(core)
{
}
}
+23
View File
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>TelegramBot.StickerTools</AssemblyName>
<RootNamespace>West.TelegramBot.StickerTools</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Core.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Delete Files="$(OutDir)\TelegramBot.dll" />
</Target>
</Project>