From 7d8895850ad350e74995bd15bca3e10569d55fa6 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Tue, 28 Apr 2020 20:10:18 +0200 Subject: [PATCH] Example for a Join/Leave Messages delete Bot --- Examples/JoinHiderBot/JoinHiderBot.csproj | 12 ++++++++ Examples/JoinHiderBot/Program.cs | 19 ++++++++++++ .../JoinHiderBot/forms/GroupManageForm.cs | 25 ++++++++++++++++ Examples/JoinHiderBot/forms/Start.cs | 29 +++++++++++++++++++ TelegramBotFramework.sln | 7 +++++ 5 files changed, 92 insertions(+) create mode 100644 Examples/JoinHiderBot/JoinHiderBot.csproj create mode 100644 Examples/JoinHiderBot/Program.cs create mode 100644 Examples/JoinHiderBot/forms/GroupManageForm.cs create mode 100644 Examples/JoinHiderBot/forms/Start.cs diff --git a/Examples/JoinHiderBot/JoinHiderBot.csproj b/Examples/JoinHiderBot/JoinHiderBot.csproj new file mode 100644 index 0000000..f45b9ca --- /dev/null +++ b/Examples/JoinHiderBot/JoinHiderBot.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/Examples/JoinHiderBot/Program.cs b/Examples/JoinHiderBot/Program.cs new file mode 100644 index 0000000..e3c2ec5 --- /dev/null +++ b/Examples/JoinHiderBot/Program.cs @@ -0,0 +1,19 @@ +using System; + +namespace JoinHiderBot +{ + class Program + { + static void Main(string[] args) + { + + String apiKey = ""; + + var bot = new TelegramBotBase.BotBase(apiKey); + + bot.Start(); + + Console.ReadLine(); + } + } +} diff --git a/Examples/JoinHiderBot/forms/GroupManageForm.cs b/Examples/JoinHiderBot/forms/GroupManageForm.cs new file mode 100644 index 0000000..3e6cc2a --- /dev/null +++ b/Examples/JoinHiderBot/forms/GroupManageForm.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using TelegramBotBase.Args; +using TelegramBotBase.Form; + +namespace JoinHiderBot.forms +{ + public class GroupManageForm : GroupForm + { + + public override async Task OnMemberChanges(MemberChangeEventArgs e) + { + if (e.Type != Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded && e.Type != Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft) + return; + + + var m = e.Result.Message; + + await this.Device.DeleteMessage(m); + } + + } +} diff --git a/Examples/JoinHiderBot/forms/Start.cs b/Examples/JoinHiderBot/forms/Start.cs new file mode 100644 index 0000000..aef4c7d --- /dev/null +++ b/Examples/JoinHiderBot/forms/Start.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using TelegramBotBase.Base; +using TelegramBotBase.Form; + +namespace JoinHiderBot.forms +{ + public class Start : SplitterForm + { + public override async Task Open(MessageResult e) + { + await this.Device.Send("This bot works only in groups."); + + return true; + } + + public override async Task OpenGroup(MessageResult e) + { + var gmf = new GroupManageForm(); + + await this.NavigateTo(gmf); + + return true; + } + + } +} diff --git a/TelegramBotFramework.sln b/TelegramBotFramework.sln index c4f75b1..f14d7d4 100644 --- a/TelegramBotFramework.sln +++ b/TelegramBotFramework.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{BF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemCommandsBot", "Examples\SystemCommandsBot\SystemCommandsBot.csproj", "{FC484952-3060-4F87-9809-4CD66D6961C0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JoinHiderBot", "Examples\JoinHiderBot\JoinHiderBot.csproj", "{E804B9E5-7ACC-49D3-9253-806766C1D9A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,12 +36,17 @@ Global {FC484952-3060-4F87-9809-4CD66D6961C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC484952-3060-4F87-9809-4CD66D6961C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC484952-3060-4F87-9809-4CD66D6961C0}.Release|Any CPU.Build.0 = Release|Any CPU + {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E804B9E5-7ACC-49D3-9253-806766C1D9A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {FC484952-3060-4F87-9809-4CD66D6961C0} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5} + {E804B9E5-7ACC-49D3-9253-806766C1D9A5} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {59CB40E1-9FA7-4867-A56F-4F418286F057}