diff --git a/Dockerfile b/Dockerfile index 66f18ff..9e9a18e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Kruzya.TelegramBot.sln b/Kruzya.TelegramBot.sln index 3a2ccca..3dc09f6 100644 --- a/Kruzya.TelegramBot.sln +++ b/Kruzya.TelegramBot.sln @@ -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} diff --git a/modules/StickerTools/Handler.cs b/modules/StickerTools/Handler.cs new file mode 100644 index 0000000..8f7710a --- /dev/null +++ b/modules/StickerTools/Handler.cs @@ -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); + } +} \ No newline at end of file diff --git a/modules/StickerTools/StickerTools.cs b/modules/StickerTools/StickerTools.cs new file mode 100644 index 0000000..f49f171 --- /dev/null +++ b/modules/StickerTools/StickerTools.cs @@ -0,0 +1,10 @@ +using Kruzya.TelegramBot.Core; + +namespace West.TelegramBot.StickerTools; + +public class StickerTools : Module +{ + public StickerTools(Core core) : base(core) + { + } +} diff --git a/modules/StickerTools/StickerTools.csproj b/modules/StickerTools/StickerTools.csproj new file mode 100644 index 0000000..85f4c55 --- /dev/null +++ b/modules/StickerTools/StickerTools.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + TelegramBot.StickerTools + West.TelegramBot.StickerTools + + + + + + + + + + + + + + +