From d2ae08771efa7205daf900452fbf1b59706eb277 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 4 Oct 2021 21:55:41 +0300 Subject: [PATCH 01/57] Fix documentation inaccuracy --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 67379a4..936392b 100644 --- a/README.md +++ b/README.md @@ -169,11 +169,9 @@ public class StartForm : FormBase } - //Gets invoked during Navigation to this form - public override async Task Init(params object[] param) - { - - } + //Gets invoked during Navigation to this form + + //Init() got replaced with event handler //Opened() got replaced with event handler From 8e29652148cf634573e6b9b620b5c0e0a5b07cf7 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 15:39:31 +0200 Subject: [PATCH 02/57] Fixing possible Deadlock in AutoCleanForm --- TelegramBotBase/Form/AutoCleanForm.cs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/TelegramBotBase/Form/AutoCleanForm.cs b/TelegramBotBase/Form/AutoCleanForm.cs index 4acc8ee..7fd9200 100644 --- a/TelegramBotBase/Form/AutoCleanForm.cs +++ b/TelegramBotBase/Form/AutoCleanForm.cs @@ -150,8 +150,15 @@ namespace TelegramBotBase.Form { parallelQuery.ForAll(i => { - Device.DeleteMessage(i).GetAwaiter().GetResult(); - deletedMessages.Add(i); + try + { + Device.DeleteMessage(i).GetAwaiter().GetResult(); + deletedMessages.Add(i); + } + catch (ApiRequestException req) when (req.ErrorCode == 400) + { + deletedMessages.Add(i); + } }); } catch (AggregateException ex) @@ -160,10 +167,10 @@ namespace TelegramBotBase.Form var retryAfterSeconds = ex.InnerExceptions .Where(e => e is ApiRequestException apiEx && apiEx.ErrorCode == 429) - .Max(e =>(int?) ((ApiRequestException)e).Parameters.RetryAfter) ?? 0; + .Max(e => (int?)((ApiRequestException)e).Parameters.RetryAfter) ?? 0; retryAfterTask = Task.Delay(retryAfterSeconds * 1000); } - + //deletedMessages.AsParallel().ForAll(i => Device.OnMessageDeleted(new MessageDeletedEventArgs(i))); oldMessages = oldMessages.Where(x => !deletedMessages.Contains(x)); @@ -183,8 +190,15 @@ namespace TelegramBotBase.Form { parallelQuery.ForAll(i => { - Device.DeleteMessage(i).GetAwaiter().GetResult(); - deletedMessages.Add(i); + try + { + Device.DeleteMessage(i).GetAwaiter().GetResult(); + deletedMessages.Add(i); + } + catch (ApiRequestException req) when (req.ErrorCode == 400) + { + deletedMessages.Add(i); + } }); } catch (AggregateException ex) From a22ede0f4fa982c041bfc62972931c53de45b91c Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 17:25:17 +0200 Subject: [PATCH 03/57] Changing BotBase behaviour to fluent api - removing unecessary constructors from BotBase - removing generics from BotBase - removing generics from SessionBase - adding StartFormFactory interface - adding DefaultStartFormFactory - adding multiple methods to BotBaseBuilder --- TelegramBotBase/BotBase.cs | 86 ++------------ TelegramBotBase/Builder/BotBaseBuilder.cs | 105 ++++++++++++++++++ .../Interfaces/IAPIKeySelectionStage.cs | 17 +++ .../Builder/Interfaces/IBuildingStage.cs | 11 ++ .../Interfaces/INetworkingSelectionStage.cs | 49 ++++++++ .../Interfaces/IStartFormSelectionPage.cs | 34 ++++++ .../Factories/DefaultStartFormFactory.cs | 26 +++++ .../Interfaces/IStartFormFactory.cs | 12 ++ TelegramBotBase/SessionBase.cs | 13 +-- 9 files changed, 271 insertions(+), 82 deletions(-) create mode 100644 TelegramBotBase/Builder/BotBaseBuilder.cs create mode 100644 TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs create mode 100644 TelegramBotBase/Builder/Interfaces/IBuildingStage.cs create mode 100644 TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs create mode 100644 TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs create mode 100644 TelegramBotBase/Factories/DefaultStartFormFactory.cs create mode 100644 TelegramBotBase/Interfaces/IStartFormFactory.cs diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index 9d9c354..9361281 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -20,8 +20,7 @@ namespace TelegramBotBase /// Bot base class for full Device/Context and Messagehandling /// /// - public class BotBase - where T : FormBase + public class BotBase { public MessageClient Client { get; set; } @@ -33,7 +32,7 @@ namespace TelegramBotBase /// /// List of all running/active sessions /// - public SessionBase Sessions { get; set; } + public SessionBase Sessions { get; set; } /// /// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start @@ -65,10 +64,15 @@ namespace TelegramBotBase /// public IStateMachine StateMachine { get; set; } + /// + /// Offers functionality to manage the creation process of the start form. + /// + public IStartFormFactory StartFormFactory { get; set; } + public Dictionary SystemSettings { get; private set; } - private BotBase() + public BotBase() { this.SystemSettings = new Dictionary(); @@ -80,78 +84,10 @@ namespace TelegramBotBase this.BotCommands = new List(); - this.Sessions = new SessionBase(); + this.Sessions = new SessionBase(); this.Sessions.BotBase = this; } - /// - /// Simple start of your Bot with the APIKey - /// - /// - public BotBase(String apiKey, bool initClient = true) : this() - { - this.APIKey = apiKey; - - if (!initClient) - return; - - this.Client = new Base.MessageClient(this.APIKey); - this.Client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); - - this.Sessions.Client = this.Client; - } - - /// - /// Simple start of your Bot with the APIKey and a proxyAdress - /// - /// - /// i.e. https://127.0.0.1:10000 - public BotBase(String apiKey, System.Net.Http.HttpClient proxy) : this(apiKey, false) - { - this.Client = new Base.MessageClient(this.APIKey, proxy); - - this.Sessions.Client = this.Client; - } - - /// - /// Simple start of your Bot with the APIKey and a TelegramBotClient instance. - /// - /// - /// - public BotBase(String apiKey, TelegramBotClient client) : this(apiKey, false) - { - this.Client = new Base.MessageClient(this.APIKey, client); - - this.Sessions.Client = this.Client; - } - - /// - /// Simple start of your Bot with the APIKey and a proxyAdress - /// - /// - /// i.e. https://127.0.0.1:10000 - public BotBase(String apiKey, String proxyBaseAddress) : this(apiKey, false) - { - var url = new Uri(proxyBaseAddress); - - this.Client = new Base.MessageClient(this.APIKey, url); - - this.Sessions.Client = this.Client; - } - - /// - /// Simple start of your Bot with the APIKey and a proxyAdress - /// - /// - /// i.e. 127.0.0.1 - /// i.e. 10000 - public BotBase(String apiKey, String proxyHost, int proxyPort) : this(apiKey, false) - { - this.Client = new Base.MessageClient(this.APIKey, proxyHost, proxyPort); - - this.Sessions.Client = this.Client; - } - /// /// Start your Bot /// @@ -324,7 +260,7 @@ namespace TelegramBotBase DeviceSession ds = e.Device; if (ds == null) { - ds = await this.Sessions.StartSession(e.DeviceId); + ds = await this.Sessions.StartSession(e.DeviceId); e.Device = ds; ds.LastMessage = e.Message; @@ -483,7 +419,7 @@ namespace TelegramBotBase DeviceSession ds = e.Device; if (ds == null) { - ds = await this.Sessions.StartSession(e.DeviceId); + ds = await this.Sessions.StartSession(e.DeviceId); e.Device = ds; } diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs new file mode 100644 index 0000000..c4595f0 --- /dev/null +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using Telegram.Bot; +using TelegramBotBase.Base; +using TelegramBotBase.Builder.Interfaces; +using TelegramBotBase.Form; +using TelegramBotBase.Interfaces; + +namespace TelegramBotBase.Builder +{ + public class BotBaseBuilder : IAPIKeySelectionStage, IStartFormSelectionPage, IBuildingStage, INetworkingSelectionStage + { + + String apiKey = null; + + IStartFormFactory factory = null; + + MessageClient client = null; + + public static IAPIKeySelectionStage Create() + { + return new BotBaseBuilder(); + } + + public IStartFormSelectionPage WithAPIKey(string apiKey) + { + this.apiKey = apiKey; + return this; + } + + public INetworkingSelectionStage WithStartForm(Type startFormClass) + { + this.factory = new Factories.DefaultStartFormFactory(startFormClass); + return this; + } + + public INetworkingSelectionStage WithStartForm() + where T : FormBase, new() + { + this.factory = new Factories.DefaultStartFormFactory(typeof(T)); + return this; + } + + public INetworkingSelectionStage WithStartFormFactory(IStartFormFactory factory) + { + this.factory = factory; + return this; + } + + + public IBuildingStage WithProxy(string proxyAddress) + { + var url = new Uri(proxyAddress); + client = new MessageClient(apiKey, url); + client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + return this; + } + + public IBuildingStage NoProxy() + { + client = new MessageClient(apiKey); + client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + return this; + } + + + public IBuildingStage WithBotClient(TelegramBotClient tgclient) + { + client = new MessageClient(apiKey, tgclient); + client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + return this; + } + + public IBuildingStage WithHostAndPort(string proxyHost, int proxyPort) + { + client = new MessageClient(apiKey, proxyHost, proxyPort); + client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + return this; + } + + public IBuildingStage WithHttpClient(HttpClient tgclient) + { + client = new MessageClient(apiKey, tgclient); + client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + return this; + } + + public BotBase Build() + { + var bb = new BotBase(); + + bb.APIKey = apiKey; + bb.StartFormFactory = factory; + + bb.Client = client; + + bb.Sessions.Client = bb.Client; + + return bb; + } + + } +} diff --git a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs new file mode 100644 index 0000000..5e33a8f --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface IAPIKeySelectionStage + { + /// + /// Sets the API Key which will be used by the telegram bot client. + /// + /// + /// + IStartFormSelectionPage WithAPIKey(String apiKey); + + } +} diff --git a/TelegramBotBase/Builder/Interfaces/IBuildingStage.cs b/TelegramBotBase/Builder/Interfaces/IBuildingStage.cs new file mode 100644 index 0000000..8313b0b --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/IBuildingStage.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface IBuildingStage + { + BotBase Build(); + } +} diff --git a/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs b/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs new file mode 100644 index 0000000..1a60a90 --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using Telegram.Bot; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface INetworkingSelectionStage + { + /// + /// Chooses a proxy as network configuration. + /// + /// + /// + IBuildingStage WithProxy(String proxyAddress); + + /// + /// Do not choose a proxy as network configuration. + /// + /// + IBuildingStage NoProxy(); + + + /// + /// Chooses a custom instance of TelegramBotClient. + /// + /// + /// + IBuildingStage WithBotClient(TelegramBotClient client); + + /// + /// Sets the custom proxy host and port. + /// + /// + /// + /// + IBuildingStage WithHostAndPort(String proxyHost, int Port); + + /// + /// Uses a custom http client. + /// + /// + /// + IBuildingStage WithHttpClient(HttpClient client); + + + } +} diff --git a/TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs b/TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs new file mode 100644 index 0000000..05ba793 --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Form; +using TelegramBotBase.Interfaces; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface IStartFormSelectionPage + { + + /// + /// Chooses a start form type which will be used for new sessions. + /// + /// + /// + INetworkingSelectionStage WithStartForm(Type startFormClass); + + /// + /// Chooses a generic start form which will be used for new sessions. + /// + /// + /// + INetworkingSelectionStage WithStartForm() where T : FormBase, new(); + + /// + /// Chooses a StartFormFactory which will be use for new sessions. + /// + /// + /// + INetworkingSelectionStage WithStartFormFactory(IStartFormFactory factory); + + } +} diff --git a/TelegramBotBase/Factories/DefaultStartFormFactory.cs b/TelegramBotBase/Factories/DefaultStartFormFactory.cs new file mode 100644 index 0000000..e3c7c20 --- /dev/null +++ b/TelegramBotBase/Factories/DefaultStartFormFactory.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Factories +{ + public class DefaultStartFormFactory : Interfaces.IStartFormFactory + { + private readonly Type _startFormClass; + + public DefaultStartFormFactory(Type startFormClass) + { + if (!typeof(FormBase).IsAssignableFrom(startFormClass)) + throw new ArgumentException("startFormClass argument must be a FormBase type"); + + _startFormClass = startFormClass; + } + + + public FormBase CreateForm() + { + return _startFormClass.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase; + } + } +} diff --git a/TelegramBotBase/Interfaces/IStartFormFactory.cs b/TelegramBotBase/Interfaces/IStartFormFactory.cs new file mode 100644 index 0000000..7c1c44d --- /dev/null +++ b/TelegramBotBase/Interfaces/IStartFormFactory.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Interfaces +{ + public interface IStartFormFactory + { + FormBase CreateForm(); + } +} diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs index 33dc0fb..60e947f 100644 --- a/TelegramBotBase/SessionBase.cs +++ b/TelegramBotBase/SessionBase.cs @@ -16,14 +16,13 @@ namespace TelegramBotBase /// /// Base class for managing all active sessions /// - public class SessionBase - where T : FormBase + public class SessionBase { public MessageClient Client { get; set; } public Dictionary SessionList { get; set; } - public BotBase BotBase { get; set; } + public BotBase BotBase { get; set; } public SessionBase() @@ -65,10 +64,10 @@ namespace TelegramBotBase /// /// /// - public async Task StartSession(long deviceId) - where T : FormBase + public async Task StartSession(long deviceId) { - T start = typeof(T).GetConstructor(new Type[] { }).Invoke(new object[] { }) as T; + var start = BotBase.StartFormFactory.CreateForm(); + //T start = typeof(T).GetConstructor(new Type[] { }).Invoke(new object[] { }) as T; start.Client = this.Client; @@ -239,7 +238,7 @@ namespace TelegramBotBase } - + /// From 755f5a245b9e82644b991d34cb3dea8cc1e369e0 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 17:27:06 +0200 Subject: [PATCH 04/57] Renaming --- TelegramBotBase/Builder/BotBaseBuilder.cs | 4 ++-- ...IStartFormSelectionPage.cs => IStartFormSelectionStage.cs} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename TelegramBotBase/Builder/Interfaces/{IStartFormSelectionPage.cs => IStartFormSelectionStage.cs} (95%) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index c4595f0..2299674 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -10,7 +10,7 @@ using TelegramBotBase.Interfaces; namespace TelegramBotBase.Builder { - public class BotBaseBuilder : IAPIKeySelectionStage, IStartFormSelectionPage, IBuildingStage, INetworkingSelectionStage + public class BotBaseBuilder : IAPIKeySelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage { String apiKey = null; @@ -24,7 +24,7 @@ namespace TelegramBotBase.Builder return new BotBaseBuilder(); } - public IStartFormSelectionPage WithAPIKey(string apiKey) + public IStartFormSelectionStage WithAPIKey(string apiKey) { this.apiKey = apiKey; return this; diff --git a/TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs b/TelegramBotBase/Builder/Interfaces/IStartFormSelectionStage.cs similarity index 95% rename from TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs rename to TelegramBotBase/Builder/Interfaces/IStartFormSelectionStage.cs index 05ba793..fec05b3 100644 --- a/TelegramBotBase/Builder/Interfaces/IStartFormSelectionPage.cs +++ b/TelegramBotBase/Builder/Interfaces/IStartFormSelectionStage.cs @@ -6,7 +6,7 @@ using TelegramBotBase.Interfaces; namespace TelegramBotBase.Builder.Interfaces { - public interface IStartFormSelectionPage + public interface IStartFormSelectionStage { /// From 1dff9d5ffe3bcc826973911d8775a34091a52107 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 17:33:49 +0200 Subject: [PATCH 05/57] Update IAPIKeySelectionStage.cs --- TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs index 5e33a8f..0d4c112 100644 --- a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs @@ -11,7 +11,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IStartFormSelectionPage WithAPIKey(String apiKey); + IStartFormSelectionStage WithAPIKey(String apiKey); } } From c4a31e987b3401c5ca545454bb9725d591151dcc Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 18:07:53 +0200 Subject: [PATCH 06/57] Replacing BotBase instance with BotBaseBuilder --- TelegramBotBaseTest/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBaseTest/Program.cs index 6371196..0b66389 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBaseTest/Program.cs @@ -8,14 +8,22 @@ using TelegramBotBase; using TelegramBotBase.Form; using TelegramBotBaseTest.Tests; using TelegramBotBase.Commands; +using TelegramBotBase.Builder; + namespace TelegramBotBaseTest { class Program { static void Main(string[] args) { + String APIKey = ""; - BotBase bb = new BotBase(APIKey); + var bb = BotBaseBuilder + .Create() + .WithAPIKey(APIKey) + .WithStartForm() + .NoProxy() + .Build(); bb.BotCommands.AddStartCommand("Starts the bot"); bb.BotCommands.AddHelpCommand("Should show you some help"); From d00c5e17995683836399cde0070870a6976d7641 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 18:21:05 +0200 Subject: [PATCH 07/57] Updating BotBaseBuilder with more functionality --- TelegramBotBase/Builder/BotBaseBuilder.cs | 93 +++++++++++++------ .../Builder/Interfaces/IBotCommandsStage.cs | 31 +++++++ .../Interfaces/INetworkingSelectionStage.cs | 10 +- .../Interfaces/ISessionSerializationStage.cs | 24 +++++ TelegramBotBaseTest/Program.cs | 17 ++-- 5 files changed, 138 insertions(+), 37 deletions(-) create mode 100644 TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs create mode 100644 TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 2299674..7ed473f 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -3,21 +3,27 @@ using System.Collections.Generic; using System.Net.Http; using System.Text; using Telegram.Bot; +using Telegram.Bot.Types; using TelegramBotBase.Base; using TelegramBotBase.Builder.Interfaces; +using TelegramBotBase.Commands; using TelegramBotBase.Form; using TelegramBotBase.Interfaces; namespace TelegramBotBase.Builder { - public class BotBaseBuilder : IAPIKeySelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage + public class BotBaseBuilder : IAPIKeySelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage { - String apiKey = null; + String _apiKey = null; - IStartFormFactory factory = null; + IStartFormFactory _factory = null; - MessageClient client = null; + MessageClient _client = null; + + List _botcommands = new List(); + + IStateMachine _statemachine = null; public static IAPIKeySelectionStage Create() { @@ -26,64 +32,95 @@ namespace TelegramBotBase.Builder public IStartFormSelectionStage WithAPIKey(string apiKey) { - this.apiKey = apiKey; + this._apiKey = apiKey; return this; } public INetworkingSelectionStage WithStartForm(Type startFormClass) { - this.factory = new Factories.DefaultStartFormFactory(startFormClass); + this._factory = new Factories.DefaultStartFormFactory(startFormClass); return this; } public INetworkingSelectionStage WithStartForm() where T : FormBase, new() { - this.factory = new Factories.DefaultStartFormFactory(typeof(T)); + this._factory = new Factories.DefaultStartFormFactory(typeof(T)); return this; } public INetworkingSelectionStage WithStartFormFactory(IStartFormFactory factory) { - this.factory = factory; + this._factory = factory; return this; } - public IBuildingStage WithProxy(string proxyAddress) + public IBotCommandsStage WithProxy(string proxyAddress) { var url = new Uri(proxyAddress); - client = new MessageClient(apiKey, url); - client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + _client = new MessageClient(_apiKey, url); + _client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); return this; } - public IBuildingStage NoProxy() + public IBotCommandsStage NoProxy() { - client = new MessageClient(apiKey); - client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + _client = new MessageClient(_apiKey); + _client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); return this; } - public IBuildingStage WithBotClient(TelegramBotClient tgclient) + public IBotCommandsStage WithBotClient(TelegramBotClient tgclient) { - client = new MessageClient(apiKey, tgclient); - client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + _client = new MessageClient(_apiKey, tgclient); + _client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); return this; } - public IBuildingStage WithHostAndPort(string proxyHost, int proxyPort) + public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort) { - client = new MessageClient(apiKey, proxyHost, proxyPort); - client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + _client = new MessageClient(_apiKey, proxyHost, proxyPort); + _client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); return this; } - public IBuildingStage WithHttpClient(HttpClient tgclient) + public IBotCommandsStage WithHttpClient(HttpClient tgclient) { - client = new MessageClient(apiKey, tgclient); - client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + _client = new MessageClient(_apiKey, tgclient); + _client.TelegramClient.Timeout = new TimeSpan(0, 1, 0); + return this; + } + + public ISessionSerializationStage NoCommands() + { + return this; + } + + public ISessionSerializationStage DefaultCommands() + { + _botcommands.AddStartCommand("Starts the bot"); + _botcommands.AddHelpCommand("Should show you some help"); + _botcommands.AddSettingsCommand("Should show you some settings"); + return this; + } + + public ISessionSerializationStage Configure(Action> action) + { + action?.Invoke(_botcommands); + return this; + } + + + public IBuildingStage NoSerialization() + { + return this; + } + + public IBuildingStage UseSerialization(IStateMachine machine) + { + this._statemachine = machine; return this; } @@ -91,13 +128,17 @@ namespace TelegramBotBase.Builder { var bb = new BotBase(); - bb.APIKey = apiKey; - bb.StartFormFactory = factory; + bb.APIKey = _apiKey; + bb.StartFormFactory = _factory; - bb.Client = client; + bb.Client = _client; bb.Sessions.Client = bb.Client; + bb.BotCommands = _botcommands; + + bb.StateMachine = _statemachine; + return bb; } diff --git a/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs b/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs new file mode 100644 index 0000000..d6b9dd4 --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Telegram.Bot.Types; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface IBotCommandsStage + { + /// + /// Does not create any commands. + /// + /// + ISessionSerializationStage NoCommands(); + + + /// + /// Creates default commands for start, help and settings. + /// + /// + ISessionSerializationStage DefaultCommands(); + + /// + /// Gives you the ability to add custom commands. + /// + /// + /// + ISessionSerializationStage Configure(Action> action); + + } +} diff --git a/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs b/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs index 1a60a90..5456877 100644 --- a/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs @@ -13,13 +13,13 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage WithProxy(String proxyAddress); + IBotCommandsStage WithProxy(String proxyAddress); /// /// Do not choose a proxy as network configuration. /// /// - IBuildingStage NoProxy(); + IBotCommandsStage NoProxy(); /// @@ -27,7 +27,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage WithBotClient(TelegramBotClient client); + IBotCommandsStage WithBotClient(TelegramBotClient client); /// /// Sets the custom proxy host and port. @@ -35,14 +35,14 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage WithHostAndPort(String proxyHost, int Port); + IBotCommandsStage WithHostAndPort(String proxyHost, int Port); /// /// Uses a custom http client. /// /// /// - IBuildingStage WithHttpClient(HttpClient client); + IBotCommandsStage WithHttpClient(HttpClient client); } diff --git a/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs b/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs new file mode 100644 index 0000000..ee51bd6 --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Interfaces; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface ISessionSerializationStage + { + /// + /// Do not uses serialization. + /// + /// + IBuildingStage NoSerialization(); + + /// + /// Sets the state machine for serialization. + /// + /// + /// + IBuildingStage UseSerialization(IStateMachine machine); + + } +} diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBaseTest/Program.cs index 0b66389..616dc3a 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBaseTest/Program.cs @@ -23,14 +23,19 @@ namespace TelegramBotBaseTest .WithAPIKey(APIKey) .WithStartForm() .NoProxy() + .Configure(a => + { + a.AddStartCommand("Starts the bot"); + a.AddHelpCommand("Should show you some help"); + a.AddSettingsCommand("Should show you some settings"); + a.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); + a.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" }); + a.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); + }) + .NoSerialization() .Build(); - bb.BotCommands.AddStartCommand("Starts the bot"); - bb.BotCommands.AddHelpCommand("Should show you some help"); - bb.BotCommands.AddSettingsCommand("Should show you some settings"); - bb.BotCommands.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); - bb.BotCommands.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" }); - bb.BotCommands.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); + bb.BotCommand += async (s, en) => { From e1d5051288e2d1ae9c4f3fc7276ba5a7f3d579f0 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 18:31:28 +0200 Subject: [PATCH 08/57] Update README.md --- README.md | 90 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 936392b..eb41c4d 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,19 @@ It needs to be a subclass of "FormBase" you will find in Namespace TelegramBotBa ``` -//Prepare the System -BotBase bb = new BotBase("{YOUR API KEY}"); +//Prepare the System (New in V5) +var bb = BotBaseBuilder + .Create() + .WithAPIKey("{YOUR API KEY}") + .WithStartForm() + .NoProxy() + .Configure(a => + { + a.AddStartCommand("Starts the bot") -//Add Systemcommands if you like, you could catch them later -bb.BotCommands.Add(new BotCommand() { Command = "start", Description = "Starts the bot" }); + }) + .NoSerialization() + .Build(); //Update bot commands to botfather bb.UploadBotCommands().Wait(); @@ -252,12 +260,22 @@ Below we have 4 options. ``` -BotBase bb = new BotBase("{YOUR API KEY}"); +var bb = BotBaseBuilder + .Create() + .WithAPIKey("{YOUR API KEY}") + .WithStartForm() + .NoProxy() + .Configure(a => + { + a.AddStartCommand("Starts the bot"); + a.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); + a.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" }); + a.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); -bb.BotCommands.Add(new BotCommand() { Command = "start", Description = "Starts the bot" }); -bb.BotCommands.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); -bb.BotCommands.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" }); -bb.BotCommands.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); + + }) + .NoSerialization() + .Build(); bb.BotCommand += async (s, en) => { @@ -963,13 +981,17 @@ In general you didn't need to do more then, to keep the actual form: ``` //Prepare the System -BotBase bb = new BotBase("{YOUR API KEY}"); - -//Add Systemcommands if you like, you could catch them later -bb.SystemCalls.Add("/start"); - -//Set the statemachine and enable it -bb.StateMachine = new TelegramBotBase.States.SimpleJSONStateMachine(AppContext.BaseDirectory + "config\\states.json"); +var bb = BotBaseBuilder + .Create() + .WithAPIKey("{YOUR API KEY}") + .WithStartForm() + .NoProxy() + .Configure(a => + { + a.AddStartCommand("Starts the bot"); + }) + .UseSerialization(new TelegramBotBase.States.SimpleJSONStateMachine(AppContext.BaseDirectory + "config\\states.json")) + .Build(); //Start your Bot bb.Start(); @@ -982,13 +1004,17 @@ In general you didn't need to do more then, to keep the actual form: ``` //Prepare the System -BotBase bb = new BotBase("{YOUR API KEY}"); - -//Add Systemcommands if you like, you could catch them later -bb.SystemCalls.Add("/start"); - -//Set the statemachine and enable it -bb.StateMachine = new TelegramBotBase.States.JSONStateMachine(AppContext.BaseDirectory + "config\\states.json"); +var bb = BotBaseBuilder + .Create() + .WithAPIKey("{YOUR API KEY}") + .WithStartForm() + .NoProxy() + .Configure(a => + { + a.AddStartCommand("Starts the bot"); + }) + .UseSerialization(new TelegramBotBase.States.JSONStateMachine(AppContext.BaseDirectory + "config\\states.json")) + .Build(); //Start your Bot bb.Start(); @@ -1002,13 +1028,17 @@ In general you didn't need to do more then, to keep the actual form: ``` //Prepare the System -BotBase bb = new BotBase("{YOUR API KEY}"); - -//Add Systemcommands if you like, you could catch them later -bb.SystemCalls.Add("/start"); - -//Set the statemachine and enable it -bb.StateMachine = new TelegramBotBase.States.XMLStateMachine(AppContext.BaseDirectory + "config\\states.xml"); +var bb = BotBaseBuilder + .Create() + .WithAPIKey("{YOUR API KEY}") + .WithStartForm() + .NoProxy() + .Configure(a => + { + a.AddStartCommand("Starts the bot"); + }) + .UseSerialization(new TelegramBotBase.States.XMLStateMachine(AppContext.BaseDirectory + "config\\states.xml")) + .Build(); //Start your Bot bb.Start(); From b001d5e9c470e709cd0db26f581f7021a8f94d6c Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 17 Oct 2021 18:38:35 +0200 Subject: [PATCH 09/57] Adding LambdaStartFormFactory --- .../Factories/LambdaStartFormFactory.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 TelegramBotBase/Factories/LambdaStartFormFactory.cs diff --git a/TelegramBotBase/Factories/LambdaStartFormFactory.cs b/TelegramBotBase/Factories/LambdaStartFormFactory.cs new file mode 100644 index 0000000..c748b20 --- /dev/null +++ b/TelegramBotBase/Factories/LambdaStartFormFactory.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Factories +{ + public class LambdaStartFormFactory : Interfaces.IStartFormFactory + { + public delegate FormBase CreateFormDelegate(); + + private readonly CreateFormDelegate _lambda; + + public LambdaStartFormFactory(CreateFormDelegate lambda) + { + _lambda = lambda; + } + + public FormBase CreateForm() + { + return _lambda(); + } + } +} From d0edf8531cfadd60b3ba374e9b917c74eb223572 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Mon, 22 Nov 2021 22:07:55 +0100 Subject: [PATCH 10/57] Replacing Configure method in BBB with CustomCommands --- TelegramBotBase/Builder/BotBaseBuilder.cs | 2 +- TelegramBotBaseTest/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 7ed473f..9bc8794 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -106,7 +106,7 @@ namespace TelegramBotBase.Builder return this; } - public ISessionSerializationStage Configure(Action> action) + public ISessionSerializationStage CustomCommands(Action> action) { action?.Invoke(_botcommands); return this; diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBaseTest/Program.cs index 616dc3a..b1b6f2b 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBaseTest/Program.cs @@ -23,7 +23,7 @@ namespace TelegramBotBaseTest .WithAPIKey(APIKey) .WithStartForm() .NoProxy() - .Configure(a => + .CustomCommands(a => { a.AddStartCommand("Starts the bot"); a.AddHelpCommand("Should show you some help"); From 0bc77ca79c4f6fdc13bb73073f9906f88772a598 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:43:38 +0100 Subject: [PATCH 11/57] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eb41c4d..01efc4a 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ var bb = BotBaseBuilder .WithAPIKey("{YOUR API KEY}") .WithStartForm() .NoProxy() - .Configure(a => + .CustomCommands(a => { a.AddStartCommand("Starts the bot") @@ -265,7 +265,7 @@ var bb = BotBaseBuilder .WithAPIKey("{YOUR API KEY}") .WithStartForm() .NoProxy() - .Configure(a => + .CustomCommands(a => { a.AddStartCommand("Starts the bot"); a.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); @@ -986,7 +986,7 @@ var bb = BotBaseBuilder .WithAPIKey("{YOUR API KEY}") .WithStartForm() .NoProxy() - .Configure(a => + .CustomCommands(a => { a.AddStartCommand("Starts the bot"); }) @@ -1009,7 +1009,7 @@ var bb = BotBaseBuilder .WithAPIKey("{YOUR API KEY}") .WithStartForm() .NoProxy() - .Configure(a => + .CustomCommands(a => { a.AddStartCommand("Starts the bot"); }) @@ -1033,7 +1033,7 @@ var bb = BotBaseBuilder .WithAPIKey("{YOUR API KEY}") .WithStartForm() .NoProxy() - .Configure(a => + .CustomCommands(a => { a.AddStartCommand("Starts the bot"); }) From 2bd46346242a935d9587fd96057bca612a86953b Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:45:24 +0100 Subject: [PATCH 12/57] V17 - Remove default selection for enums --- TelegramBotBase/Controls/Hybrid/ButtonGrid.cs | 2 +- TelegramBotBase/Controls/Hybrid/CheckedButtonList.cs | 2 +- TelegramBotBase/Controls/Hybrid/TaggedButtonGrid.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TelegramBotBase/Controls/Hybrid/ButtonGrid.cs b/TelegramBotBase/Controls/Hybrid/ButtonGrid.cs index d8bfdb1..d62179f 100644 --- a/TelegramBotBase/Controls/Hybrid/ButtonGrid.cs +++ b/TelegramBotBase/Controls/Hybrid/ButtonGrid.cs @@ -75,7 +75,7 @@ namespace TelegramBotBase.Controls.Hybrid /// /// Parsemode of the message. /// - public ParseMode MessageParseMode { get; set; } = ParseMode.Default; + public ParseMode MessageParseMode { get; set; } = ParseMode.Markdown; /// /// Enables automatic paging of buttons when the amount of rows is exceeding the limits. diff --git a/TelegramBotBase/Controls/Hybrid/CheckedButtonList.cs b/TelegramBotBase/Controls/Hybrid/CheckedButtonList.cs index 9c2e414..12026b2 100644 --- a/TelegramBotBase/Controls/Hybrid/CheckedButtonList.cs +++ b/TelegramBotBase/Controls/Hybrid/CheckedButtonList.cs @@ -76,7 +76,7 @@ namespace TelegramBotBase.Controls.Hybrid /// /// Parsemode of the message. /// - public ParseMode MessageParseMode { get; set; } = ParseMode.Default; + public ParseMode MessageParseMode { get; set; } = ParseMode.Markdown; /// /// Enables automatic paging of buttons when the amount of rows is exceeding the limits. diff --git a/TelegramBotBase/Controls/Hybrid/TaggedButtonGrid.cs b/TelegramBotBase/Controls/Hybrid/TaggedButtonGrid.cs index 55ed12e..cf0bc90 100644 --- a/TelegramBotBase/Controls/Hybrid/TaggedButtonGrid.cs +++ b/TelegramBotBase/Controls/Hybrid/TaggedButtonGrid.cs @@ -73,7 +73,7 @@ namespace TelegramBotBase.Controls.Hybrid /// /// Parsemode of the message. /// - public ParseMode MessageParseMode { get; set; } = ParseMode.Default; + public ParseMode MessageParseMode { get; set; } = ParseMode.Markdown; /// /// Enables automatic paging of buttons when the amount of rows is exceeding the limits. From c1a0b12a94701d0e564615ffdb6ac512320783be Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:47:42 +0100 Subject: [PATCH 13/57] Replace Configure with CustomCommands --- TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs b/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs index d6b9dd4..9dcdadf 100644 --- a/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs @@ -20,12 +20,13 @@ namespace TelegramBotBase.Builder.Interfaces /// ISessionSerializationStage DefaultCommands(); + /// /// Gives you the ability to add custom commands. /// /// /// - ISessionSerializationStage Configure(Action> action); + ISessionSerializationStage CustomCommands(Action> action); } } From 2aee4863701e369c647a6c6e713f55a48b609779 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:49:17 +0100 Subject: [PATCH 14/57] V17 - Replacing default enum values --- TelegramBotBase/Sessions/DeviceSession.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index cf3a5c4..a593d82 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Telegram.Bot; using Telegram.Bot.Exceptions; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; @@ -146,7 +147,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Edit(int messageId, String text, ButtonForm buttons = null, ParseMode parseMode = ParseMode.Default) + public async Task Edit(int messageId, String text, ButtonForm buttons = null, ParseMode parseMode = ParseMode.Markdown) { InlineKeyboardMarkup markup = buttons; @@ -175,7 +176,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Edit(int messageId, String text, InlineKeyboardMarkup markup, ParseMode parseMode = ParseMode.Default) + public async Task Edit(int messageId, String text, InlineKeyboardMarkup markup, ParseMode parseMode = ParseMode.Markdown) { if (text.Length > Constants.Telegram.MaxMessageLength) { @@ -202,7 +203,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Edit(Message message, ButtonForm buttons = null, ParseMode parseMode = ParseMode.Default) + public async Task Edit(Message message, ButtonForm buttons = null, ParseMode parseMode = ParseMode.Markdown) { InlineKeyboardMarkup markup = buttons; @@ -253,7 +254,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Send(long deviceId, String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true) + public async Task Send(long deviceId, String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown, bool MarkdownV2AutoEscape = true) { if (this.ActiveForm == null) return null; @@ -293,7 +294,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Send(String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true) + public async Task Send(String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown, bool MarkdownV2AutoEscape = true) { return await Send(this.DeviceId, text, buttons, replyTo, disableNotification, parseMode, MarkdownV2AutoEscape); } @@ -306,7 +307,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Send(String text, InlineKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true) + public async Task Send(String text, InlineKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown, bool MarkdownV2AutoEscape = true) { if (this.ActiveForm == null) return null; @@ -344,7 +345,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task Send(String text, ReplyMarkupBase markup, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true) + public async Task Send(String text, ReplyMarkupBase markup, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown, bool MarkdownV2AutoEscape = true) { if (this.ActiveForm == null) return null; @@ -382,7 +383,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task SendPhoto(InputOnlineFile file, String caption = null, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default) + public async Task SendPhoto(InputOnlineFile file, String caption = null, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown) { if (this.ActiveForm == null) return null; @@ -450,7 +451,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task SendVideo(InputOnlineFile file, String caption = null, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default) + public async Task SendVideo(InputOnlineFile file, String caption = null, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown) { if (this.ActiveForm == null) return null; @@ -480,7 +481,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task SendVideo(String url, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default) + public async Task SendVideo(String url, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown) { if (this.ActiveForm == null) return null; From e9c25ea9e4dee059addd647093c10ef61c8b4cde Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:49:33 +0100 Subject: [PATCH 15/57] New ConfirmAction method --- TelegramBotBase/Sessions/DeviceSession.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index a593d82..fceac78 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -140,6 +140,23 @@ namespace TelegramBotBase.Sessions } + /// + /// Confirm incomming action (i.e. Button click) + /// + /// + /// + public async Task ConfirmAction(String CallbackQueryId, String message = "", bool showAlert = false, String urlToOpen = null) + { + try + { + await this.Client.TelegramClient.AnswerCallbackQueryAsync(CallbackQueryId, message, showAlert, urlToOpen); + } + catch + { + + } + } + /// /// Edits the text message /// From 31e52887ba14b01bcfa278044f24f37288551fbd Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:57:49 +0100 Subject: [PATCH 16/57] V17 - Big Update - Adding a message loop interface to build custom message loops - extracting default message loop from BotBase into seperate class - updates to BotBaseBuilder for integration of custom message loops - updating all result classes for using the new Update object of V17 - improving MessageResult and UpdateResult classes - BotBase has been prepared for cleanup (a lot of comments) - Comment cleanup at the next build - updating Readme --- README.md | 5 + TelegramBotBase/Base/DataResult.cs | 56 ++- TelegramBotBase/Base/MessageClient.cs | 252 ++++++---- TelegramBotBase/Base/MessageResult.cs | 75 +-- TelegramBotBase/Base/ResultBase.cs | 3 +- TelegramBotBase/Base/UpdateResult.cs | 59 +++ TelegramBotBase/BotBase.cs | 440 ++++++++++-------- TelegramBotBase/Builder/BotBaseBuilder.cs | 50 +- .../Interfaces/IAPIKeySelectionStage.cs | 2 +- .../Interfaces/IMessageLoopSelectionStage.cs | 36 ++ .../Interfaces/INetworkingSelectionStage.cs | 2 + .../MessageLoops/FormBaseMessageLoop.cs | 131 ++++++ TelegramBotBase/Form/ButtonBase.cs | 4 +- TelegramBotBase/Form/GroupForm.cs | 4 +- .../Interfaces/IMessageLoopFactory.cs | 21 + TelegramBotBase/Sessions/DeviceSession.cs | 14 +- 16 files changed, 824 insertions(+), 330 deletions(-) create mode 100644 TelegramBotBase/Base/UpdateResult.cs create mode 100644 TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs create mode 100644 TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs create mode 100644 TelegramBotBase/Interfaces/IMessageLoopFactory.cs diff --git a/README.md b/README.md index 01efc4a..b1fdcdf 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ It needs to be a subclass of "FormBase" you will find in Namespace TelegramBotBa var bb = BotBaseBuilder .Create() .WithAPIKey("{YOUR API KEY}") + .DefaultMessageLoop() .WithStartForm() .NoProxy() .CustomCommands(a => @@ -263,6 +264,7 @@ Below we have 4 options. var bb = BotBaseBuilder .Create() .WithAPIKey("{YOUR API KEY}") + .DefaultMessageLoop() .WithStartForm() .NoProxy() .CustomCommands(a => @@ -984,6 +986,7 @@ In general you didn't need to do more then, to keep the actual form: var bb = BotBaseBuilder .Create() .WithAPIKey("{YOUR API KEY}") + .DefaultMessageLoop() .WithStartForm() .NoProxy() .CustomCommands(a => @@ -1007,6 +1010,7 @@ In general you didn't need to do more then, to keep the actual form: var bb = BotBaseBuilder .Create() .WithAPIKey("{YOUR API KEY}") + .DefaultMessageLoop() .WithStartForm() .NoProxy() .CustomCommands(a => @@ -1031,6 +1035,7 @@ In general you didn't need to do more then, to keep the actual form: var bb = BotBaseBuilder .Create() .WithAPIKey("{YOUR API KEY}") + .DefaultMessageLoop() .WithStartForm() .NoProxy() .CustomCommands(a => diff --git a/TelegramBotBase/Base/DataResult.cs b/TelegramBotBase/Base/DataResult.cs index c3f2a21..55ff7b2 100644 --- a/TelegramBotBase/Base/DataResult.cs +++ b/TelegramBotBase/Base/DataResult.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.InputFiles; @@ -14,7 +15,11 @@ namespace TelegramBotBase.Base /// public class DataResult : ResultBase { - public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; } + + //public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; } + + public UpdateResult Update { get; set; } + public Contact Contact { @@ -64,11 +69,21 @@ namespace TelegramBotBase.Base } } + + //public Telegram.Bot.Types.Enums.MessageType Type + //{ + // get + // { + // return this.RawMessageData?.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown; + // } + //} + + public Telegram.Bot.Types.Enums.MessageType Type { get { - return this.RawMessageData?.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown; + return this.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown; } } @@ -87,23 +102,30 @@ namespace TelegramBotBase.Base } - public DataResult(Telegram.Bot.Args.MessageEventArgs rawdata) + //public DataResult(Telegram.Bot.Args.MessageEventArgs rawdata) + //{ + // this.RawMessageData = rawdata; + // this.Message = rawdata.Message; + //} + + //public DataResult(MessageResult message) + //{ + // this.RawMessageData = message.RawMessageData; + // this.Message = message.Message; + + // this.Client = message.Client; + //} + + + public DataResult(UpdateResult update) { - this.RawMessageData = rawdata; - this.Message = rawdata.Message; + this.Update = update; } - public DataResult(MessageResult message) - { - this.RawMessageData = message.RawMessageData; - this.Message = message.Message; - - this.Client = message.Client; - } public async Task DownloadDocument() { - var encryptedContent = new System.IO.MemoryStream(this.Document.FileSize); + var encryptedContent = new System.IO.MemoryStream(this.Document.FileSize.Value); var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, encryptedContent); return new InputOnlineFile(encryptedContent, this.Document.FileName); @@ -156,13 +178,13 @@ namespace TelegramBotBase.Base ms.Position = 0; var sr = new StreamReader(ms, encoding); - + return sr.ReadToEnd(); } public async Task DownloadVideo() { - var encryptedContent = new System.IO.MemoryStream(this.Video.FileSize); + var encryptedContent = new System.IO.MemoryStream(this.Video.FileSize.Value); var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent); return new InputOnlineFile(encryptedContent, ""); @@ -179,7 +201,7 @@ namespace TelegramBotBase.Base public async Task DownloadAudio() { - var encryptedContent = new System.IO.MemoryStream(this.Audio.FileSize); + var encryptedContent = new System.IO.MemoryStream(this.Audio.FileSize.Value); var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent); return new InputOnlineFile(encryptedContent, ""); @@ -197,7 +219,7 @@ namespace TelegramBotBase.Base public async Task DownloadPhoto(int index) { var photo = this.Photos[index]; - var encryptedContent = new System.IO.MemoryStream(photo.FileSize); + var encryptedContent = new System.IO.MemoryStream(photo.FileSize.Value); var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent); return new InputOnlineFile(encryptedContent, ""); diff --git a/TelegramBotBase/Base/MessageClient.cs b/TelegramBotBase/Base/MessageClient.cs index 22a71fe..80327fb 100644 --- a/TelegramBotBase/Base/MessageClient.cs +++ b/TelegramBotBase/Base/MessageClient.cs @@ -5,8 +5,13 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Text; +using System.Threading; using System.Threading.Tasks; +using Telegram.Bot.Exceptions; +using Telegram.Bot; using Telegram.Bot.Types; +using Telegram.Bot.Types.Enums; +using Telegram.Bot.Extensions.Polling; namespace TelegramBotBase.Base { @@ -19,16 +24,20 @@ namespace TelegramBotBase.Base public String APIKey { get; set; } - public Telegram.Bot.TelegramBotClient TelegramClient { get; set; } + public ITelegramBotClient TelegramClient { get; set; } private EventHandlerList __Events { get; set; } = new EventHandlerList(); + private static object __evOnMessageLoop = new object(); + private static object __evOnMessage = new object(); private static object __evOnMessageEdit = new object(); private static object __evCallbackQuery = new object(); + CancellationTokenSource __cancellationTokenSource; + public MessageClient(String APIKey) { @@ -47,13 +56,22 @@ namespace TelegramBotBase.Base Prepare(); } - public MessageClient(String APIKey, Uri proxyUrl) + + + public MessageClient(String APIKey, Uri proxyUrl, NetworkCredential credential = null) { this.APIKey = APIKey; - var proxy = new WebProxy(proxyUrl); + var proxy = new WebProxy(proxyUrl) + { + Credentials = credential + }; - this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, proxy); + var httpClient = new HttpClient( + new HttpClientHandler { Proxy = proxy, UseProxy = true } + ); + + this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, httpClient); Prepare(); } @@ -70,11 +88,17 @@ namespace TelegramBotBase.Base var proxy = new WebProxy(proxyHost, proxyPort); - this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, proxy); + var httpClient = new HttpClient( + new HttpClientHandler { Proxy = proxy, UseProxy = true } + ); + + this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, httpClient); Prepare(); } + + public MessageClient(String APIKey, Telegram.Bot.TelegramBotClient Client) { this.APIKey = APIKey; @@ -88,62 +112,106 @@ namespace TelegramBotBase.Base { this.TelegramClient.Timeout = new TimeSpan(0, 0, 30); - this.TelegramClient.OnMessage += TelegramClient_OnMessage; - this.TelegramClient.OnMessageEdited += TelegramClient_OnMessageEdited; - this.TelegramClient.OnCallbackQuery += TelegramClient_OnCallbackQuery; + + //this.TelegramClient.OnMessage += TelegramClient_OnMessage; + //this.TelegramClient.OnMessageEdited += TelegramClient_OnMessageEdited; + //this.TelegramClient.OnCallbackQuery += TelegramClient_OnCallbackQuery; + } - private async void TelegramClient_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) + + + public void StartReceiving() { - //Skip empty messages by default - if (e.Message == null) - return; + __cancellationTokenSource = new CancellationTokenSource(); - try - { - var mr = new MessageResult(e); - mr.Client = this; - OnMessage(mr); - } - catch + var receiverOptions = new ReceiverOptions { + AllowedUpdates = { } // receive all update types + }; - } + this.TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, __cancellationTokenSource.Token); } - - private async void TelegramClient_OnMessageEdited(object sender, Telegram.Bot.Args.MessageEventArgs e) + public void StopReceiving() { - //Skip empty messages by default - if (e.Message == null) - return; - - try - { - var mr = new MessageResult(e); - mr.Client = this; - OnMessageEdit(mr); - } - catch - { - - } + __cancellationTokenSource.Cancel(); } - private async void TelegramClient_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e) + + //private async void TelegramClient_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) + //{ + // //Skip empty messages by default + // if (e.Message == null) + // return; + + // try + // { + // var mr = new MessageResult(e); + // mr.Client = this; + // OnMessage(mr); + // } + // catch + // { + + // } + //} + + + //private async void TelegramClient_OnMessageEdited(object sender, Telegram.Bot.Args.MessageEventArgs e) + //{ + // //Skip empty messages by default + // if (e.Message == null) + // return; + + // try + // { + // var mr = new MessageResult(e); + // mr.Client = this; + // OnMessageEdit(mr); + // } + // catch + // { + + // } + //} + + //private async void TelegramClient_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e) + //{ + // try + // { + // var ar = new MessageResult(e); + // ar.Client = this; + // OnAction(ar); + // } + // catch + // { + + // } + //} + + + public Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) { - try - { - var ar = new MessageResult(e); - ar.Client = this; - OnAction(ar); - } - catch - { + OnMessageLoop(new UpdateResult(update, null)); - } + return Task.CompletedTask; } + public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) + { + if (exception is ApiRequestException exAPI) + { + Console.WriteLine($"Telegram API Error:\n[{exAPI.ErrorCode}]\n{exAPI.Message}"); + } + else + { + Console.WriteLine(exception.ToString()); + } + return Task.CompletedTask; + } + + /// /// This will return the current list of bot commands. /// @@ -168,56 +236,78 @@ namespace TelegramBotBase.Base #region "Events" - public event EventHandler Message + + + public event Async.AsyncEventHandler MessageLoop { add { - this.__Events.AddHandler(__evOnMessage, value); + this.__Events.AddHandler(__evOnMessageLoop, value); } remove { - this.__Events.RemoveHandler(__evOnMessage, value); + this.__Events.RemoveHandler(__evOnMessageLoop, value); } } - public void OnMessage(MessageResult result) + public void OnMessageLoop(UpdateResult update) { - (this.__Events[__evOnMessage] as EventHandler)?.Invoke(this, result); + (this.__Events[__evOnMessageLoop] as Async.AsyncEventHandler)?.Invoke(this, update); } - public event EventHandler MessageEdit - { - add - { - this.__Events.AddHandler(__evOnMessageEdit, value); - } - remove - { - this.__Events.RemoveHandler(__evOnMessageEdit, value); - } - } - public void OnMessageEdit(MessageResult result) - { - (this.__Events[__evOnMessageEdit] as EventHandler)?.Invoke(this, result); - } + //public event EventHandler Message + //{ + // add + // { + // this.__Events.AddHandler(__evOnMessage, value); + // } + // remove + // { + // this.__Events.RemoveHandler(__evOnMessage, value); + // } + //} - public event EventHandler Action - { - add - { - this.__Events.AddHandler(__evCallbackQuery, value); - } - remove - { - this.__Events.RemoveHandler(__evCallbackQuery, value); - } - } + //public void OnMessage(MessageResult result) + //{ + // (this.__Events[__evOnMessage] as EventHandler)?.Invoke(this, result); + //} - public void OnAction(MessageResult result) - { - (this.__Events[__evCallbackQuery] as EventHandler)?.Invoke(this, result); - } + + + //public event EventHandler MessageEdit + //{ + // add + // { + // this.__Events.AddHandler(__evOnMessageEdit, value); + // } + // remove + // { + // this.__Events.RemoveHandler(__evOnMessageEdit, value); + // } + //} + + //public void OnMessageEdit(MessageResult result) + //{ + // (this.__Events[__evOnMessageEdit] as EventHandler)?.Invoke(this, result); + //} + + //public event EventHandler Action + //{ + // add + // { + // this.__Events.AddHandler(__evCallbackQuery, value); + // } + // remove + // { + // this.__Events.RemoveHandler(__evCallbackQuery, value); + // } + //} + + //public void OnAction(MessageResult result) + //{ + // (this.__Events[__evCallbackQuery] as EventHandler)?.Invoke(this, result); + //} #endregion diff --git a/TelegramBotBase/Base/MessageResult.cs b/TelegramBotBase/Base/MessageResult.cs index 7da2bdd..8ecf3fd 100644 --- a/TelegramBotBase/Base/MessageResult.cs +++ b/TelegramBotBase/Base/MessageResult.cs @@ -3,15 +3,21 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Telegram.Bot; +using Telegram.Bot.Types; using TelegramBotBase.Sessions; namespace TelegramBotBase.Base { public class MessageResult : ResultBase { - public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; } - public Telegram.Bot.Args.CallbackQueryEventArgs RawCallbackData { get; set; } + //public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; } + + //public Telegram.Bot.Args.CallbackQueryEventArgs RawCallbackData { get; set; } + + + public Telegram.Bot.Types.Update UpdateData { get; set; } /// /// Returns the Device/ChatId @@ -20,8 +26,9 @@ namespace TelegramBotBase.Base { get { - return this.RawMessageData?.Message?.Chat.Id - ?? this.RawCallbackData?.CallbackQuery.Message?.Chat.Id + return this.UpdateData?.Message?.Chat?.Id + ?? this.UpdateData?.EditedMessage?.Chat.Id + ?? this.UpdateData?.CallbackQuery.Message?.Chat.Id ?? Device?.DeviceId ?? 0; } @@ -40,8 +47,9 @@ namespace TelegramBotBase.Base { get { - return this.Message?.MessageId - ?? this.RawCallbackData?.CallbackQuery?.Message?.MessageId + return this.UpdateData?.Message?.MessageId + ?? this.Message?.MessageId + ?? this.UpdateData?.CallbackQuery?.Message?.MessageId ?? 0; } } @@ -50,7 +58,7 @@ namespace TelegramBotBase.Base { get { - return this.RawMessageData?.Message?.Text ?? ""; + return this.UpdateData?.Message?.Text ?? ""; } } @@ -58,7 +66,7 @@ namespace TelegramBotBase.Base { get { - return this.RawMessageData?.Message?.Text ?? ""; + return this.UpdateData?.Message?.Text ?? ""; } } @@ -66,8 +74,19 @@ namespace TelegramBotBase.Base { get { - return this.RawMessageData?.Message?.Type - ?? Telegram.Bot.Types.Enums.MessageType.Unknown; + return Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown; + } + } + + public Message Message + { + get + { + return this.UpdateData?.Message + ?? this.UpdateData?.EditedMessage + ?? this.UpdateData?.ChannelPost + ?? this.UpdateData?.EditedChannelPost + ?? this.UpdateData?.CallbackQuery?.Message; } } @@ -78,7 +97,7 @@ namespace TelegramBotBase.Base { get { - return (this.RawCallbackData != null); + return (this.UpdateData.CallbackQuery != null); } } @@ -133,7 +152,7 @@ namespace TelegramBotBase.Base { get { - return this.RawCallbackData?.CallbackQuery?.Data; + return this.UpdateData?.CallbackQuery?.Data; } } @@ -162,14 +181,7 @@ namespace TelegramBotBase.Base /// public async Task ConfirmAction(String message = "", bool showAlert = false, String urlToOpen = null) { - try - { - await this.Client.TelegramClient.AnswerCallbackQueryAsync(this.RawCallbackData.CallbackQuery.Id, message, showAlert, urlToOpen); - } - catch - { - - } + await this.Device.ConfirmAction(this.UpdateData.CallbackQuery.Id, message, showAlert, urlToOpen); } public override async Task DeleteMessage() @@ -189,17 +201,24 @@ namespace TelegramBotBase.Base } - public MessageResult(Telegram.Bot.Args.MessageEventArgs rawdata) + public MessageResult(Telegram.Bot.Types.Update update) { - this.RawMessageData = rawdata; - this.Message = rawdata.Message; + this.UpdateData = update; + } - public MessageResult(Telegram.Bot.Args.CallbackQueryEventArgs callback) - { - this.RawCallbackData = callback; - this.Message = callback.CallbackQuery.Message; - } + + //public MessageResult(Telegram.Bot.Args.MessageEventArgs rawdata) + //{ + // this.RawMessageData = rawdata; + // this.Message = rawdata.Message; + //} + + //public MessageResult(Telegram.Bot.Args.CallbackQueryEventArgs callback) + //{ + // this.RawCallbackData = callback; + // this.Message = callback.CallbackQuery.Message; + //} } } diff --git a/TelegramBotBase/Base/ResultBase.cs b/TelegramBotBase/Base/ResultBase.cs index e351860..e5d37e8 100644 --- a/TelegramBotBase/Base/ResultBase.cs +++ b/TelegramBotBase/Base/ResultBase.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Telegram.Bot; namespace TelegramBotBase.Base { @@ -20,7 +21,7 @@ namespace TelegramBotBase.Base } } - public Telegram.Bot.Types.Message Message { get; set; } + public virtual Telegram.Bot.Types.Message Message { get; set; } /// /// Deletes the current message diff --git a/TelegramBotBase/Base/UpdateResult.cs b/TelegramBotBase/Base/UpdateResult.cs new file mode 100644 index 0000000..f2341dd --- /dev/null +++ b/TelegramBotBase/Base/UpdateResult.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Telegram.Bot.Types; +using TelegramBotBase.Sessions; + +namespace TelegramBotBase.Base +{ + public class UpdateResult : ResultBase + { + public UpdateResult(Update rawData, DeviceSession device) + { + RawData = rawData; + Device = device; + + + } + + /// + /// Returns the Device/ChatId + /// + public override long DeviceId + { + get + { + return this.RawData?.Message?.Chat?.Id + ?? this.RawData?.CallbackQuery?.Message?.Chat?.Id + ?? Device?.DeviceId + ?? 0; + } + } + + public Update RawData { get; set; } + + public override Message Message + { + get + { + return RawData?.Message + ?? RawData?.EditedMessage + ?? RawData?.ChannelPost + ?? RawData?.EditedChannelPost + ?? RawData?.CallbackQuery?.Message; + } + } + + + + public DeviceSession Device + { + get; + set; + } + + + } + +} diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index 9361281..e5a6d93 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -3,13 +3,17 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Telegram.Bot; +using Telegram.Bot.Exceptions; using Telegram.Bot.Types; +using Telegram.Bot.Types.Enums; using TelegramBotBase.Args; using TelegramBotBase.Attributes; using TelegramBotBase.Base; using TelegramBotBase.Enums; +using TelegramBotBase.Factories.MessageLoops; using TelegramBotBase.Form; using TelegramBotBase.Interfaces; using TelegramBotBase.Sessions; @@ -69,6 +73,8 @@ namespace TelegramBotBase /// public IStartFormFactory StartFormFactory { get; set; } + public IMessageLoopFactory MessageLoopFactory { get; set; } + public Dictionary SystemSettings { get; private set; } @@ -88,6 +94,8 @@ namespace TelegramBotBase this.Sessions.BotBase = this; } + + /// /// Start your Bot /// @@ -96,9 +104,12 @@ namespace TelegramBotBase if (this.Client == null) return; - this.Client.Message += Client_Message; - this.Client.MessageEdit += Client_MessageEdit; - this.Client.Action += Client_Action; + this.Client.MessageLoop += Client_MessageLoop; + + //this.Client.Message += Client_Message; + //this.Client.MessageEdit += Client_MessageEdit; + //this.Client.Action += Client_Action; + if (this.StateMachine != null) { @@ -116,7 +127,39 @@ namespace TelegramBotBase DeviceSession.MaxNumberOfRetries = this.GetSetting(eSettings.MaxNumberOfRetries, 5); - this.Client.TelegramClient.StartReceiving(); + this.Client.StartReceiving(); + } + + + private async Task Client_MessageLoop(object sender, UpdateResult e) + { + DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + if (ds == null) + { + ds = this.Sessions.StartSession(e.DeviceId).GetAwaiter().GetResult(); + e.Device = ds; + ds.LastMessage = e.RawData.Message; + + OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); + } + + var mr = new MessageResult(e.RawData); + + int i = 0; + + //Should formulars get navigated (allow maximum of 10, to dont get loops) + do + { + i++; + + //Reset navigation + ds.FormSwitched = false; + + await MessageLoopFactory.MessageLoop(this, ds, e, mr); + + mr.IsFirstHandler = false; + + } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); } @@ -128,10 +171,14 @@ namespace TelegramBotBase if (this.Client == null) return; - this.Client.Message -= Client_Message; - this.Client.Action -= Client_Action; + this.Client.MessageLoop -= Client_MessageLoop; - this.Client.TelegramClient.StopReceiving(); + //this.Client.Message -= Client_Message; + //this.Client.MessageEdit -= Client_MessageEdit; + //this.Client.Action -= Client_Action; + + + this.Client.StopReceiving(); this.Sessions.SaveSessionStates(); } @@ -152,35 +199,37 @@ namespace TelegramBotBase } } - private async void Client_Message(object sender, MessageResult e) - { - if (this.GetSetting(eSettings.SkipAllMessages, false)) - return; - try - { - DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - e.Device = ds; - if (this.GetSetting(eSettings.LogAllMessages, false)) - { - OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); - } + //private async void Client_Message(object sender, MessageResult e) + //{ + // if (this.GetSetting(eSettings.SkipAllMessages, false)) + // return; - ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); + // try + // { + // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + // e.Device = ds; - await Client_Loop(sender, e); - } - catch (Telegram.Bot.Exceptions.ApiRequestException ex) - { + // if (this.GetSetting(eSettings.LogAllMessages, false)) + // { + // OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); + // } - } - catch (Exception ex) - { - DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); - } - } + // ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); + + // await Client_Loop(sender, e); + // } + // catch (Telegram.Bot.Exceptions.ApiRequestException ex) + // { + + // } + // catch (Exception ex) + // { + // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + // OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); + // } + //} @@ -255,101 +304,107 @@ namespace TelegramBotBase //} - private async Task Client_Loop(object sender, MessageResult e) - { - DeviceSession ds = e.Device; - if (ds == null) - { - ds = await this.Sessions.StartSession(e.DeviceId); - e.Device = ds; - ds.LastMessage = e.Message; - OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); - } + //private async Task Client_Loop(object sender, MessageResult e) + //{ + // DeviceSession ds = e.Device; + // if (ds == null) + // { + // ds = await this.Sessions.StartSession(e.DeviceId); + // e.Device = ds; + // ds.LastMessage = e.Message; - ds.LastAction = DateTime.Now; - ds.LastMessage = e.Message; + // OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); + // } - //Is this a bot command ? - if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0) - { - var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds); - await OnBotCommand(sce); + // ds.LastAction = DateTime.Now; + // ds.LastMessage = e.Message; - if (sce.Handled) - return; - } + // //Is this a bot command ? + // if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0) + // { + // var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds); + // await OnBotCommand(sce); - FormBase activeForm = null; + // if (sce.Handled) + // return; + // } - int i = 0; + // FormBase activeForm = null; - //Should formulars get navigated (allow maximum of 10, to dont get loops) - do - { - i++; + // int i = 0; - //Reset navigation - ds.FormSwitched = false; - - activeForm = ds.ActiveForm; - - //Pre Loading Event - await activeForm.PreLoad(e); - - //Send Load event to controls - await activeForm.LoadControls(e); - - //Loading Event - await activeForm.Load(e); - - //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) - if (e.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Location | - e.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio) - { - await activeForm.SentData(new DataResult(e)); - } - - //Action Event - if (!ds.FormSwitched && e.IsAction) - { - //Send Action event to controls - await activeForm.ActionControls(e); - - //Send Action event to form itself - await activeForm.Action(e); - - if (!e.Handled) - { - var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); - OnUnhandledCall(uhc); - - if (uhc.Handled) - { - e.Handled = true; - if (!ds.FormSwitched) - { - break; - } - } - } - - } - - if (!ds.FormSwitched) - { - //Render Event - await activeForm.RenderControls(e); - - await activeForm.Render(e); - } - - e.IsFirstHandler = false; - - } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); + // //Should formulars get navigated (allow maximum of 10, to dont get loops) + // do + // { + // i++; - } + + // //Reset navigation + // ds.FormSwitched = false; + + // activeForm = ds.ActiveForm; + + + + // //Pre Loading Event + // await activeForm.PreLoad(e); + + // //Send Load event to controls + // await activeForm.LoadControls(e); + + // //Loading Event + // await activeForm.Load(e); + + // //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) + // if (e.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Location | + // e.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio) + // { + // await activeForm.SentData(new DataResult(e)); + // } + + // //Action Event + // if (!ds.FormSwitched && e.IsAction) + // { + // //Send Action event to controls + // await activeForm.ActionControls(e); + + // //Send Action event to form itself + // await activeForm.Action(e); + + // if (!e.Handled) + // { + // var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); + // OnUnhandledCall(uhc); + + // if (uhc.Handled) + // { + // e.Handled = true; + // if (!ds.FormSwitched) + // { + // break; + // } + // } + // } + + // } + + // if (!ds.FormSwitched) + // { + // //Render Event + // await activeForm.RenderControls(e); + + // await activeForm.Render(e); + // } + + // e.IsFirstHandler = false; + + // } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); + + + //} + /// /// This will invoke the full message loop for the device even when no "userevent" like message or action has been raised. @@ -374,7 +429,8 @@ namespace TelegramBotBase DeviceSession ds = this.Sessions.GetSession(DeviceId); e.Device = ds; - await Client_Loop(this, e); + await MessageLoopFactory.MessageLoop(this, ds, new UpdateResult(e.UpdateData, ds), e); + //await Client_Loop(this, e); } catch (Exception ex) { @@ -383,79 +439,85 @@ namespace TelegramBotBase } } - private async void Client_MessageEdit(object sender, MessageResult e) + + //private async void Client_MessageEdit(object sender, MessageResult e) + //{ + // if (this.GetSetting(eSettings.SkipAllMessages, false)) + // return; + + // try + // { + // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + // e.Device = ds; + + // if (this.GetSetting(eSettings.LogAllMessages, false)) + // { + // OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); + // } + + // //Call same, to handle received liked edited + // ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); + + // await Client_TryMessageEdit(sender, e); + // } + // catch (Telegram.Bot.Exceptions.ApiRequestException ex) + // { + + // } + // catch (Exception ex) + // { + // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + // OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); + // } + //} + + //private async Task Client_TryMessageEdit(object sender, MessageResult e) + //{ + // DeviceSession ds = e.Device; + // if (ds == null) + // { + // ds = await this.Sessions.StartSession(e.DeviceId); + // e.Device = ds; + // } + + // ds.LastAction = DateTime.Now; + // ds.LastMessage = e.Message; + + // //Pre Loading Event + // await ds.ActiveForm.Edited(e); + + // //When form has been switched due navigation within the edit method, reopen Client_Message + // if (ds.FormSwitched) + // { + // await Client_Loop(sender, e); + // } + + //} + + //private async void Client_Action(object sender, MessageResult e) + //{ + // try + // { + // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + // e.Device = ds; + + // if (this.GetSetting(eSettings.LogAllMessages, false)) + // { + // OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); + // } + + // await Client_Loop(sender, e); + // } + // catch (Exception ex) + // { + // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); + // OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); + // } + //} + + public void MessageLoopFactory_UnhandledCall(object sender, UnhandledCallEventArgs e) { - if (this.GetSetting(eSettings.SkipAllMessages, false)) - return; - - try - { - DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - e.Device = ds; - - if (this.GetSetting(eSettings.LogAllMessages, false)) - { - OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); - } - - //Call same, to handle received liked edited - ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); - - await Client_TryMessageEdit(sender, e); - } - catch (Telegram.Bot.Exceptions.ApiRequestException ex) - { - - } - catch (Exception ex) - { - DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); - } - } - - private async Task Client_TryMessageEdit(object sender, MessageResult e) - { - DeviceSession ds = e.Device; - if (ds == null) - { - ds = await this.Sessions.StartSession(e.DeviceId); - e.Device = ds; - } - - ds.LastAction = DateTime.Now; - ds.LastMessage = e.Message; - - //Pre Loading Event - await ds.ActiveForm.Edited(e); - - //When form has been switched due navigation within the edit method, reopen Client_Message - if (ds.FormSwitched) - { - await Client_Loop(sender, e); - } - - } - - private async void Client_Action(object sender, MessageResult e) - { - try - { - DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - e.Device = ds; - - if (this.GetSetting(eSettings.LogAllMessages, false)) - { - OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); - } - - await Client_Loop(sender, e); - } - catch (Exception ex) - { - DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); - } + OnUnhandledCall(e); } //private async void Client_TryAction(object sender, MessageResult e) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 9bc8794..dc4eb33 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -12,7 +12,7 @@ using TelegramBotBase.Interfaces; namespace TelegramBotBase.Builder { - public class BotBaseBuilder : IAPIKeySelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage + public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage { String _apiKey = null; @@ -25,17 +25,55 @@ namespace TelegramBotBase.Builder IStateMachine _statemachine = null; + IMessageLoopFactory _messageloopfactory = null; + public static IAPIKeySelectionStage Create() { return new BotBaseBuilder(); } - public IStartFormSelectionStage WithAPIKey(string apiKey) + #region "Step 1" + + public IMessageLoopSelectionStage WithAPIKey(string apiKey) { this._apiKey = apiKey; return this; } + #endregion + + + #region "Step 2" + + public IStartFormSelectionStage DefaultMessageLoop() + { + _messageloopfactory = new Factories.MessageLoops.FormBaseMessageLoop(); + + return this; + } + + public IStartFormSelectionStage CustomMessageLoop(Type messageLoopClass) + { + if (messageLoopClass.IsSubclassOf(typeof(IMessageLoopFactory))) + throw new ArgumentException($"Not a subclass of {nameof(IMessageLoopFactory)}"); + + _messageloopfactory = messageLoopClass.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as IMessageLoopFactory; + + return this; + } + + public IStartFormSelectionStage CustomMessageLoop() + where T : class, new() + { + _messageloopfactory = typeof(T).GetConstructor(new Type[] { })?.Invoke(new object[] { }) as IMessageLoopFactory; + + return this; + } + + #endregion + + #region "Step 3" + public INetworkingSelectionStage WithStartForm(Type startFormClass) { this._factory = new Factories.DefaultStartFormFactory(startFormClass); @@ -55,6 +93,8 @@ namespace TelegramBotBase.Builder return this; } + #endregion + public IBotCommandsStage WithProxy(string proxyAddress) { @@ -64,6 +104,7 @@ namespace TelegramBotBase.Builder return this; } + public IBotCommandsStage NoProxy() { _client = new MessageClient(_apiKey); @@ -79,6 +120,7 @@ namespace TelegramBotBase.Builder return this; } + public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort) { _client = new MessageClient(_apiKey, proxyHost, proxyPort); @@ -139,6 +181,10 @@ namespace TelegramBotBase.Builder bb.StateMachine = _statemachine; + bb.MessageLoopFactory = _messageloopfactory; + + bb.MessageLoopFactory.UnhandledCall += bb.MessageLoopFactory_UnhandledCall; + return bb; } diff --git a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs index 0d4c112..cfa6131 100644 --- a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs @@ -11,7 +11,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IStartFormSelectionStage WithAPIKey(String apiKey); + IMessageLoopSelectionStage WithAPIKey(String apiKey); } } diff --git a/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs new file mode 100644 index 0000000..125945e --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Form; +using TelegramBotBase.Interfaces; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface IMessageLoopSelectionStage + { + + /// + /// Chooses a default message loop. + /// + /// + /// + IStartFormSelectionStage DefaultMessageLoop(); + + /// + /// Chooses a custom message loop. + /// + /// + /// + IStartFormSelectionStage CustomMessageLoop(Type startFormClass); + + + /// + /// Chooses a custom message loop. + /// + /// + /// + IStartFormSelectionStage CustomMessageLoop() where T : class, new(); + + + } +} diff --git a/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs b/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs index 5456877..4b5bcce 100644 --- a/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/INetworkingSelectionStage.cs @@ -8,6 +8,7 @@ namespace TelegramBotBase.Builder.Interfaces { public interface INetworkingSelectionStage { + /// /// Chooses a proxy as network configuration. /// @@ -29,6 +30,7 @@ namespace TelegramBotBase.Builder.Interfaces /// IBotCommandsStage WithBotClient(TelegramBotClient client); + /// /// Sets the custom proxy host and port. /// diff --git a/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs b/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs new file mode 100644 index 0000000..a902fe0 --- /dev/null +++ b/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Telegram.Bot.Types; +using TelegramBotBase.Args; +using TelegramBotBase.Base; +using TelegramBotBase.Enums; +using TelegramBotBase.Interfaces; +using TelegramBotBase.Sessions; + +namespace TelegramBotBase.Factories.MessageLoops +{ + public class FormBaseMessageLoop : IMessageLoopFactory + { + private static object __evUnhandledCall = new object(); + + private EventHandlerList __Events = new EventHandlerList(); + + public FormBaseMessageLoop() + { + + } + + public async Task MessageLoop(BotBase Bot, DeviceSession session, UpdateResult ur, MessageResult mr) + { + var update = ur.RawData; + + + if (update.Type != Telegram.Bot.Types.Enums.UpdateType.Message + && update.Type != Telegram.Bot.Types.Enums.UpdateType.EditedMessage + && update.Type != Telegram.Bot.Types.Enums.UpdateType.CallbackQuery) + { + return; + } + + //Is this a bot command ? + if (mr.IsFirstHandler && mr.IsBotCommand && Bot.BotCommands.Count(a => "/" + a.Command == mr.BotCommand) > 0) + { + var sce = new BotCommandEventArgs(mr.BotCommand, mr.BotCommandParameters, mr.Message, session.DeviceId, session); + await Bot.OnBotCommand(sce); + + if (sce.Handled) + return; + } + + //var mr = new MessageResult(update); + + mr.Device = session; + + + //var message = update.Message ?? update.EditedMessage; + + var activeForm = session.ActiveForm; + + //Pre Loading Event + await activeForm.PreLoad(mr); + + //Send Load event to controls + await activeForm.LoadControls(mr); + + //Loading Event + await activeForm.Load(mr); + + //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) + if (mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Location | + mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio) + { + await activeForm.SentData(new DataResult(ur)); + } + + //Action Event + if (!session.FormSwitched && mr.IsAction) + { + //Send Action event to controls + await activeForm.ActionControls(mr); + + //Send Action event to form itself + await activeForm.Action(mr); + + if (!mr.Handled) + { + var uhc = new UnhandledCallEventArgs(ur.Message.Text, mr.RawData, session.DeviceId, mr.MessageId, ur.Message, session); + OnUnhandledCall(uhc); + + if (uhc.Handled) + { + mr.Handled = true; + if (!session.FormSwitched) + { + return; + } + } + } + + } + + if (!session.FormSwitched) + { + //Render Event + await activeForm.RenderControls(mr); + + await activeForm.Render(mr); + } + + } + + /// + /// Will be called if no form handeled this call + /// + public event EventHandler UnhandledCall + { + add + { + this.__Events.AddHandler(__evUnhandledCall, value); + } + remove + { + this.__Events.RemoveHandler(__evUnhandledCall, value); + } + } + + public void OnUnhandledCall(UnhandledCallEventArgs e) + { + (this.__Events[__evUnhandledCall] as EventHandler)?.Invoke(this, e); + + } + } +} diff --git a/TelegramBotBase/Form/ButtonBase.cs b/TelegramBotBase/Form/ButtonBase.cs index 54ffefe..efb4466 100644 --- a/TelegramBotBase/Form/ButtonBase.cs +++ b/TelegramBotBase/Form/ButtonBase.cs @@ -46,9 +46,9 @@ namespace TelegramBotBase.Form return InlineKeyboardButton.WithCallbackData(this.Text, id + this.Value); } - var ikb = new InlineKeyboardButton(); + var ikb = new InlineKeyboardButton(this.Text); - ikb.Text = this.Text; + //ikb.Text = this.Text; ikb.Url = this.Url; return ikb; diff --git a/TelegramBotBase/Form/GroupForm.cs b/TelegramBotBase/Form/GroupForm.cs index 6b460cf..ecdc01f 100644 --- a/TelegramBotBase/Form/GroupForm.cs +++ b/TelegramBotBase/Form/GroupForm.cs @@ -24,12 +24,12 @@ namespace TelegramBotBase.Form { case Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded: - await OnMemberChanges(new MemberChangeEventArgs(Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded, message, message.RawMessageData.Message.NewChatMembers)); + await OnMemberChanges(new MemberChangeEventArgs(Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded, message, message.Message.NewChatMembers)); break; case Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft: - await OnMemberChanges(new MemberChangeEventArgs(Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft, message, message.RawMessageData.Message.LeftChatMember)); + await OnMemberChanges(new MemberChangeEventArgs(Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft, message, message.Message.LeftChatMember)); break; diff --git a/TelegramBotBase/Interfaces/IMessageLoopFactory.cs b/TelegramBotBase/Interfaces/IMessageLoopFactory.cs new file mode 100644 index 0000000..fec857f --- /dev/null +++ b/TelegramBotBase/Interfaces/IMessageLoopFactory.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Telegram.Bot.Types; +using TelegramBotBase.Args; +using TelegramBotBase.Base; +using TelegramBotBase.Sessions; + +namespace TelegramBotBase.Interfaces +{ + public interface IMessageLoopFactory + { + + Task MessageLoop(BotBase Bot, DeviceSession session, UpdateResult ur, MessageResult e); + + event EventHandler UnhandledCall; + + + } +} diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index fceac78..1238c66 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -769,7 +769,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public T RAW(Func call) + public T RAW(Func call) { return call(this.Client.TelegramClient); } @@ -780,7 +780,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task API(Func> call) + public async Task API(Func> call) { var numberOfTries = 0; while (numberOfTries < DeviceSession.MaxNumberOfRetries) @@ -794,8 +794,8 @@ namespace TelegramBotBase.Sessions if (ex.ErrorCode != 429) throw; - if (ex.Parameters != null) - await Task.Delay(ex.Parameters.RetryAfter * 1000); + if (ex.Parameters != null && ex.Parameters.RetryAfter != null) + await Task.Delay(ex.Parameters.RetryAfter.Value * 1000); numberOfTries++; } @@ -808,7 +808,7 @@ namespace TelegramBotBase.Sessions /// /// /// - public async Task API(Func call) + public async Task API(Func call) { var numberOfTries = 0; while (numberOfTries < DeviceSession.MaxNumberOfRetries) @@ -823,8 +823,8 @@ namespace TelegramBotBase.Sessions if (ex.ErrorCode != 429) throw; - if (ex.Parameters != null) - await Task.Delay(ex.Parameters.RetryAfter * 1000); + if (ex.Parameters != null && ex.Parameters.RetryAfter != null) + await Task.Delay(ex.Parameters.RetryAfter.Value * 1000); numberOfTries++; } From 1fc581b959e72d479d1814c068d4f47f1b4ee85b Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:58:49 +0100 Subject: [PATCH 17/57] V17 - Testproject Update --- TelegramBotBaseTest/Program.cs | 6 ++++-- .../TelegramBotBaseTest.csproj | 2 +- TelegramBotBaseTest/Tests/DataForm.cs | 1 + TelegramBotBaseTest/Tests/Navigation/Start.cs | 21 +++++++++++-------- TelegramBotBaseTest/Tests/TestForm.cs | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBaseTest/Program.cs index b1b6f2b..50c9319 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBaseTest/Program.cs @@ -21,6 +21,7 @@ namespace TelegramBotBaseTest var bb = BotBaseBuilder .Create() .WithAPIKey(APIKey) + .DefaultMessageLoop() .WithStartForm() .NoProxy() .CustomCommands(a => @@ -37,6 +38,7 @@ namespace TelegramBotBaseTest + bb.BotCommand += async (s, en) => { switch (en.Command) @@ -67,7 +69,7 @@ namespace TelegramBotBaseTest case "/params": String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b); - + await en.Device.Send("Your parameters are: " + m, replyTo: en.Device.LastMessageId); en.Handled = true; @@ -82,7 +84,7 @@ namespace TelegramBotBaseTest bb.SetSetting(TelegramBotBase.Enums.eSettings.LogAllMessages, true); - bb.Message += (s,en) => + bb.Message += (s, en) => { Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? "")); }; diff --git a/TelegramBotBaseTest/TelegramBotBaseTest.csproj b/TelegramBotBaseTest/TelegramBotBaseTest.csproj index f52e456..3bf6473 100644 --- a/TelegramBotBaseTest/TelegramBotBaseTest.csproj +++ b/TelegramBotBaseTest/TelegramBotBaseTest.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1;net5 + netcoreapp3.1;net5;net472;net6 false Debug;Release diff --git a/TelegramBotBaseTest/Tests/DataForm.cs b/TelegramBotBaseTest/Tests/DataForm.cs index a53f74b..4a6edec 100644 --- a/TelegramBotBaseTest/Tests/DataForm.cs +++ b/TelegramBotBaseTest/Tests/DataForm.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.InputFiles; using Telegram.Bot.Types.ReplyMarkups; diff --git a/TelegramBotBaseTest/Tests/Navigation/Start.cs b/TelegramBotBaseTest/Tests/Navigation/Start.cs index 07402fa..1f70b5c 100644 --- a/TelegramBotBaseTest/Tests/Navigation/Start.cs +++ b/TelegramBotBaseTest/Tests/Navigation/Start.cs @@ -16,16 +16,9 @@ namespace TelegramBotBaseTest.Tests.Navigation public Start() { - this.Closed += Start_Closed; + } - private async Task Start_Closed(object sender, EventArgs e) - { - if (msg == null) - return; - - await Device.DeleteMessage(msg); - } public override async Task Load(MessageResult message) { @@ -49,12 +42,18 @@ namespace TelegramBotBaseTest.Tests.Navigation //Create navigation controller and navigate to it, keep the current form as root form so we can get back to here later var nc = new CustomController(this); + nc.ForceCleanupOnLastPop = true; var f1 = new Form1(); + await nc.PushAsync(f1); + await NavigateTo(nc); - await nc.PushAsync(f1); + if (msg == null) + return; + + await Device.DeleteMessage(msg); break; @@ -66,6 +65,10 @@ namespace TelegramBotBaseTest.Tests.Navigation await NavigateTo(mn); + if (msg == null) + return; + + await Device.DeleteMessage(msg); break; } diff --git a/TelegramBotBaseTest/Tests/TestForm.cs b/TelegramBotBaseTest/Tests/TestForm.cs index 57d5981..8994465 100644 --- a/TelegramBotBaseTest/Tests/TestForm.cs +++ b/TelegramBotBaseTest/Tests/TestForm.cs @@ -51,10 +51,10 @@ namespace TelegramBotBaseTest.Tests default: - if (message.RawMessageData == null) + if (message.UpdateData == null) return; - this.LastMessage = message.RawMessageData.Message.Text; + this.LastMessage = message.Message.Text; break; } From 65ec7f1c2b12c542c7e8302ddf91f6fb3ec772ae Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 26 Nov 2021 17:59:58 +0100 Subject: [PATCH 18/57] Update TelegramBotBase.csproj --- TelegramBotBase/TelegramBotBase.csproj | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 0b31660..456e344 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -19,7 +19,7 @@ - + @@ -65,9 +65,12 @@ + - - + + + + From e28663138bd19323c6e0e0700e95bc81def82787 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 28 Nov 2021 23:20:56 +0100 Subject: [PATCH 19/57] Integrating Images Project --- .../ImageExtensions.cs | 61 +++++++++++++++++++ .../TelegramBotBase.Extensions.Images.csproj | 17 ++++++ TelegramBotBase/Sessions/DeviceSession.cs | 40 ------------ TelegramBotBase/TelegramBotBase.csproj | 11 ++-- TelegramBotBase/Tools/Images.cs | 22 ------- .../TelegramBotBaseTest.csproj | 1 + TelegramBotFramework.sln | 10 ++- 7 files changed, 93 insertions(+), 69 deletions(-) create mode 100644 TelegramBotBase.Extensions.Images/ImageExtensions.cs create mode 100644 TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj delete mode 100644 TelegramBotBase/Tools/Images.cs diff --git a/TelegramBotBase.Extensions.Images/ImageExtensions.cs b/TelegramBotBase.Extensions.Images/ImageExtensions.cs new file mode 100644 index 0000000..0ae703f --- /dev/null +++ b/TelegramBotBase.Extensions.Images/ImageExtensions.cs @@ -0,0 +1,61 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Threading.Tasks; +using Telegram.Bot.Types.InputFiles; +using Telegram.Bot.Types; +using TelegramBotBase.Sessions; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Extensions.Images +{ + public static class ImageExtensions + { + public static Stream ToStream(this Image image, ImageFormat format) + { + var stream = new System.IO.MemoryStream(); + image.Save(stream, format); + stream.Position = 0; + return stream; + } + + /// + /// Sends an image + /// + /// + /// + /// + /// + /// + /// + public static async Task SendPhoto(this DeviceSession session, Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) + { + using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) + { + InputOnlineFile fts = new InputOnlineFile(fileStream, name); + + return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); + } + } + + /// + /// Sends an image + /// + /// + /// + /// + /// + /// + /// + public static async Task SendPhoto(this DeviceSession session, Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) + { + using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) + { + InputOnlineFile fts = new InputOnlineFile(fileStream, name); + + return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); + } + } + } +} diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj new file mode 100644 index 0000000..aa47dfd --- /dev/null +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.1;net472;net5;netcoreapp3.1;net6 + https://github.com/MajMcCloud/TelegramBotFramework + https://github.com/MajMcCloud/TelegramBotFramework + MIT + + + + + + + + + + \ No newline at end of file diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index 1238c66..da0a5ed 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; @@ -422,44 +420,6 @@ namespace TelegramBotBase.Sessions } } - /// - /// Sends an image - /// - /// - /// - /// - /// - /// - /// - public async Task SendPhoto(Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) - { - using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) - { - InputOnlineFile fts = new InputOnlineFile(fileStream, name); - - return await SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); - } - } - - /// - /// Sends an image - /// - /// - /// - /// - /// - /// - /// - public async Task SendPhoto(Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) - { - using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) - { - InputOnlineFile fts = new InputOnlineFile(fileStream, name); - - return await SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification); - } - } - /// /// Sends an video /// diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 456e344..8a9fb11 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -1,9 +1,9 @@  - netstandard2.1;net472;net5;netcoreapp3.1 + netstandard2.1;net472;net5;netcoreapp3.1;net6 false - false + False true https://github.com/MajMcCloud/TelegramBotFramework https://github.com/MajMcCloud/TelegramBotFramework @@ -16,6 +16,9 @@ true true snupkg + $(VersionPrefix) + + @@ -28,7 +31,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG prompt 4 @@ -64,10 +67,8 @@ - - diff --git a/TelegramBotBase/Tools/Images.cs b/TelegramBotBase/Tools/Images.cs deleted file mode 100644 index e941884..0000000 --- a/TelegramBotBase/Tools/Images.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TelegramBotBase.Tools -{ - public static class Images - { - public static Stream ToStream(this Image image, ImageFormat format) - { - var stream = new System.IO.MemoryStream(); - image.Save(stream, format); - stream.Position = 0; - return stream; - } - } -} diff --git a/TelegramBotBaseTest/TelegramBotBaseTest.csproj b/TelegramBotBaseTest/TelegramBotBaseTest.csproj index 3bf6473..0224404 100644 --- a/TelegramBotBaseTest/TelegramBotBaseTest.csproj +++ b/TelegramBotBaseTest/TelegramBotBaseTest.csproj @@ -27,6 +27,7 @@ + diff --git a/TelegramBotFramework.sln b/TelegramBotFramework.sln index f14d7d4..234b44b 100644 --- a/TelegramBotFramework.sln +++ b/TelegramBotFramework.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29324.140 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase", "TelegramBotBase\TelegramBotBase.csproj", "{0BD16FB9-7ED4-4CCB-83EB-5CEE538E1B6C}" EndProject @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemCommandsBot", "Exampl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JoinHiderBot", "Examples\JoinHiderBot\JoinHiderBot.csproj", "{E804B9E5-7ACC-49D3-9253-806766C1D9A5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TelegramBotBase.Extensions.Images", "TelegramBotBase.Extensions.Images\TelegramBotBase.Extensions.Images.csproj", "{B5DDFA45-0E01-46A5-B67D-541300CDD606}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,6 +42,10 @@ Global {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 + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5DDFA45-0E01-46A5-B67D-541300CDD606}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 077bd1384fb56efafa35aba730994eb295bf6293 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 28 Nov 2021 23:58:23 +0100 Subject: [PATCH 20/57] Removing System.ComponentModel dependency --- TelegramBotBase/TelegramBotBase.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 8a9fb11..5fd56de 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -68,7 +68,6 @@ - From fb38d32e9e3be52a205285ada1994c947c08a94a Mon Sep 17 00:00:00 2001 From: Florian Dahn Date: Mon, 29 Nov 2021 15:57:49 +0100 Subject: [PATCH 21/57] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1fdcdf..de0d049 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # .Net Telegram Bot Framework - Context based addon -[![NuGet version (TelegramBotBase)](https://img.shields.io/nuget/v/TelegramBotBase.svg?style=flat-square)](https://www.nuget.org/packages/TelegramBotBase/) +[![NuGet version (TelegramBotBase)](https://img.shields.io/nuget/vpre/TelegramBotBase.svg?style=flat-square)](https://www.nuget.org/packages/TelegramBotBase/) [![telegram chat](https://img.shields.io/badge/Support_Chat-Telegram-blue.svg?style=flat-square)](https://www.t.me/tgbotbase) From 4026f9ba4ee1a5d39c7760f00496ac6f6920c047 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Mon, 6 Dec 2021 02:36:59 +0100 Subject: [PATCH 22/57] Update for easier serialization during BotBaseBuilder --- README.md | 6 ++--- .../TelegramBotBase.Extensions.Images.csproj | 2 +- TelegramBotBase/Builder/BotBaseBuilder.cs | 20 +++++++++++++++ .../Interfaces/ISessionSerializationStage.cs | 25 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b1fdcdf..b52f9b3 100644 --- a/README.md +++ b/README.md @@ -993,7 +993,7 @@ var bb = BotBaseBuilder { a.AddStartCommand("Starts the bot"); }) - .UseSerialization(new TelegramBotBase.States.SimpleJSONStateMachine(AppContext.BaseDirectory + "config\\states.json")) + .UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json") .Build(); //Start your Bot @@ -1017,7 +1017,7 @@ var bb = BotBaseBuilder { a.AddStartCommand("Starts the bot"); }) - .UseSerialization(new TelegramBotBase.States.JSONStateMachine(AppContext.BaseDirectory + "config\\states.json")) + .UseJSON(AppContext.BaseDirectory + "config\\states.json") .Build(); //Start your Bot @@ -1042,7 +1042,7 @@ var bb = BotBaseBuilder { a.AddStartCommand("Starts the bot"); }) - .UseSerialization(new TelegramBotBase.States.XMLStateMachine(AppContext.BaseDirectory + "config\\states.xml")) + .UseXML(AppContext.BaseDirectory + "config\\states.xml") .Build(); //Start your Bot diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj index aa47dfd..ea76a8f 100644 --- a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index dc4eb33..0a91ea9 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -9,6 +9,7 @@ using TelegramBotBase.Builder.Interfaces; using TelegramBotBase.Commands; using TelegramBotBase.Form; using TelegramBotBase.Interfaces; +using TelegramBotBase.States; namespace TelegramBotBase.Builder { @@ -166,6 +167,25 @@ namespace TelegramBotBase.Builder return this; } + + public IBuildingStage UseJSON(string path) + { + this._statemachine = new JSONStateMachine(path); + return this; + } + + public IBuildingStage UseSimpleJSON(string path) + { + this._statemachine = new SimpleJSONStateMachine(path); + return this; + } + + public IBuildingStage UseXML(string path) + { + this._statemachine = new XMLStateMachine(path); + return this; + } + public BotBase Build() { var bb = new BotBase(); diff --git a/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs b/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs index ee51bd6..7231c81 100644 --- a/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs +++ b/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs @@ -13,6 +13,7 @@ namespace TelegramBotBase.Builder.Interfaces /// IBuildingStage NoSerialization(); + /// /// Sets the state machine for serialization. /// @@ -20,5 +21,29 @@ namespace TelegramBotBase.Builder.Interfaces /// IBuildingStage UseSerialization(IStateMachine machine); + + /// + /// Using the complex version of .Net JSON, which can serialize all objects. + /// + /// + /// + IBuildingStage UseJSON(String path); + + + /// + /// Use the easy version of .Net JSON, which can serialize basic types, but not generics and others. + /// + /// + /// + IBuildingStage UseSimpleJSON(String path); + + + /// + /// Uses the XML serializer for session serialization. + /// + /// + /// + IBuildingStage UseXML(String path); + } } From 03565aba98adc4f4332e9bea676cfcce824d7577 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Mon, 6 Dec 2021 02:41:55 +0100 Subject: [PATCH 23/57] Replacing Nuget packages with project references --- TelegramBotBase.Extensions.Images/ImageExtensions.cs | 4 ++-- .../TelegramBotBase.Extensions.Images.csproj | 5 ++++- TelegramBotBaseTest/Tests/TestForm2.cs | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/TelegramBotBase.Extensions.Images/ImageExtensions.cs b/TelegramBotBase.Extensions.Images/ImageExtensions.cs index 0ae703f..55ddbb2 100644 --- a/TelegramBotBase.Extensions.Images/ImageExtensions.cs +++ b/TelegramBotBase.Extensions.Images/ImageExtensions.cs @@ -31,7 +31,7 @@ namespace TelegramBotBase.Extensions.Images /// public static async Task SendPhoto(this DeviceSession session, Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) { - using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) + using (var fileStream = ToStream(image, ImageFormat.Png)) { InputOnlineFile fts = new InputOnlineFile(fileStream, name); @@ -50,7 +50,7 @@ namespace TelegramBotBase.Extensions.Images /// public static async Task SendPhoto(this DeviceSession session, Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) { - using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png)) + using (var fileStream = ToStream(image, ImageFormat.Png)) { InputOnlineFile fts = new InputOnlineFile(fileStream, name); diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj index ea76a8f..87f356b 100644 --- a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -11,7 +11,10 @@ - + + + + \ No newline at end of file diff --git a/TelegramBotBaseTest/Tests/TestForm2.cs b/TelegramBotBaseTest/Tests/TestForm2.cs index 89855d8..089430e 100644 --- a/TelegramBotBaseTest/Tests/TestForm2.cs +++ b/TelegramBotBaseTest/Tests/TestForm2.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Telegram.Bot.Types; using Telegram.Bot.Types.ReplyMarkups; using TelegramBotBase.Base; +using TelegramBotBase.Extensions.Images; using TelegramBotBase.Form; namespace TelegramBotBaseTest.Tests From 3b8b24593f6a83d8bd14cf0f45968235689b277f Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Thu, 16 Dec 2021 14:57:28 +0100 Subject: [PATCH 24/57] Dependency Update - downgrade NetStandard from 2.1 to 2.0 to allow .NetFramework usage from 4.6.1 to 4.8 - remove .Net Framework 4.7.2 compilation target - replacing conditioned compilation for .Net Framework with .Net Standard - removing System.Net.Http dependency (was only necessary for .Net Framework) --- TelegramBotBase/Form/AutoCleanForm.cs | 2 +- TelegramBotBase/TelegramBotBase.csproj | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/TelegramBotBase/Form/AutoCleanForm.cs b/TelegramBotBase/Form/AutoCleanForm.cs index 7fd9200..4e6a692 100644 --- a/TelegramBotBase/Form/AutoCleanForm.cs +++ b/TelegramBotBase/Form/AutoCleanForm.cs @@ -138,7 +138,7 @@ namespace TelegramBotBase.Form { var oldMessages = OldMessages.AsEnumerable(); -#if !NET472 +#if !NETSTANDARD2_0 while (oldMessages.Any()) { using var cts = new CancellationTokenSource(); diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 5fd56de..5d14fca 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -1,7 +1,7 @@  - netstandard2.1;net472;net5;netcoreapp3.1;net6 + netstandard2.0;net5;netcoreapp3.1;net6 false False true @@ -68,7 +68,6 @@ - From 35045f3aeb7489ba92bbfec9f977e00d25e7edd0 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Thu, 16 Dec 2021 15:08:56 +0100 Subject: [PATCH 25/57] Removing Newtonsoft Dependency --- TelegramBotBase/TelegramBotBase.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 5d14fca..adf2a8a 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -7,7 +7,7 @@ true https://github.com/MajMcCloud/TelegramBotFramework https://github.com/MajMcCloud/TelegramBotFramework - - moving from .Net Framework 4.7.2 to .Net Standard 2.1 for the Library and .Net Core 3.1 for the test project! + - Dependency update. Removing .Net Framework target and replacing with .Net Standard 2.0 Debug;Release; MIT false @@ -67,7 +67,6 @@ - From fc33da0496d1e11596005dcac7bcfd6d713bc555 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 17 Dec 2021 15:15:58 +0100 Subject: [PATCH 26/57] Fixing empty message field --- TelegramBotBase/Base/DataResult.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/TelegramBotBase/Base/DataResult.cs b/TelegramBotBase/Base/DataResult.cs index 55ff7b2..9168f75 100644 --- a/TelegramBotBase/Base/DataResult.cs +++ b/TelegramBotBase/Base/DataResult.cs @@ -18,7 +18,7 @@ namespace TelegramBotBase.Base //public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; } - public UpdateResult Update { get; set; } + public UpdateResult UpdateData { get; set; } public Contact Contact @@ -87,6 +87,14 @@ namespace TelegramBotBase.Base } } + public override Message Message + { + get + { + return this.UpdateData?.Message; + } + } + /// /// Returns the FileId of the first reachable element. /// @@ -119,7 +127,7 @@ namespace TelegramBotBase.Base public DataResult(UpdateResult update) { - this.Update = update; + this.UpdateData = update; } From 1cc0a2bdf73a8ceaad2e44dd9d0b3ad7a72838e3 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 19 Dec 2021 14:55:23 +0100 Subject: [PATCH 27/57] Ignore Callback queries with original image attached to message, no SentData event --- .../MessageLoops/FormBaseMessageLoop.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs b/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs index a902fe0..6568e19 100644 --- a/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs +++ b/TelegramBotBase/Factories/MessageLoops/FormBaseMessageLoop.cs @@ -29,8 +29,8 @@ namespace TelegramBotBase.Factories.MessageLoops var update = ur.RawData; - if (update.Type != Telegram.Bot.Types.Enums.UpdateType.Message - && update.Type != Telegram.Bot.Types.Enums.UpdateType.EditedMessage + if (update.Type != Telegram.Bot.Types.Enums.UpdateType.Message + && update.Type != Telegram.Bot.Types.Enums.UpdateType.EditedMessage && update.Type != Telegram.Bot.Types.Enums.UpdateType.CallbackQuery) { return; @@ -45,14 +45,9 @@ namespace TelegramBotBase.Factories.MessageLoops if (sce.Handled) return; } - - //var mr = new MessageResult(update); - - mr.Device = session; - - //var message = update.Message ?? update.EditedMessage; - + mr.Device = session; + var activeForm = session.ActiveForm; //Pre Loading Event @@ -64,11 +59,19 @@ namespace TelegramBotBase.Factories.MessageLoops //Loading Event await activeForm.Load(mr); - //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) - if (mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Location | - mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio) + + //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) (Ignore Callback Queries) + if (update.Type == Telegram.Bot.Types.Enums.UpdateType.Message) { - await activeForm.SentData(new DataResult(ur)); + if (mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact + | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Document + | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Location + | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo + | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Video + | mr.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio) + { + await activeForm.SentData(new DataResult(ur)); + } } //Action Event From 0ebba5e204b22fccb07a4281c96c1d089c01dcaf Mon Sep 17 00:00:00 2001 From: Florian Dahn Date: Mon, 20 Dec 2021 14:15:52 +0100 Subject: [PATCH 28/57] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 936392b..fb572bc 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,17 @@ Download a release: [Releases](https://github.com/MajMcCloud/TelegramBotFramewor Donations -Bitcoin: 1NqyGWmZg8HLp9qQELbf6bChEoba3mxaFc +Bitcoin: 1GoUJYMwAvBipQTfw2FKydAz12J8RDyeJs / bc1qqwlp0p5ley29lsu6jhe0qv7s7963kfc7d0m53d -ETH: 0x795B70CFC27C69603ce115F2b450cbAC5a5460D0 +ETH: 0xAf3835104c2C3E5b3e721FA2c7365955e87DB931 -Litecoin: LM5iCN6Nz22wAi8LSFnKgdGGWEtxWfJZXv +Litecoin: LRhF1eB7kneFontcDRDU8YjJhEm2GoYHch -DASH: Xb2qyVefvbKTXusHoxZ4Soja2S6R4vLsSr +DASH: XudiUwWtSmAJj1QDdVW7jocQumJFLsyoGZ -Paypal: https://paypal.me/majmccloud +TRON: TYVZSykaVT1nKZnz9hjDgBRNB9VavU1bpW + +BITTORRENT: TYVZSykaVT1nKZnz9hjDgBRNB9VavU1bpW Thanks ! From b508a7e3ce664695e4c578bd272baf00f23d1eac Mon Sep 17 00:00:00 2001 From: Florian Dahn Date: Mon, 20 Dec 2021 14:16:28 +0100 Subject: [PATCH 29/57] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9323a68..296db4e 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,17 @@ Download a release: [Releases](https://github.com/MajMcCloud/TelegramBotFramewor Donations -Bitcoin: 1NqyGWmZg8HLp9qQELbf6bChEoba3mxaFc +Bitcoin: 1GoUJYMwAvBipQTfw2FKydAz12J8RDyeJs / bc1qqwlp0p5ley29lsu6jhe0qv7s7963kfc7d0m53d -ETH: 0x795B70CFC27C69603ce115F2b450cbAC5a5460D0 +ETH: 0xAf3835104c2C3E5b3e721FA2c7365955e87DB931 -Litecoin: LM5iCN6Nz22wAi8LSFnKgdGGWEtxWfJZXv +Litecoin: LRhF1eB7kneFontcDRDU8YjJhEm2GoYHch -DASH: Xb2qyVefvbKTXusHoxZ4Soja2S6R4vLsSr +DASH: XudiUwWtSmAJj1QDdVW7jocQumJFLsyoGZ -Paypal: https://paypal.me/majmccloud +TRON: TYVZSykaVT1nKZnz9hjDgBRNB9VavU1bpW + +BITTORRENT: TYVZSykaVT1nKZnz9hjDgBRNB9VavU1bpW Thanks ! From 871d25b95bdf47d3542381abebaff3eb75bff384 Mon Sep 17 00:00:00 2001 From: Florian Dahn Date: Wed, 22 Dec 2021 15:38:46 +0100 Subject: [PATCH 30/57] Create README.md --- TelegramBotBase.Extensions.Images/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 TelegramBotBase.Extensions.Images/README.md diff --git a/TelegramBotBase.Extensions.Images/README.md b/TelegramBotBase.Extensions.Images/README.md new file mode 100644 index 0000000..9bec740 --- /dev/null +++ b/TelegramBotBase.Extensions.Images/README.md @@ -0,0 +1 @@ +TelegramBotBase.Extensions.Images From 4bd43de0feb0155f51f735eb8021d8eea4b003cd Mon Sep 17 00:00:00 2001 From: Florian Dahn Date: Wed, 22 Dec 2021 15:40:14 +0100 Subject: [PATCH 31/57] Update README.md --- TelegramBotBase.Extensions.Images/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TelegramBotBase.Extensions.Images/README.md b/TelegramBotBase.Extensions.Images/README.md index 9bec740..cdef1e3 100644 --- a/TelegramBotBase.Extensions.Images/README.md +++ b/TelegramBotBase.Extensions.Images/README.md @@ -1 +1,8 @@ -TelegramBotBase.Extensions.Images +# TelegramBotBase.Extensions.Images + +[![NuGet version (TelegramBotBase)](https://img.shields.io/nuget/v/TelegramBotBase.Extensions.Images.svg?style=flat-square)](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/) +[![telegram chat](https://img.shields.io/badge/Support_Chat-Telegram-blue.svg?style=flat-square)](https://www.t.me/tgbotbase) + + +[![license](https://img.shields.io/github/license/MajMcCloud/telegrambotframework.svg?style=flat-square&maxAge=2592000&label=License)](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md) +[![downloads](https://img.shields.io/nuget/dt/TelegramBotBase.Extensions.Images.svg?style=flat-square&label=Package%20Downloads)](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images) From 2c58f86524b168f30504110091150229094e4431 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 16:10:32 +0100 Subject: [PATCH 32/57] Adding localization selection step to BotBaseBuilder - Adding localization step - Updating test project --- TelegramBotBase/Builder/BotBaseBuilder.cs | 37 ++++++++++++++++--- .../Builder/Interfaces/ILanguageStage.cs | 36 ++++++++++++++++++ .../Interfaces/ISessionSerializationStage.cs | 10 ++--- TelegramBotBaseTest/Program.cs | 3 +- 4 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 TelegramBotBase/Builder/Interfaces/ILanguageStage.cs diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 0a91ea9..c8d41af 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -9,11 +9,12 @@ using TelegramBotBase.Builder.Interfaces; using TelegramBotBase.Commands; using TelegramBotBase.Form; using TelegramBotBase.Interfaces; +using TelegramBotBase.Localizations; using TelegramBotBase.States; namespace TelegramBotBase.Builder { - public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage + public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage, ILanguageSelectionStage { String _apiKey = null; @@ -156,36 +157,59 @@ namespace TelegramBotBase.Builder } - public IBuildingStage NoSerialization() + public ILanguageSelectionStage NoSerialization() { return this; } - public IBuildingStage UseSerialization(IStateMachine machine) + public ILanguageSelectionStage UseSerialization(IStateMachine machine) { this._statemachine = machine; return this; } - public IBuildingStage UseJSON(string path) + public ILanguageSelectionStage UseJSON(string path) { this._statemachine = new JSONStateMachine(path); return this; } - public IBuildingStage UseSimpleJSON(string path) + public ILanguageSelectionStage UseSimpleJSON(string path) { this._statemachine = new SimpleJSONStateMachine(path); return this; } - public IBuildingStage UseXML(string path) + public ILanguageSelectionStage UseXML(string path) { this._statemachine = new XMLStateMachine(path); return this; } + public IBuildingStage DefaultLanguage() + { + return this; + } + + public IBuildingStage UseEnglish() + { + Localizations.Default.Language = new Localizations.English(); + return this; + } + + public IBuildingStage UseGerman() + { + Localizations.Default.Language = new Localizations.German(); + return this; + } + + public IBuildingStage Custom(Localization language) + { + Localizations.Default.Language = language; + return this; + } + public BotBase Build() { var bb = new BotBase(); @@ -208,5 +232,6 @@ namespace TelegramBotBase.Builder return bb; } + } } diff --git a/TelegramBotBase/Builder/Interfaces/ILanguageStage.cs b/TelegramBotBase/Builder/Interfaces/ILanguageStage.cs new file mode 100644 index 0000000..2e5e01a --- /dev/null +++ b/TelegramBotBase/Builder/Interfaces/ILanguageStage.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TelegramBotBase.Localizations; + +namespace TelegramBotBase.Builder.Interfaces +{ + public interface ILanguageSelectionStage + { + + /// + /// Selects the default language for control usage. (English) + /// + /// + IBuildingStage DefaultLanguage(); + + /// + /// Selects english as the default language for control labels. + /// + /// + IBuildingStage UseEnglish(); + + /// + /// Selects german as the default language for control labels. + /// + /// + IBuildingStage UseGerman(); + + /// + /// Selects a custom language as the default language for control labels. + /// + /// + IBuildingStage Custom(Localization language); + + } +} diff --git a/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs b/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs index 7231c81..a729da2 100644 --- a/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs +++ b/TelegramBotBase/Builder/Interfaces/ISessionSerializationStage.cs @@ -11,7 +11,7 @@ namespace TelegramBotBase.Builder.Interfaces /// Do not uses serialization. /// /// - IBuildingStage NoSerialization(); + ILanguageSelectionStage NoSerialization(); /// @@ -19,7 +19,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage UseSerialization(IStateMachine machine); + ILanguageSelectionStage UseSerialization(IStateMachine machine); /// @@ -27,7 +27,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage UseJSON(String path); + ILanguageSelectionStage UseJSON(String path); /// @@ -35,7 +35,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage UseSimpleJSON(String path); + ILanguageSelectionStage UseSimpleJSON(String path); /// @@ -43,7 +43,7 @@ namespace TelegramBotBase.Builder.Interfaces /// /// /// - IBuildingStage UseXML(String path); + ILanguageSelectionStage UseXML(String path); } } diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBaseTest/Program.cs index 50c9319..d457fa8 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBaseTest/Program.cs @@ -34,11 +34,10 @@ namespace TelegramBotBaseTest a.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); }) .NoSerialization() + .UseEnglish() .Build(); - - bb.BotCommand += async (s, en) => { switch (en.Command) From e5d8e403a01be172c33cb77a770cba9963f8125a Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 16:12:26 +0100 Subject: [PATCH 33/57] Update readme with new BotBaseBuilder --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 296db4e..4fb135b 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ var bb = BotBaseBuilder }) .NoSerialization() + .UseEnglish() .Build(); //Update bot commands to botfather @@ -279,6 +280,7 @@ var bb = BotBaseBuilder }) .NoSerialization() + .UseEnglish() .Build(); bb.BotCommand += async (s, en) => @@ -996,6 +998,7 @@ var bb = BotBaseBuilder a.AddStartCommand("Starts the bot"); }) .UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json") + .UseEnglish() .Build(); //Start your Bot @@ -1020,6 +1023,7 @@ var bb = BotBaseBuilder a.AddStartCommand("Starts the bot"); }) .UseJSON(AppContext.BaseDirectory + "config\\states.json") + .UseEnglish() .Build(); //Start your Bot @@ -1045,6 +1049,7 @@ var bb = BotBaseBuilder a.AddStartCommand("Starts the bot"); }) .UseXML(AppContext.BaseDirectory + "config\\states.xml") + .UseEnglish() .Build(); //Start your Bot From b8bdc756d481743902cf370c312dd80f6c4e005b Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 16:13:31 +0100 Subject: [PATCH 34/57] Rename file to class name --- .../Interfaces/{ILanguageStage.cs => ILanguageSelectionStage.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TelegramBotBase/Builder/Interfaces/{ILanguageStage.cs => ILanguageSelectionStage.cs} (100%) diff --git a/TelegramBotBase/Builder/Interfaces/ILanguageStage.cs b/TelegramBotBase/Builder/Interfaces/ILanguageSelectionStage.cs similarity index 100% rename from TelegramBotBase/Builder/Interfaces/ILanguageStage.cs rename to TelegramBotBase/Builder/Interfaces/ILanguageSelectionStage.cs From 27e45b397dc124deafccac0abd70b7d9276480df Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 17:32:21 +0100 Subject: [PATCH 35/57] Changing debugtype to portable to allow snupkg file to be attached. - removing double Releae config in project settings - change debugtype to portable to allow correct snupkg package upload --- TelegramBotBase/TelegramBotBase.csproj | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index adf2a8a..d462240 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -19,6 +19,7 @@ $(VersionPrefix) + portable @@ -36,20 +37,9 @@ 4 - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\TelegramBotBase.xml - - - - pdbonly + portable true bin\Release\ TRACE From caf9b3cc8ee124376393f8c617a90db75910856b Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 17:34:20 +0100 Subject: [PATCH 36/57] Change version of polling library to 1.0.1 --- TelegramBotBase/TelegramBotBase.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index d462240..7d4eddc 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -58,7 +58,7 @@ - + From 21c6b2fde5b99ce5d37b6abd2414947a025f4dc5 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 17:34:47 +0100 Subject: [PATCH 37/57] removing .NET 472 compilation target from test project --- TelegramBotBaseTest/TelegramBotBaseTest.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotBaseTest/TelegramBotBaseTest.csproj b/TelegramBotBaseTest/TelegramBotBaseTest.csproj index 0224404..a1abbf6 100644 --- a/TelegramBotBaseTest/TelegramBotBaseTest.csproj +++ b/TelegramBotBaseTest/TelegramBotBaseTest.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1;net5;net472;net6 + netcoreapp3.1;net5;net6 false Debug;Release From 4f97e2a91916ce07b2f46a39b84b19c495c3de1e Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 17:47:11 +0100 Subject: [PATCH 38/57] Changing debugtype to portable to allow snupkg file to be attached. --- .../TelegramBotBase.Extensions.Images.csproj | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj index 87f356b..9f4e339 100644 --- a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -1,20 +1,21 @@  - - netstandard2.1;net472;net5;netcoreapp3.1;net6 - https://github.com/MajMcCloud/TelegramBotFramework - https://github.com/MajMcCloud/TelegramBotFramework - MIT - - + + netstandard2.1;net472;net5;netcoreapp3.1;net6 + https://github.com/MajMcCloud/TelegramBotFramework + https://github.com/MajMcCloud/TelegramBotFramework + MIT + true + snupkg + - - - - + + + + - - - + + + \ No newline at end of file From c6106f17ecddf785498066b52e9965cb1d306fc7 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 25 Dec 2021 17:52:17 +0100 Subject: [PATCH 39/57] Removing .Net 4.7.2 and adding .Net Standard 2.0 instead of 2.1 - removing .Net 4.7.2 compilation target - changing .Net Standard from 2.1 to 2.0 for backwards compatibility --- .../TelegramBotBase.Extensions.Images.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj index 9f4e339..c73c1ce 100644 --- a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -1,7 +1,7 @@  - netstandard2.1;net472;net5;netcoreapp3.1;net6 + netstandard2.0;net5;netcoreapp3.1;net6 https://github.com/MajMcCloud/TelegramBotFramework https://github.com/MajMcCloud/TelegramBotFramework MIT From c5fa153d54e1695635017a875c1286b43cf297c8 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Tue, 4 Jan 2022 23:40:33 +0200 Subject: [PATCH 40/57] Replace KickChatMemberAsync/KickUser --- TelegramBotBase/Sessions/DeviceSession.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index da0a5ed..945abfd 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -697,11 +697,24 @@ namespace TelegramBotBase.Sessions return null; } + [Obsolete("User BanUser instead.")] public virtual async Task KickUser(long userId, DateTime until = default(DateTime)) { try { - await API(a => a.KickChatMemberAsync(this.DeviceId, userId, until)); + await API(a => a.BanChatMemberAsync(this.DeviceId, userId, until)); + } + catch + { + + } + } + + public virtual async Task BanUser(long userId, DateTime until = default(DateTime)) + { + try + { + await API(a => a.BanChatMemberAsync(this.DeviceId, userId, until)); } catch { From 584bb76e0f678292d6d3319fc24404eb4d5a75f7 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Tue, 4 Jan 2022 23:42:13 +0200 Subject: [PATCH 41/57] Adding comments --- TelegramBotBase/BotBase.cs | 12 +++++++++++- TelegramBotBase/SessionBase.cs | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index e5a6d93..3441673 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -73,9 +73,14 @@ namespace TelegramBotBase /// public IStartFormFactory StartFormFactory { get; set; } + /// + /// Contains the message loop factory, which cares about "message-management." + /// public IMessageLoopFactory MessageLoopFactory { get; set; } - + /// + /// All internal used settings. + /// public Dictionary SystemSettings { get; private set; } public BotBase() @@ -515,6 +520,11 @@ namespace TelegramBotBase // } //} + /// + /// Will get invoke on an unhandled call. + /// + /// + /// public void MessageLoopFactory_UnhandledCall(object sender, UnhandledCallEventArgs e) { OnUnhandledCall(e); diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs index 60e947f..b94f59a 100644 --- a/TelegramBotBase/SessionBase.cs +++ b/TelegramBotBase/SessionBase.cs @@ -18,10 +18,20 @@ namespace TelegramBotBase /// public class SessionBase { + /// + /// The Basic message client. + /// public MessageClient Client { get; set; } + /// + /// A list of all active sessions. + /// public Dictionary SessionList { get; set; } + + /// + /// Reference to the Main BotBase instance for later use. + /// public BotBase BotBase { get; set; } From ca1c3829242187939aba26634a644b28365db488 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Tue, 4 Jan 2022 23:44:43 +0200 Subject: [PATCH 42/57] Removing old commented stuff --- TelegramBotBase/BotBase.cs | 355 ------------------------------------- 1 file changed, 355 deletions(-) diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index 3441673..bfeeb1e 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -206,211 +206,6 @@ namespace TelegramBotBase - //private async void Client_Message(object sender, MessageResult e) - //{ - // if (this.GetSetting(eSettings.SkipAllMessages, false)) - // return; - - // try - // { - // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - // e.Device = ds; - - // if (this.GetSetting(eSettings.LogAllMessages, false)) - // { - // OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); - // } - - // ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); - - // await Client_Loop(sender, e); - // } - // catch (Telegram.Bot.Exceptions.ApiRequestException ex) - // { - - // } - // catch (Exception ex) - // { - // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - // OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); - // } - //} - - - - //private async Task Client_TryMessage(object sender, MessageResult e) - //{ - // DeviceSession ds = e.Device; - // if (ds == null) - // { - // ds = await this.Sessions.StartSession(e.DeviceId); - // e.Device = ds; - - // ds.LastMessage = e.Message; - - // OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); - // } - - // ds.LastAction = DateTime.Now; - // ds.LastMessage = e.Message; - - // //Is this a bot command ? - // if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0) - // { - // var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds); - // await OnBotCommand(sce); - - // if (sce.Handled) - // return; - // } - - // FormBase activeForm = null; - - // int i = 0; - - // //Should formulars get navigated (allow maximum of 10, to dont get loops) - // do - // { - // i++; - - // //Reset navigation - // ds.FormSwitched = false; - - // activeForm = ds.ActiveForm; - - // //Pre Loading Event - // await activeForm.PreLoad(e); - - // //Send Load event to controls - // await activeForm.LoadControls(e); - - // //Loading Event - // await activeForm.Load(e); - - // //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) - // if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Contact | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Location | - // e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Photo | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Video | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Audio) - // { - // await activeForm.SentData(new DataResult(e)); - // } - - // //Render Event - // if (!ds.FormSwitched) - // { - // await activeForm.RenderControls(e); - - // await activeForm.Render(e); - // } - - // e.IsFirstHandler = false; - - // } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); - - - //} - - - //private async Task Client_Loop(object sender, MessageResult e) - //{ - // DeviceSession ds = e.Device; - // if (ds == null) - // { - // ds = await this.Sessions.StartSession(e.DeviceId); - // e.Device = ds; - // ds.LastMessage = e.Message; - - // OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); - // } - - // ds.LastAction = DateTime.Now; - // ds.LastMessage = e.Message; - - // //Is this a bot command ? - // if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0) - // { - // var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds); - // await OnBotCommand(sce); - - // if (sce.Handled) - // return; - // } - - // FormBase activeForm = null; - - // int i = 0; - - // //Should formulars get navigated (allow maximum of 10, to dont get loops) - // do - // { - // i++; - - - - // //Reset navigation - // ds.FormSwitched = false; - - // activeForm = ds.ActiveForm; - - - - // //Pre Loading Event - // await activeForm.PreLoad(e); - - // //Send Load event to controls - // await activeForm.LoadControls(e); - - // //Loading Event - // await activeForm.Load(e); - - // //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) - // if (e.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Location | - // e.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio) - // { - // await activeForm.SentData(new DataResult(e)); - // } - - // //Action Event - // if (!ds.FormSwitched && e.IsAction) - // { - // //Send Action event to controls - // await activeForm.ActionControls(e); - - // //Send Action event to form itself - // await activeForm.Action(e); - - // if (!e.Handled) - // { - // var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); - // OnUnhandledCall(uhc); - - // if (uhc.Handled) - // { - // e.Handled = true; - // if (!ds.FormSwitched) - // { - // break; - // } - // } - // } - - // } - - // if (!ds.FormSwitched) - // { - // //Render Event - // await activeForm.RenderControls(e); - - // await activeForm.Render(e); - // } - - // e.IsFirstHandler = false; - - // } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); - - - //} - - /// /// This will invoke the full message loop for the device even when no "userevent" like message or action has been raised. /// @@ -445,81 +240,6 @@ namespace TelegramBotBase } - //private async void Client_MessageEdit(object sender, MessageResult e) - //{ - // if (this.GetSetting(eSettings.SkipAllMessages, false)) - // return; - - // try - // { - // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - // e.Device = ds; - - // if (this.GetSetting(eSettings.LogAllMessages, false)) - // { - // OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); - // } - - // //Call same, to handle received liked edited - // ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); - - // await Client_TryMessageEdit(sender, e); - // } - // catch (Telegram.Bot.Exceptions.ApiRequestException ex) - // { - - // } - // catch (Exception ex) - // { - // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - // OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); - // } - //} - - //private async Task Client_TryMessageEdit(object sender, MessageResult e) - //{ - // DeviceSession ds = e.Device; - // if (ds == null) - // { - // ds = await this.Sessions.StartSession(e.DeviceId); - // e.Device = ds; - // } - - // ds.LastAction = DateTime.Now; - // ds.LastMessage = e.Message; - - // //Pre Loading Event - // await ds.ActiveForm.Edited(e); - - // //When form has been switched due navigation within the edit method, reopen Client_Message - // if (ds.FormSwitched) - // { - // await Client_Loop(sender, e); - // } - - //} - - //private async void Client_Action(object sender, MessageResult e) - //{ - // try - // { - // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - // e.Device = ds; - - // if (this.GetSetting(eSettings.LogAllMessages, false)) - // { - // OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); - // } - - // await Client_Loop(sender, e); - // } - // catch (Exception ex) - // { - // DeviceSession ds = this.Sessions.GetSession(e.DeviceId); - // OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); - // } - //} - /// /// Will get invoke on an unhandled call. /// @@ -530,81 +250,6 @@ namespace TelegramBotBase OnUnhandledCall(e); } - //private async void Client_TryAction(object sender, MessageResult e) - //{ - // DeviceSession ds = e.Device; - // if (ds == null) - // { - // ds = await this.Sessions.StartSession(e.DeviceId); - // e.Device = ds; - // } - - // ds.LastAction = DateTime.Now; - // ds.LastMessage = e.Message; - - // FormBase activeForm = null; - - // int i = 0; - - // //Should formulars get navigated (allow maximum of 10, to dont get loops) - // do - // { - // i++; - - // //Reset navigation - // ds.FormSwitched = false; - - // activeForm = ds.ActiveForm; - - // //Pre Loading Event - // await activeForm.PreLoad(e); - - // //Send Load event to controls - // await activeForm.LoadControls(e); - - // //Loading Event - // await activeForm.Load(e); - - // //Action Event - // if (!ds.FormSwitched) - // { - // //Send Action event to controls - // await activeForm.ActionControls(e); - - // //Send Action event to form itself - // await activeForm.Action(e); - - // if (!e.Handled) - // { - // var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); - // OnUnhandledCall(uhc); - - // if (uhc.Handled) - // { - // e.Handled = true; - // if (!ds.FormSwitched) - // { - // break; - // } - // } - // } - - // } - - // //Render Event - // if (!ds.FormSwitched) - // { - // await activeForm.RenderControls(e); - - // await activeForm.Render(e); - // } - - // e.IsFirstHandler = false; - - // } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); - - //} - /// /// This method will update all local created bot commands to the botfather. /// From b65ec13d8bd34d73a43806cefc28236e8089f6b1 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 01:16:22 +0200 Subject: [PATCH 43/57] Simplifying BotBuilder BotCommands - Simplifying BotBuilder BotCommands - updating test project --- TelegramBotBase/Builder/BotBaseBuilder.cs | 6 +++--- TelegramBotBase/Commands/Extensions.cs | 17 ++++++++++++++--- TelegramBotBaseTest/Program.cs | 12 ++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index c8d41af..bf44005 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -144,9 +144,9 @@ namespace TelegramBotBase.Builder public ISessionSerializationStage DefaultCommands() { - _botcommands.AddStartCommand("Starts the bot"); - _botcommands.AddHelpCommand("Should show you some help"); - _botcommands.AddSettingsCommand("Should show you some settings"); + _botcommands.Start("Starts the bot"); + _botcommands.Help("Should show you some help"); + _botcommands.Settings("Should show you some settings"); return this; } diff --git a/TelegramBotBase/Commands/Extensions.cs b/TelegramBotBase/Commands/Extensions.cs index b866439..a07c031 100644 --- a/TelegramBotBase/Commands/Extensions.cs +++ b/TelegramBotBase/Commands/Extensions.cs @@ -12,7 +12,7 @@ namespace TelegramBotBase.Commands /// /// /// - public static void AddStartCommand(this List cmds, String description) + public static void Start(this List cmds, String description) { cmds.Add(new BotCommand() { Command = "start", Description = description }); } @@ -22,7 +22,7 @@ namespace TelegramBotBase.Commands /// /// /// - public static void AddHelpCommand(this List cmds, String description) + public static void Help(this List cmds, String description) { cmds.Add(new BotCommand() { Command = "help", Description = description }); } @@ -32,9 +32,20 @@ namespace TelegramBotBase.Commands /// /// /// - public static void AddSettingsCommand(this List cmds, String description) + public static void Settings(this List cmds, String description) { cmds.Add(new BotCommand() { Command = "settings", Description = description }); } + + /// + /// Adding the command with a description. + /// + /// + /// + /// + public static void Add(this List cmds, String command, String description) + { + cmds.Add(new BotCommand() { Command = command, Description = description }); + } } } diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBaseTest/Program.cs index d457fa8..3ba3a2e 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBaseTest/Program.cs @@ -26,12 +26,12 @@ namespace TelegramBotBaseTest .NoProxy() .CustomCommands(a => { - a.AddStartCommand("Starts the bot"); - a.AddHelpCommand("Should show you some help"); - a.AddSettingsCommand("Should show you some settings"); - a.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); - a.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" }); - a.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); + a.Start("Starts the bot"); + a.Help("Should show you some help"); + a.Settings("Should show you some settings"); + a.Add("form1", "Opens test form 1"); + a.Add("form2", "Opens test form 2"); + a.Add("params", "Returns all send parameters as a message."); }) .NoSerialization() .UseEnglish() From 2b914f6f58d2aefae792ca67159d01c9a0a3b26c Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 01:17:44 +0200 Subject: [PATCH 44/57] Changing CustomMessageLoop parameter --- TelegramBotBase/Builder/BotBaseBuilder.cs | 7 ++----- .../Builder/Interfaces/IMessageLoopSelectionStage.cs | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index bf44005..9a021d7 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -54,12 +54,9 @@ namespace TelegramBotBase.Builder return this; } - public IStartFormSelectionStage CustomMessageLoop(Type messageLoopClass) + public IStartFormSelectionStage CustomMessageLoop(IMessageLoopFactory messageLoopClass) { - if (messageLoopClass.IsSubclassOf(typeof(IMessageLoopFactory))) - throw new ArgumentException($"Not a subclass of {nameof(IMessageLoopFactory)}"); - - _messageloopfactory = messageLoopClass.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as IMessageLoopFactory; + _messageloopfactory = messageLoopClass; return this; } diff --git a/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs index 125945e..02cf87e 100644 --- a/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IMessageLoopSelectionStage.cs @@ -19,9 +19,9 @@ namespace TelegramBotBase.Builder.Interfaces /// /// Chooses a custom message loop. /// - /// + /// /// - IStartFormSelectionStage CustomMessageLoop(Type startFormClass); + IStartFormSelectionStage CustomMessageLoop(IMessageLoopFactory startFormClass); /// From 09d7164385bb484695e85a675df99b619da4a7c3 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 14:22:21 +0100 Subject: [PATCH 45/57] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4fb135b..89d134e 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ var bb = BotBaseBuilder .NoProxy() .CustomCommands(a => { - a.AddStartCommand("Starts the bot") + a.Start("Starts the bot") }) .NoSerialization() @@ -272,10 +272,10 @@ var bb = BotBaseBuilder .NoProxy() .CustomCommands(a => { - a.AddStartCommand("Starts the bot"); - a.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" }); - a.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" }); - a.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." }); + a.Start("Starts the bot"); + a.Add("form1","Opens test form 1" ); + a.Add("form2", "Opens test form 2" ); + a.Add("params", "Returns all send parameters as a message." ); }) @@ -995,7 +995,7 @@ var bb = BotBaseBuilder .NoProxy() .CustomCommands(a => { - a.AddStartCommand("Starts the bot"); + a.Start("Starts the bot"); }) .UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json") .UseEnglish() @@ -1020,7 +1020,7 @@ var bb = BotBaseBuilder .NoProxy() .CustomCommands(a => { - a.AddStartCommand("Starts the bot"); + a.Start("Starts the bot"); }) .UseJSON(AppContext.BaseDirectory + "config\\states.json") .UseEnglish() @@ -1046,7 +1046,7 @@ var bb = BotBaseBuilder .NoProxy() .CustomCommands(a => { - a.AddStartCommand("Starts the bot"); + a.Start("Starts the bot"); }) .UseXML(AppContext.BaseDirectory + "config\\states.xml") .UseEnglish() From d5a89a4ed861ada89ee491f4a776da53406b8af0 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:25:04 +0100 Subject: [PATCH 46/57] Adding regions to BotBaseBuilder --- TelegramBotBase/Builder/BotBaseBuilder.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 9a021d7..d76f3f8 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -34,7 +34,7 @@ namespace TelegramBotBase.Builder return new BotBaseBuilder(); } - #region "Step 1" + #region "Step 1 (Basic Stuff)" public IMessageLoopSelectionStage WithAPIKey(string apiKey) { @@ -45,7 +45,7 @@ namespace TelegramBotBase.Builder #endregion - #region "Step 2" + #region "Step 2 (Message Loop)" public IStartFormSelectionStage DefaultMessageLoop() { @@ -71,7 +71,7 @@ namespace TelegramBotBase.Builder #endregion - #region "Step 3" + #region "Step 3 (Start Form/Factory)" public INetworkingSelectionStage WithStartForm(Type startFormClass) { @@ -94,6 +94,7 @@ namespace TelegramBotBase.Builder #endregion + #region "Step 4 (Network Settings)" public IBotCommandsStage WithProxy(string proxyAddress) { @@ -134,6 +135,11 @@ namespace TelegramBotBase.Builder return this; } + + #endregion + + #region "Step 5 (Bot Commands)" + public ISessionSerializationStage NoCommands() { return this; @@ -153,6 +159,9 @@ namespace TelegramBotBase.Builder return this; } + #endregion + + #region "Step 6 (Serialization)" public ILanguageSelectionStage NoSerialization() { @@ -184,6 +193,10 @@ namespace TelegramBotBase.Builder return this; } + #endregion + + #region "Step 7 (Language)" + public IBuildingStage DefaultLanguage() { return this; @@ -207,6 +220,8 @@ namespace TelegramBotBase.Builder return this; } + #endregion + public BotBase Build() { var bb = new BotBase(); From 18bb6584f43153dd91ec413a7b737e7d909bb4d4 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:25:33 +0100 Subject: [PATCH 47/57] Adding OnlyStart BotBaseBuilder command option --- TelegramBotBase/Builder/BotBaseBuilder.cs | 8 ++++++++ TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index d76f3f8..861a12a 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -145,6 +145,14 @@ namespace TelegramBotBase.Builder return this; } + public ISessionSerializationStage OnlyStart() + { + _botcommands.Start("Starts the bot"); + + return this; + + } + public ISessionSerializationStage DefaultCommands() { _botcommands.Start("Starts the bot"); diff --git a/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs b/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs index 9dcdadf..cb1507c 100644 --- a/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IBotCommandsStage.cs @@ -21,6 +21,13 @@ namespace TelegramBotBase.Builder.Interfaces ISessionSerializationStage DefaultCommands(); + /// + /// Only adds the start command. + /// + /// + ISessionSerializationStage OnlyStart(); + + /// /// Gives you the ability to add custom commands. /// From f03e67f345cda5ac2cff72c0454e0b5b0c45554f Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:26:10 +0100 Subject: [PATCH 48/57] Adding QuickStart Option for BotBaseBuilder --- TelegramBotBase/Builder/BotBaseBuilder.cs | 58 ++++++++++++++++++- .../Interfaces/IAPIKeySelectionStage.cs | 28 +++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 861a12a..dd194bf 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -42,6 +42,63 @@ namespace TelegramBotBase.Builder return this; } + + public IBuildingStage QuickStart(string apiKey, Type StartForm) + { + this._apiKey = apiKey; + this._factory = new Factories.DefaultStartFormFactory(StartForm); + + DefaultMessageLoop(); + + NoProxy(); + + OnlyStart(); + + NoSerialization(); + + DefaultLanguage(); + + return this; + } + + + public IBuildingStage QuickStart(string apiKey) + where T : FormBase + { + this._apiKey = apiKey; + this._factory = new Factories.DefaultStartFormFactory(typeof(T)); + + DefaultMessageLoop(); + + NoProxy(); + + OnlyStart(); + + NoSerialization(); + + DefaultLanguage(); + + return this; + } + + public IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory) + { + this._apiKey = apiKey; + this._factory = StartFormFactory; + + DefaultMessageLoop(); + + NoProxy(); + + OnlyStart(); + + NoSerialization(); + + DefaultLanguage(); + + return this; + } + #endregion @@ -252,6 +309,5 @@ namespace TelegramBotBase.Builder return bb; } - } } diff --git a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs index cfa6131..bd6f05e 100644 --- a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Text; +using TelegramBotBase.Form; +using TelegramBotBase.Interfaces; namespace TelegramBotBase.Builder.Interfaces { @@ -13,5 +15,31 @@ namespace TelegramBotBase.Builder.Interfaces /// IMessageLoopSelectionStage WithAPIKey(String apiKey); + + /// + /// Quick and easy way to create a BotBase instance. + /// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage + /// + /// + /// + /// + IBuildingStage QuickStart(String apiKey, Type StartForm); + + /// + /// Quick and easy way to create a BotBase instance. + /// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage + /// + /// + /// + IBuildingStage QuickStart(String apiKey) where T : FormBase; + + /// + /// Quick and easy way to create a BotBase instance. + /// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage + /// + /// + /// + /// + IBuildingStage QuickStart(String apiKey, IStartFormFactory StartFormFactory); } } From d0d93a07c024b9de065a7355c34a816adab0cd96 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:30:25 +0100 Subject: [PATCH 49/57] Adding QuickStart to readme. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 89d134e..c751bd5 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Thanks ! ## Index - [Introduction](#introduction) - [How to Start](#how-to-start) +- [Quick Start](#quick-start) - [Message Handling](#message-handling) * [Example #0 - System Calls](#add-some-system-calls-example-0---system-calls) @@ -241,6 +242,28 @@ var tf = new TestForm(); await this.NavigateTo(tf); ``` +## Quick Start: + + +When migrating from a previous version or starting completely new, all these options can be a bit overwhelming. +For this I added a QuickStart option, directly after the Create call. It just need basic parameters like in earlier versions. + + +``` + +//Prepare the System (New in V5) +var bb = BotBaseBuilder + .Create() + .QuickStart("{YOUR API KEY}", StartForm) + .Build(); + +//Start your Bot +bb.Start(); + +``` + + + ## Message Handling All examples are within the test project, so just try it out on your own. From 7d2703138c10a19455bd5db71b6896c0b2fd71e1 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:31:30 +0100 Subject: [PATCH 50/57] Readme fix to "generics" like in earlier versions. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c751bd5..dbe65ea 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ For this I added a QuickStart option, directly after the Create call. It just ne //Prepare the System (New in V5) var bb = BotBaseBuilder .Create() - .QuickStart("{YOUR API KEY}", StartForm) + .QuickStart("{YOUR API KEY}") .Build(); //Start your Bot From 4f85677deb82529a92e9117d0f908d6099642b5a Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:39:06 +0100 Subject: [PATCH 51/57] Comment Cleanup --- TelegramBotBase/Base/DataResult.cs | 25 ------ TelegramBotBase/Base/MessageClient.cs | 111 -------------------------- TelegramBotBase/BotBase.cs | 8 -- 3 files changed, 144 deletions(-) diff --git a/TelegramBotBase/Base/DataResult.cs b/TelegramBotBase/Base/DataResult.cs index 9168f75..8fc9e34 100644 --- a/TelegramBotBase/Base/DataResult.cs +++ b/TelegramBotBase/Base/DataResult.cs @@ -70,15 +70,6 @@ namespace TelegramBotBase.Base } - //public Telegram.Bot.Types.Enums.MessageType Type - //{ - // get - // { - // return this.RawMessageData?.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown; - // } - //} - - public Telegram.Bot.Types.Enums.MessageType Type { get @@ -109,22 +100,6 @@ namespace TelegramBotBase.Base } } - - //public DataResult(Telegram.Bot.Args.MessageEventArgs rawdata) - //{ - // this.RawMessageData = rawdata; - // this.Message = rawdata.Message; - //} - - //public DataResult(MessageResult message) - //{ - // this.RawMessageData = message.RawMessageData; - // this.Message = message.Message; - - // this.Client = message.Client; - //} - - public DataResult(UpdateResult update) { this.UpdateData = update; diff --git a/TelegramBotBase/Base/MessageClient.cs b/TelegramBotBase/Base/MessageClient.cs index 80327fb..e252f35 100644 --- a/TelegramBotBase/Base/MessageClient.cs +++ b/TelegramBotBase/Base/MessageClient.cs @@ -112,11 +112,6 @@ namespace TelegramBotBase.Base { this.TelegramClient.Timeout = new TimeSpan(0, 0, 30); - - //this.TelegramClient.OnMessage += TelegramClient_OnMessage; - //this.TelegramClient.OnMessageEdited += TelegramClient_OnMessageEdited; - //this.TelegramClient.OnCallbackQuery += TelegramClient_OnCallbackQuery; - } @@ -139,58 +134,6 @@ namespace TelegramBotBase.Base } - //private async void TelegramClient_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) - //{ - // //Skip empty messages by default - // if (e.Message == null) - // return; - - // try - // { - // var mr = new MessageResult(e); - // mr.Client = this; - // OnMessage(mr); - // } - // catch - // { - - // } - //} - - - //private async void TelegramClient_OnMessageEdited(object sender, Telegram.Bot.Args.MessageEventArgs e) - //{ - // //Skip empty messages by default - // if (e.Message == null) - // return; - - // try - // { - // var mr = new MessageResult(e); - // mr.Client = this; - // OnMessageEdit(mr); - // } - // catch - // { - - // } - //} - - //private async void TelegramClient_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e) - //{ - // try - // { - // var ar = new MessageResult(e); - // ar.Client = this; - // OnAction(ar); - // } - // catch - // { - - // } - //} - - public Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) { OnMessageLoop(new UpdateResult(update, null)); @@ -256,60 +199,6 @@ namespace TelegramBotBase.Base } - //public event EventHandler Message - //{ - // add - // { - // this.__Events.AddHandler(__evOnMessage, value); - // } - // remove - // { - // this.__Events.RemoveHandler(__evOnMessage, value); - // } - //} - - //public void OnMessage(MessageResult result) - //{ - // (this.__Events[__evOnMessage] as EventHandler)?.Invoke(this, result); - //} - - - - //public event EventHandler MessageEdit - //{ - // add - // { - // this.__Events.AddHandler(__evOnMessageEdit, value); - // } - // remove - // { - // this.__Events.RemoveHandler(__evOnMessageEdit, value); - // } - //} - - //public void OnMessageEdit(MessageResult result) - //{ - // (this.__Events[__evOnMessageEdit] as EventHandler)?.Invoke(this, result); - //} - - //public event EventHandler Action - //{ - // add - // { - // this.__Events.AddHandler(__evCallbackQuery, value); - // } - // remove - // { - // this.__Events.RemoveHandler(__evCallbackQuery, value); - // } - //} - - //public void OnAction(MessageResult result) - //{ - // (this.__Events[__evCallbackQuery] as EventHandler)?.Invoke(this, result); - //} - - #endregion diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index bfeeb1e..c853c30 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -111,10 +111,6 @@ namespace TelegramBotBase this.Client.MessageLoop += Client_MessageLoop; - //this.Client.Message += Client_Message; - //this.Client.MessageEdit += Client_MessageEdit; - //this.Client.Action += Client_Action; - if (this.StateMachine != null) { @@ -178,10 +174,6 @@ namespace TelegramBotBase this.Client.MessageLoop -= Client_MessageLoop; - //this.Client.Message -= Client_Message; - //this.Client.MessageEdit -= Client_MessageEdit; - //this.Client.Action -= Client_Action; - this.Client.StopReceiving(); From 50fd5255c8cf9f7966d7f6865add5a7c53551feb Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:39:35 +0100 Subject: [PATCH 52/57] Adding SourceLink to Image Extension --- .../TelegramBotBase.Extensions.Images.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj index c73c1ce..4b974c8 100644 --- a/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj +++ b/TelegramBotBase.Extensions.Images/TelegramBotBase.Extensions.Images.csproj @@ -10,6 +10,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From ff3c22566a066c0cbb7a388525a304d3444f6a6a Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Wed, 5 Jan 2022 18:40:44 +0100 Subject: [PATCH 53/57] Comment Cleanup --- TelegramBotBase/Base/MessageResult.cs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/TelegramBotBase/Base/MessageResult.cs b/TelegramBotBase/Base/MessageResult.cs index 8ecf3fd..762ac8f 100644 --- a/TelegramBotBase/Base/MessageResult.cs +++ b/TelegramBotBase/Base/MessageResult.cs @@ -12,11 +12,6 @@ namespace TelegramBotBase.Base public class MessageResult : ResultBase { - //public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; } - - //public Telegram.Bot.Args.CallbackQueryEventArgs RawCallbackData { get; set; } - - public Telegram.Bot.Types.Update UpdateData { get; set; } /// @@ -207,18 +202,5 @@ namespace TelegramBotBase.Base } - - //public MessageResult(Telegram.Bot.Args.MessageEventArgs rawdata) - //{ - // this.RawMessageData = rawdata; - // this.Message = rawdata.Message; - //} - - //public MessageResult(Telegram.Bot.Args.CallbackQueryEventArgs callback) - //{ - // this.RawCallbackData = callback; - // this.Message = callback.CallbackQuery.Message; - //} - } } From 5453add9564030a73cdada1a003b34375ff116f9 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Thu, 6 Jan 2022 15:53:41 +0100 Subject: [PATCH 54/57] Renaming TelegramBotBaseTest -> TelegramBotBase.Test --- .../App.config | 0 .../Program.cs | 4 +++- .../Properties/AssemblyInfo.cs | 0 .../TelegramBotBaseTest.csproj | 0 .../Tests/ButtonTestForm.cs | 0 .../Tests/Controls/ButtonGridForm.cs | 0 .../Tests/Controls/ButtonGridPagingForm.cs | 0 .../Tests/Controls/ButtonGridTagForm.cs | 0 .../Tests/Controls/CalendarPickerForm.cs | 0 .../Tests/Controls/CheckedButtonListForm.cs | 0 .../Tests/Controls/MonthPickerForm.cs | 0 .../Tests/Controls/MultiToggleButtons.cs | 0 .../Tests/Controls/MultiViewForm.cs | 20 ------------------- .../Tests/Controls/Subclass/MultiViewTest.cs | 0 .../Tests/Controls/ToggleButtons.cs | 0 .../Tests/Controls/TreeViewForms.cs | 0 .../Tests/DataForm.cs | 0 .../Tests/Datasources/CustomDataSource.cs | 0 .../Tests/Datasources/List.cs | 11 ---------- .../Tests/Groups/GroupChange.cs | 0 .../Tests/Groups/LinkReplaceTest.cs | 0 .../Tests/Groups/WelcomeUser.cs | 0 .../Tests/Menu.cs | 0 .../Tests/Navigation/CustomController.cs | 0 .../Tests/Navigation/Form1.cs | 0 .../Tests/Navigation/Start.cs | 0 .../Tests/Notifications/Start.cs | 0 .../Tests/ProgressTest.cs | 0 .../Tests/Register/PerForm.cs | 0 .../Tests/Register/PerStep.cs | 0 .../Tests/Register/Start.cs | 0 .../Tests/Register/Steps/Data.cs | 0 .../Tests/Register/Steps/Step1.cs | 0 .../Tests/Register/Steps/Step2.cs | 0 .../Tests/Register/Steps/Step3.cs | 0 .../Tests/SimpleForm.cs | 0 .../Tests/Start.cs | 0 .../Tests/TestForm.cs | 0 .../Tests/TestForm2.cs | 0 .../packages.config | 0 40 files changed, 3 insertions(+), 32 deletions(-) rename {TelegramBotBaseTest => TelegramBotBase.Test}/App.config (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Program.cs (91%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Properties/AssemblyInfo.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/TelegramBotBaseTest.csproj (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/ButtonTestForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/ButtonGridForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/ButtonGridPagingForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/ButtonGridTagForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/CalendarPickerForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/CheckedButtonListForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/MonthPickerForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/MultiToggleButtons.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/MultiViewForm.cs (82%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/Subclass/MultiViewTest.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/ToggleButtons.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Controls/TreeViewForms.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/DataForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Datasources/CustomDataSource.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Datasources/List.cs (87%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Groups/GroupChange.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Groups/LinkReplaceTest.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Groups/WelcomeUser.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Menu.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Navigation/CustomController.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Navigation/Form1.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Navigation/Start.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Notifications/Start.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/ProgressTest.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/PerForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/PerStep.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/Start.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/Steps/Data.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/Steps/Step1.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/Steps/Step2.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Register/Steps/Step3.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/SimpleForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/Start.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/TestForm.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/Tests/TestForm2.cs (100%) rename {TelegramBotBaseTest => TelegramBotBase.Test}/packages.config (100%) diff --git a/TelegramBotBaseTest/App.config b/TelegramBotBase.Test/App.config similarity index 100% rename from TelegramBotBaseTest/App.config rename to TelegramBotBase.Test/App.config diff --git a/TelegramBotBaseTest/Program.cs b/TelegramBotBase.Test/Program.cs similarity index 91% rename from TelegramBotBaseTest/Program.cs rename to TelegramBotBase.Test/Program.cs index 3ba3a2e..62e2f21 100644 --- a/TelegramBotBaseTest/Program.cs +++ b/TelegramBotBase.Test/Program.cs @@ -16,7 +16,9 @@ namespace TelegramBotBaseTest { static void Main(string[] args) { - String APIKey = ""; + //Test: 822283338:AAGmeSX5j65pcO3UKBQ7Ro_nuSaW9LCxwl0 + //Live: 480896099:AAE6M9WqvwFdBkk-tGKki4rgdOvoVxcHTBQ + String APIKey = "822283338:AAGmeSX5j65pcO3UKBQ7Ro_nuSaW9LCxwl0";// "822283338:AAGmeSX5j65pcO3UKBQ7Ro_nuSaW9LCxwl0"; var bb = BotBaseBuilder .Create() diff --git a/TelegramBotBaseTest/Properties/AssemblyInfo.cs b/TelegramBotBase.Test/Properties/AssemblyInfo.cs similarity index 100% rename from TelegramBotBaseTest/Properties/AssemblyInfo.cs rename to TelegramBotBase.Test/Properties/AssemblyInfo.cs diff --git a/TelegramBotBaseTest/TelegramBotBaseTest.csproj b/TelegramBotBase.Test/TelegramBotBaseTest.csproj similarity index 100% rename from TelegramBotBaseTest/TelegramBotBaseTest.csproj rename to TelegramBotBase.Test/TelegramBotBaseTest.csproj diff --git a/TelegramBotBaseTest/Tests/ButtonTestForm.cs b/TelegramBotBase.Test/Tests/ButtonTestForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/ButtonTestForm.cs rename to TelegramBotBase.Test/Tests/ButtonTestForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/ButtonGridForm.cs b/TelegramBotBase.Test/Tests/Controls/ButtonGridForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/ButtonGridForm.cs rename to TelegramBotBase.Test/Tests/Controls/ButtonGridForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/ButtonGridPagingForm.cs b/TelegramBotBase.Test/Tests/Controls/ButtonGridPagingForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/ButtonGridPagingForm.cs rename to TelegramBotBase.Test/Tests/Controls/ButtonGridPagingForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/ButtonGridTagForm.cs b/TelegramBotBase.Test/Tests/Controls/ButtonGridTagForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/ButtonGridTagForm.cs rename to TelegramBotBase.Test/Tests/Controls/ButtonGridTagForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/CalendarPickerForm.cs b/TelegramBotBase.Test/Tests/Controls/CalendarPickerForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/CalendarPickerForm.cs rename to TelegramBotBase.Test/Tests/Controls/CalendarPickerForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/CheckedButtonListForm.cs b/TelegramBotBase.Test/Tests/Controls/CheckedButtonListForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/CheckedButtonListForm.cs rename to TelegramBotBase.Test/Tests/Controls/CheckedButtonListForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/MonthPickerForm.cs b/TelegramBotBase.Test/Tests/Controls/MonthPickerForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/MonthPickerForm.cs rename to TelegramBotBase.Test/Tests/Controls/MonthPickerForm.cs diff --git a/TelegramBotBaseTest/Tests/Controls/MultiToggleButtons.cs b/TelegramBotBase.Test/Tests/Controls/MultiToggleButtons.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/MultiToggleButtons.cs rename to TelegramBotBase.Test/Tests/Controls/MultiToggleButtons.cs diff --git a/TelegramBotBaseTest/Tests/Controls/MultiViewForm.cs b/TelegramBotBase.Test/Tests/Controls/MultiViewForm.cs similarity index 82% rename from TelegramBotBaseTest/Tests/Controls/MultiViewForm.cs rename to TelegramBotBase.Test/Tests/Controls/MultiViewForm.cs index 543b3c5..fccdfcb 100644 --- a/TelegramBotBaseTest/Tests/Controls/MultiViewForm.cs +++ b/TelegramBotBase.Test/Tests/Controls/MultiViewForm.cs @@ -48,26 +48,6 @@ namespace TelegramBotBaseTest.Tests.Controls } } - public override async Task Load(MessageResult message) - { - - - - } - - public override async Task Action(MessageResult message) - { - - - } - - - public override async Task Render(MessageResult message) - { - - } - - } } diff --git a/TelegramBotBaseTest/Tests/Controls/Subclass/MultiViewTest.cs b/TelegramBotBase.Test/Tests/Controls/Subclass/MultiViewTest.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/Subclass/MultiViewTest.cs rename to TelegramBotBase.Test/Tests/Controls/Subclass/MultiViewTest.cs diff --git a/TelegramBotBaseTest/Tests/Controls/ToggleButtons.cs b/TelegramBotBase.Test/Tests/Controls/ToggleButtons.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/ToggleButtons.cs rename to TelegramBotBase.Test/Tests/Controls/ToggleButtons.cs diff --git a/TelegramBotBaseTest/Tests/Controls/TreeViewForms.cs b/TelegramBotBase.Test/Tests/Controls/TreeViewForms.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Controls/TreeViewForms.cs rename to TelegramBotBase.Test/Tests/Controls/TreeViewForms.cs diff --git a/TelegramBotBaseTest/Tests/DataForm.cs b/TelegramBotBase.Test/Tests/DataForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/DataForm.cs rename to TelegramBotBase.Test/Tests/DataForm.cs diff --git a/TelegramBotBaseTest/Tests/Datasources/CustomDataSource.cs b/TelegramBotBase.Test/Tests/Datasources/CustomDataSource.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Datasources/CustomDataSource.cs rename to TelegramBotBase.Test/Tests/Datasources/CustomDataSource.cs diff --git a/TelegramBotBaseTest/Tests/Datasources/List.cs b/TelegramBotBase.Test/Tests/Datasources/List.cs similarity index 87% rename from TelegramBotBaseTest/Tests/Datasources/List.cs rename to TelegramBotBase.Test/Tests/Datasources/List.cs index b2ec372..c352384 100644 --- a/TelegramBotBaseTest/Tests/Datasources/List.cs +++ b/TelegramBotBase.Test/Tests/Datasources/List.cs @@ -49,17 +49,6 @@ namespace TelegramBotBaseTest.Tests.Datasources } } - public override async Task Load(MessageResult message) - { - - } - - - public override async Task Render(MessageResult message) - { - - } - } } diff --git a/TelegramBotBaseTest/Tests/Groups/GroupChange.cs b/TelegramBotBase.Test/Tests/Groups/GroupChange.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Groups/GroupChange.cs rename to TelegramBotBase.Test/Tests/Groups/GroupChange.cs diff --git a/TelegramBotBaseTest/Tests/Groups/LinkReplaceTest.cs b/TelegramBotBase.Test/Tests/Groups/LinkReplaceTest.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Groups/LinkReplaceTest.cs rename to TelegramBotBase.Test/Tests/Groups/LinkReplaceTest.cs diff --git a/TelegramBotBaseTest/Tests/Groups/WelcomeUser.cs b/TelegramBotBase.Test/Tests/Groups/WelcomeUser.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Groups/WelcomeUser.cs rename to TelegramBotBase.Test/Tests/Groups/WelcomeUser.cs diff --git a/TelegramBotBaseTest/Tests/Menu.cs b/TelegramBotBase.Test/Tests/Menu.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Menu.cs rename to TelegramBotBase.Test/Tests/Menu.cs diff --git a/TelegramBotBaseTest/Tests/Navigation/CustomController.cs b/TelegramBotBase.Test/Tests/Navigation/CustomController.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Navigation/CustomController.cs rename to TelegramBotBase.Test/Tests/Navigation/CustomController.cs diff --git a/TelegramBotBaseTest/Tests/Navigation/Form1.cs b/TelegramBotBase.Test/Tests/Navigation/Form1.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Navigation/Form1.cs rename to TelegramBotBase.Test/Tests/Navigation/Form1.cs diff --git a/TelegramBotBaseTest/Tests/Navigation/Start.cs b/TelegramBotBase.Test/Tests/Navigation/Start.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Navigation/Start.cs rename to TelegramBotBase.Test/Tests/Navigation/Start.cs diff --git a/TelegramBotBaseTest/Tests/Notifications/Start.cs b/TelegramBotBase.Test/Tests/Notifications/Start.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Notifications/Start.cs rename to TelegramBotBase.Test/Tests/Notifications/Start.cs diff --git a/TelegramBotBaseTest/Tests/ProgressTest.cs b/TelegramBotBase.Test/Tests/ProgressTest.cs similarity index 100% rename from TelegramBotBaseTest/Tests/ProgressTest.cs rename to TelegramBotBase.Test/Tests/ProgressTest.cs diff --git a/TelegramBotBaseTest/Tests/Register/PerForm.cs b/TelegramBotBase.Test/Tests/Register/PerForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/PerForm.cs rename to TelegramBotBase.Test/Tests/Register/PerForm.cs diff --git a/TelegramBotBaseTest/Tests/Register/PerStep.cs b/TelegramBotBase.Test/Tests/Register/PerStep.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/PerStep.cs rename to TelegramBotBase.Test/Tests/Register/PerStep.cs diff --git a/TelegramBotBaseTest/Tests/Register/Start.cs b/TelegramBotBase.Test/Tests/Register/Start.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/Start.cs rename to TelegramBotBase.Test/Tests/Register/Start.cs diff --git a/TelegramBotBaseTest/Tests/Register/Steps/Data.cs b/TelegramBotBase.Test/Tests/Register/Steps/Data.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/Steps/Data.cs rename to TelegramBotBase.Test/Tests/Register/Steps/Data.cs diff --git a/TelegramBotBaseTest/Tests/Register/Steps/Step1.cs b/TelegramBotBase.Test/Tests/Register/Steps/Step1.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/Steps/Step1.cs rename to TelegramBotBase.Test/Tests/Register/Steps/Step1.cs diff --git a/TelegramBotBaseTest/Tests/Register/Steps/Step2.cs b/TelegramBotBase.Test/Tests/Register/Steps/Step2.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/Steps/Step2.cs rename to TelegramBotBase.Test/Tests/Register/Steps/Step2.cs diff --git a/TelegramBotBaseTest/Tests/Register/Steps/Step3.cs b/TelegramBotBase.Test/Tests/Register/Steps/Step3.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Register/Steps/Step3.cs rename to TelegramBotBase.Test/Tests/Register/Steps/Step3.cs diff --git a/TelegramBotBaseTest/Tests/SimpleForm.cs b/TelegramBotBase.Test/Tests/SimpleForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/SimpleForm.cs rename to TelegramBotBase.Test/Tests/SimpleForm.cs diff --git a/TelegramBotBaseTest/Tests/Start.cs b/TelegramBotBase.Test/Tests/Start.cs similarity index 100% rename from TelegramBotBaseTest/Tests/Start.cs rename to TelegramBotBase.Test/Tests/Start.cs diff --git a/TelegramBotBaseTest/Tests/TestForm.cs b/TelegramBotBase.Test/Tests/TestForm.cs similarity index 100% rename from TelegramBotBaseTest/Tests/TestForm.cs rename to TelegramBotBase.Test/Tests/TestForm.cs diff --git a/TelegramBotBaseTest/Tests/TestForm2.cs b/TelegramBotBase.Test/Tests/TestForm2.cs similarity index 100% rename from TelegramBotBaseTest/Tests/TestForm2.cs rename to TelegramBotBase.Test/Tests/TestForm2.cs diff --git a/TelegramBotBaseTest/packages.config b/TelegramBotBase.Test/packages.config similarity index 100% rename from TelegramBotBaseTest/packages.config rename to TelegramBotBase.Test/packages.config From 19856ab044cb87cc8881338e6c4c2a5cfe8fc310 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Thu, 6 Jan 2022 15:56:16 +0100 Subject: [PATCH 55/57] Update Solution File --- TelegramBotBase.Test/Program.cs | 5 ++--- TelegramBotFramework.sln | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/TelegramBotBase.Test/Program.cs b/TelegramBotBase.Test/Program.cs index 62e2f21..55ac0aa 100644 --- a/TelegramBotBase.Test/Program.cs +++ b/TelegramBotBase.Test/Program.cs @@ -16,9 +16,8 @@ namespace TelegramBotBaseTest { static void Main(string[] args) { - //Test: 822283338:AAGmeSX5j65pcO3UKBQ7Ro_nuSaW9LCxwl0 - //Live: 480896099:AAE6M9WqvwFdBkk-tGKki4rgdOvoVxcHTBQ - String APIKey = "822283338:AAGmeSX5j65pcO3UKBQ7Ro_nuSaW9LCxwl0";// "822283338:AAGmeSX5j65pcO3UKBQ7Ro_nuSaW9LCxwl0"; + + String APIKey = ""; var bb = BotBaseBuilder .Create() diff --git a/TelegramBotFramework.sln b/TelegramBotFramework.sln index 234b44b..326160e 100644 --- a/TelegramBotFramework.sln +++ b/TelegramBotFramework.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase", "TelegramBotBase\TelegramBotBase.csproj", "{0BD16FB9-7ED4-4CCB-83EB-5CEE538E1B6C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBaseTest", "TelegramBotBaseTest\TelegramBotBaseTest.csproj", "{88EC0E02-583D-4B9D-956C-81D63C8CFCFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBaseTest", "TelegramBotBase.Test\TelegramBotBaseTest.csproj", "{88EC0E02-583D-4B9D-956C-81D63C8CFCFA}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3856B3FB-63E3-444A-9FF0-34171BE7AC5D}" ProjectSection(SolutionItems) = preProject From 8303b0c87f558d78cb5e6a2b55c2ee78928187c8 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Thu, 6 Jan 2022 16:54:50 +0100 Subject: [PATCH 56/57] Adding private constructor - Adding private constructor - some spacing for regions --- TelegramBotBase/Builder/BotBaseBuilder.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index dd194bf..517a8fb 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -29,6 +29,11 @@ namespace TelegramBotBase.Builder IMessageLoopFactory _messageloopfactory = null; + private BotBaseBuilder() + { + + } + public static IAPIKeySelectionStage Create() { return new BotBaseBuilder(); @@ -128,6 +133,7 @@ namespace TelegramBotBase.Builder #endregion + #region "Step 3 (Start Form/Factory)" public INetworkingSelectionStage WithStartForm(Type startFormClass) @@ -151,6 +157,7 @@ namespace TelegramBotBase.Builder #endregion + #region "Step 4 (Network Settings)" public IBotCommandsStage WithProxy(string proxyAddress) @@ -195,6 +202,7 @@ namespace TelegramBotBase.Builder #endregion + #region "Step 5 (Bot Commands)" public ISessionSerializationStage NoCommands() @@ -226,6 +234,7 @@ namespace TelegramBotBase.Builder #endregion + #region "Step 6 (Serialization)" public ILanguageSelectionStage NoSerialization() @@ -260,6 +269,7 @@ namespace TelegramBotBase.Builder #endregion + #region "Step 7 (Language)" public IBuildingStage DefaultLanguage() @@ -287,6 +297,7 @@ namespace TelegramBotBase.Builder #endregion + public BotBase Build() { var bb = new BotBase(); From 3340ef7b76c90c8971deec92c68f668aa5a79782 Mon Sep 17 00:00:00 2001 From: Florian Dahn Date: Mon, 10 Jan 2022 13:59:26 +0100 Subject: [PATCH 57/57] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbe65ea..0d4e6e7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # .Net Telegram Bot Framework - Context based addon -[![NuGet version (TelegramBotBase)](https://img.shields.io/nuget/vpre/TelegramBotBase.svg?style=flat-square)](https://www.nuget.org/packages/TelegramBotBase/) +[![NuGet version (TelegramBotBase)](https://img.shields.io/nuget/v/TelegramBotBase.svg?style=flat-square)](https://www.nuget.org/packages/TelegramBotBase/) [![telegram chat](https://img.shields.io/badge/Support_Chat-Telegram-blue.svg?style=flat-square)](https://www.t.me/tgbotbase)