From 77242a200fead54e3857d133eca093488740d6c6 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Sat, 15 Oct 2022 18:16:22 +0300 Subject: [PATCH] upstream: apply changes --- .../AsyncFormUpdates/AsyncFormUpdates.csproj | 77 +++---------------- Examples/AsyncFormUpdates/Program.cs | 12 +-- .../Properties/AssemblyInfo.cs | 35 --------- TelegramBotBase/Base/MessageResult.cs | 2 +- TelegramBotBase/BotBase.cs | 18 ++--- TelegramBotBase/Builder/BotBaseBuilder.cs | 2 - .../DataSources/ButtonFormDataSource.cs | 4 +- TelegramBotBase/Form/SplitterForm.cs | 4 +- TelegramBotBase/Localizations/English.cs | 6 +- .../{SessionBase.cs => SessionManager.cs} | 24 ++---- TelegramBotBase/Sessions/DeviceSession.cs | 4 +- TelegramBotBase/TelegramBotBase.csproj | 14 ++-- 12 files changed, 48 insertions(+), 154 deletions(-) delete mode 100644 Examples/AsyncFormUpdates/Properties/AssemblyInfo.cs rename TelegramBotBase/{SessionBase.cs => SessionManager.cs} (95%) diff --git a/Examples/AsyncFormUpdates/AsyncFormUpdates.csproj b/Examples/AsyncFormUpdates/AsyncFormUpdates.csproj index 6c2fe0b..95f3bea 100644 --- a/Examples/AsyncFormUpdates/AsyncFormUpdates.csproj +++ b/Examples/AsyncFormUpdates/AsyncFormUpdates.csproj @@ -1,74 +1,19 @@ - - - + + - Debug - AnyCPU - {673A56F5-6110-4AED-A68D-562FD6ED3EA6} Exe - AsyncFormUpdates - AsyncFormUpdates - v4.8 - 512 - true - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + net6.0 + enable + disable + - - - - - - - - - - - ..\..\packages\Telegram.Bot.17.0.0\lib\netstandard2.0\Telegram.Bot.dll - + + + - - - - - + - - - - - - {0bd16fb9-7ed4-4ccb-83eb-5cee538e1b6c} - TelegramBotBase - - - - - - - - - - + diff --git a/Examples/AsyncFormUpdates/Program.cs b/Examples/AsyncFormUpdates/Program.cs index facc257..63ecc9d 100644 --- a/Examples/AsyncFormUpdates/Program.cs +++ b/Examples/AsyncFormUpdates/Program.cs @@ -1,8 +1,8 @@ -using System; -using System.Timers; +using System.Timers; using AsyncFormUpdates.forms; using TelegramBotBase; using TelegramBotBase.Builder; +using Timer = System.Timers.Timer; namespace AsyncFormUpdates { @@ -10,7 +10,7 @@ namespace AsyncFormUpdates { private static BotBase __bot; - private static void Main(string[] args) + private static async Task Main(string[] args) { var apiKey = "APIKey"; @@ -18,7 +18,7 @@ namespace AsyncFormUpdates .QuickStart(apiKey) .Build(); - __bot.Start(); + await __bot.Start(); var timer = new Timer(5000); @@ -28,7 +28,7 @@ namespace AsyncFormUpdates Console.ReadLine(); timer.Stop(); - __bot.Stop(); + await __bot.Stop(); } private static async void Timer_Elapsed(object sender, ElapsedEventArgs e) @@ -46,4 +46,4 @@ namespace AsyncFormUpdates } } } -} \ No newline at end of file +} diff --git a/Examples/AsyncFormUpdates/Properties/AssemblyInfo.cs b/Examples/AsyncFormUpdates/Properties/AssemblyInfo.cs deleted file mode 100644 index f89e22b..0000000 --- a/Examples/AsyncFormUpdates/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// Allgemeine Informationen über eine Assembly werden über die folgenden -// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -// die einer Assembly zugeordnet sind. -[assembly: AssemblyTitle("AsyncFormUpdates")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("AsyncFormUpdates")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly -// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von -// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. -[assembly: ComVisible(false)] - -// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird -[assembly: Guid("673a56f5-6110-4aed-a68d-562fd6ed3ea6")] - -// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -// -// Hauptversion -// Nebenversion -// Buildnummer -// Revision -// -// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -// indem Sie "*" wie unten gezeigt eingeben: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/TelegramBotBase/Base/MessageResult.cs b/TelegramBotBase/Base/MessageResult.cs index c6579ef..11e33d7 100644 --- a/TelegramBotBase/Base/MessageResult.cs +++ b/TelegramBotBase/Base/MessageResult.cs @@ -123,7 +123,7 @@ public class MessageResult : ResultBase } /// - /// Confirm incomming action (i.e. Button click) + /// Confirm incoming action (i.e. Button click) /// /// /// diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index 8e6fcad..14fe7ba 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -18,9 +18,9 @@ namespace TelegramBotBase; /// Bot base class for full Device/Context and Messagehandling /// /// -public class BotBase +public sealed class BotBase { - public BotBase() + internal BotBase() { SystemSettings = new Dictionary(); @@ -32,10 +32,7 @@ public class BotBase BotCommandScopes = new Dictionary>(); - Sessions = new SessionBase - { - BotBase = this - }; + Sessions = new SessionManager(this); } public MessageClient Client { get; set; } @@ -48,7 +45,7 @@ public class BotBase /// /// List of all running/active sessions /// - public SessionBase Sessions { get; set; } + public SessionManager Sessions { get; set; } /// /// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start @@ -94,9 +91,10 @@ public class BotBase await Sessions.LoadSessionStates(StateMachine); } - //Enable auto session saving + // Enable auto session saving if (GetSetting(ESettings.SaveSessionsOnConsoleExit, false)) { + // should be waited until finish Console.SetHandler(() => { Sessions.SaveSessionStates().GetAwaiter().GetResult(); }); } @@ -329,8 +327,6 @@ public class BotBase private static readonly object EvMessage = new(); - private static object __evSystemCall = new(); - public delegate Task BotCommandEventHandler(object sender, BotCommandEventArgs e); private static readonly object EvException = new(); @@ -356,7 +352,7 @@ public class BotBase } /// - /// Will be called on incomming message + /// Will be called on incoming message /// public event EventHandler Message { diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index c20368e..f73e27d 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -48,8 +48,6 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, Client = _client }; - bot.Sessions.Client = bot.Client; - bot.BotCommandScopes = BotCommandScopes; bot.StateMachine = _statemachine; diff --git a/TelegramBotBase/DataSources/ButtonFormDataSource.cs b/TelegramBotBase/DataSources/ButtonFormDataSource.cs index c14b7e3..e91668c 100644 --- a/TelegramBotBase/DataSources/ButtonFormDataSource.cs +++ b/TelegramBotBase/DataSources/ButtonFormDataSource.cs @@ -39,7 +39,7 @@ public class ButtonFormDataSource : IDataSource /// - /// Returns the amount of rows exisiting. + /// Returns the amount of rows existing. /// /// public virtual int Count => ButtonForm.Count; @@ -134,4 +134,4 @@ public class ButtonFormDataSource : IDataSource { return ds.ButtonForm; } -} \ No newline at end of file +} diff --git a/TelegramBotBase/Form/SplitterForm.cs b/TelegramBotBase/Form/SplitterForm.cs index 4d8d668..99c0d85 100644 --- a/TelegramBotBase/Form/SplitterForm.cs +++ b/TelegramBotBase/Form/SplitterForm.cs @@ -5,7 +5,7 @@ using TelegramBotBase.Base; namespace TelegramBotBase.Form; /// -/// This is used to split incomming requests depending on the chat type. +/// This is used to split incoming requests depending on the chat type. /// public class SplitterForm : FormBase { @@ -90,4 +90,4 @@ public class SplitterForm : FormBase { return base.SentData(message); } -} \ No newline at end of file +} diff --git a/TelegramBotBase/Localizations/English.cs b/TelegramBotBase/Localizations/English.cs index fb5b948..5a7c362 100644 --- a/TelegramBotBase/Localizations/English.cs +++ b/TelegramBotBase/Localizations/English.cs @@ -25,11 +25,11 @@ public class English : Localization Values["ToggleButton_OnIcon"] = "⚫"; Values["ToggleButton_OffIcon"] = "⚪"; Values["ToggleButton_Title"] = "Toggle"; - Values["ToggleButton_Changed"] = "Choosen"; + Values["ToggleButton_Changed"] = "Chosen"; Values["MultiToggleButton_SelectedIcon"] = "✅"; Values["MultiToggleButton_Title"] = "Multi-Toggle"; - Values["MultiToggleButton_Changed"] = "Choosen"; + Values["MultiToggleButton_Changed"] = "Chosen"; Values["PromptDialog_Back"] = "Back"; Values["ToggleButton_Changed"] = "Setting changed"; } -} \ No newline at end of file +} diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionManager.cs similarity index 95% rename from TelegramBotBase/SessionBase.cs rename to TelegramBotBase/SessionManager.cs index bd4f2bb..7e9d257 100644 --- a/TelegramBotBase/SessionBase.cs +++ b/TelegramBotBase/SessionManager.cs @@ -16,17 +16,18 @@ namespace TelegramBotBase; /// /// Base class for managing all active sessions /// -public class SessionBase +public class SessionManager { - public SessionBase() + public SessionManager(BotBase botBase) { + BotBase = botBase; SessionList = new Dictionary(); } /// /// The Basic message client. /// - public MessageClient Client { get; set; } + public MessageClient Client => BotBase.Client; /// /// A list of all active sessions. @@ -37,18 +38,7 @@ public class SessionBase /// /// Reference to the Main BotBase instance for later use. /// - public BotBase BotBase { get; set; } - - /// - /// Get device session from Device/ChatId - /// - /// - /// - public DeviceSession this[long key] - { - get => SessionList[key]; - set => SessionList[key] = value; - } + public BotBase BotBase { get; } /// /// Get device session from Device/ChatId @@ -80,7 +70,7 @@ public class SessionBase await start.OnOpened(EventArgs.Empty); - this[deviceId] = ds; + SessionList[deviceId] = ds; return ds; } @@ -90,7 +80,7 @@ public class SessionBase /// public void EndSession(long deviceId) { - var d = this[deviceId]; + var d = SessionList[deviceId]; if (d != null) { SessionList.Remove(deviceId); diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index 2ece87c..5da18ab 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -125,7 +125,7 @@ public class DeviceSession : IDeviceSession /// - /// Confirm incomming action (i.e. Button click) + /// Confirm incoming action (i.e. Button click) /// /// /// @@ -992,4 +992,4 @@ public class DeviceSession : IDeviceSession } #endregion -} \ No newline at end of file +} diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 3879e73..12c0a79 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -22,8 +22,8 @@ - - + + @@ -50,15 +50,15 @@ - - - + + + - - + +