diff --git a/.gitignore b/.gitignore index 1c9a181..e49c333 100644 --- a/.gitignore +++ b/.gitignore @@ -240,3 +240,15 @@ ModelManifest.xml # FAKE - F# Make .fake/ +MigrationBackup +TelegramBotBase/nuget.exe +Material +TelegramBotBase/cp.ps1 +TelegramBotBase/TelegramBotBase.nuspec +Program.cs +TelegramBotBase/Archive +/TelegramBotBase/TelegramBotBase.1.5.0.zip +/TelegramBotBase/TelegramBotBase.1.5.1.zip +/TelegramBotBase/TelegramBotBase.1.5.2.zip +/TelegramBotBase/cpush.ps1 +/TelegramBotBase/cpack.ps1 diff --git a/TelegramBotBase/Base/FormBase.cs b/TelegramBotBase/Base/FormBase.cs index c8d82f8..0a89174 100644 --- a/TelegramBotBase/Base/FormBase.cs +++ b/TelegramBotBase/Base/FormBase.cs @@ -291,7 +291,7 @@ namespace TelegramBotBase.Form await newForm.OnInit(new InitEventArgs(args)); - await this.CloseControls(); + this.CloseControls().Wait(); await this.OnClosed(new EventArgs()); diff --git a/TelegramBotBase/Controls/ButtonGrid.cs b/TelegramBotBase/Controls/ButtonGrid.cs index 76cdfdc..f569daf 100644 --- a/TelegramBotBase/Controls/ButtonGrid.cs +++ b/TelegramBotBase/Controls/ButtonGrid.cs @@ -8,6 +8,7 @@ using Telegram.Bot.Types; using Telegram.Bot.Types.ReplyMarkups; using TelegramBotBase.Base; using TelegramBotBase.Enums; +using TelegramBotBase.Exceptions; using TelegramBotBase.Form; namespace TelegramBotBase.Controls @@ -27,6 +28,15 @@ namespace TelegramBotBase.Controls public int? MessageId { get; set; } + + /// + /// Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. + /// Source: https://core.telegram.org/bots/api#replykeyboardmarkup + /// + public bool ResizeKeyboard { get; set; } = false; + + public bool OneTimeKeyboard { get; set; } = false; + /// /// Defines which type of Button Keyboard should be rendered. /// @@ -39,7 +49,7 @@ namespace TelegramBotBase.Controls } set { - if(m_eKeyboardType != value) + if (m_eKeyboardType != value) { this.RenderNecessary = true; @@ -47,7 +57,7 @@ namespace TelegramBotBase.Controls m_eKeyboardType = value; } - + } } @@ -133,6 +143,36 @@ namespace TelegramBotBase.Controls if (!this.RenderNecessary) return; + + switch (m_eKeyboardType) + { + case eKeyboardType.InlineKeyBoard: + + if (ButtonsForm.Rows > 13) + { + throw new MaximumRowsReachedException() { Value = ButtonsForm.Rows, Maximum = 13 }; + } + + if (ButtonsForm.Rows > 8) + { + throw new MaximumColsException() { Value = ButtonsForm.Rows, Maximum = 8 }; + } + + break; + case eKeyboardType.ReplyKeyboard: + + if (ButtonsForm.Rows > 25) + { + throw new MaximumRowsReachedException() { Value = ButtonsForm.Rows, Maximum = 25 }; + } + + if (ButtonsForm.Rows > 12) + { + throw new MaximumColsException() { Value = ButtonsForm.Rows, Maximum = 12 }; + } + break; + } + Message m = null; if (this.MessageId != null) { @@ -142,12 +182,15 @@ namespace TelegramBotBase.Controls case eKeyboardType.ReplyKeyboard: if (this.ButtonsForm.Count == 0) { - await this.Device.Send("", new ReplyKeyboardRemove()); + await this.Device.HideReplyKeyboard(); this.MessageId = null; } else { - m = await this.Device.Send(this.Title, (ReplyKeyboardMarkup)this.ButtonsForm, disableNotification: true); + var rkm = (ReplyKeyboardMarkup)this.ButtonsForm; + rkm.ResizeKeyboard = this.ResizeKeyboard; + rkm.OneTimeKeyboard = this.OneTimeKeyboard; + m = await this.Device.Send(this.Title, rkm, disableNotification: true); } break; @@ -164,7 +207,10 @@ namespace TelegramBotBase.Controls switch (this.KeyboardType) { case eKeyboardType.ReplyKeyboard: - m = await this.Device.Send(this.Title, (ReplyKeyboardMarkup)this.ButtonsForm, disableNotification: true); + var rkm = (ReplyKeyboardMarkup)this.ButtonsForm; + rkm.ResizeKeyboard = this.ResizeKeyboard; + rkm.OneTimeKeyboard = this.OneTimeKeyboard; + m = await this.Device.Send(this.Title, rkm, disableNotification: true); break; case eKeyboardType.InlineKeyBoard: @@ -194,7 +240,7 @@ namespace TelegramBotBase.Controls if (this.KeyboardType == eKeyboardType.ReplyKeyboard) { - await this.Device.Send("", new ReplyKeyboardRemove()); + await this.Device.HideReplyKeyboard(autoDeleteResponse: false); } } diff --git a/TelegramBotBase/Exceptions/MaximumColsException.cs b/TelegramBotBase/Exceptions/MaximumColsException.cs new file mode 100644 index 0000000..de7cffc --- /dev/null +++ b/TelegramBotBase/Exceptions/MaximumColsException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Exceptions +{ + public class MaximumColsException : Exception + { + public int Value { get; set; } + + public int Maximum { get; set; } + + + public override string Message + { + get + { + return $"You have exceeded the maximum of columns by {Value.ToString()} / {Maximum.ToString()}"; + } + } + } +} diff --git a/TelegramBotBase/Exceptions/MaximumRowsException.cs b/TelegramBotBase/Exceptions/MaximumRowsException.cs new file mode 100644 index 0000000..1d00f18 --- /dev/null +++ b/TelegramBotBase/Exceptions/MaximumRowsException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Exceptions +{ + public class MaximumRowsReachedException : Exception + { + public int Value { get; set; } + + public int Maximum { get; set; } + + + public override string Message + { + get + { + return $"You have exceeded the maximum of rows by {Value.ToString()} / {Maximum.ToString()}"; + } + } + } +} diff --git a/TelegramBotBase/Form/ArrayPromptDialog.cs b/TelegramBotBase/Form/ArrayPromptDialog.cs index 0891a88..22fbf3b 100644 --- a/TelegramBotBase/Form/ArrayPromptDialog.cs +++ b/TelegramBotBase/Form/ArrayPromptDialog.cs @@ -56,7 +56,7 @@ namespace TelegramBotBase.Form var buttons = this.Buttons.Aggregate((a, b) => a.Union(b).ToArray()).ToList(); - if(call==null) + if (call == null) { return; } @@ -83,7 +83,7 @@ namespace TelegramBotBase.Form { ButtonForm btn = new ButtonForm(); - foreach(var bl in this.Buttons) + foreach (var bl in this.Buttons) { btn.AddButtonRow(bl.Select(a => new ButtonBase(a.Text, CallbackData.Create("action", a.Value))).ToList()); } diff --git a/TelegramBotBase/Form/ButtonForm.cs b/TelegramBotBase/Form/ButtonForm.cs index 6fe043d..8f99423 100644 --- a/TelegramBotBase/Form/ButtonForm.cs +++ b/TelegramBotBase/Form/ButtonForm.cs @@ -20,6 +20,28 @@ namespace TelegramBotBase.Form public ControlBase DependencyControl { get; set; } + /// + /// Contains the number of rows. + /// + public int Rows + { + get + { + return Buttons.Count; + } + } + + /// + /// Contains the highest number of columns in an row. + /// + public int Cols + { + get + { + return Buttons.Select(a => a.Count).OrderByDescending(a => a).FirstOrDefault(); + } + } + public ButtonForm() { diff --git a/TelegramBotBase/Properties/AssemblyInfo.cs b/TelegramBotBase/Properties/AssemblyInfo.cs index 6c8be64..07b0325 100644 --- a/TelegramBotBase/Properties/AssemblyInfo.cs +++ b/TelegramBotBase/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index af603b0..67e953b 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -492,6 +492,26 @@ namespace TelegramBotBase.Sessions return await this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, requestMessage, replyMarkup: rcl); } + public async Task HideReplyKeyboard(String closedMsg = "Closed", bool autoDeleteResponse = true) + { + try + { + var m = await this.Send(closedMsg, new ReplyKeyboardRemove()); + + if (autoDeleteResponse && m != null) + { + await this.DeleteMessage(m); + } + + return m; + } + catch + { + + } + return null; + } + /// /// Deletes a message /// diff --git a/TelegramBotBase/TelegramBotBase.2.0.0.zip b/TelegramBotBase/TelegramBotBase.2.0.0.zip new file mode 100644 index 0000000..63845d5 Binary files /dev/null and b/TelegramBotBase/TelegramBotBase.2.0.0.zip differ diff --git a/TelegramBotBase/TelegramBotBase.2.1.0.zip b/TelegramBotBase/TelegramBotBase.2.1.0.zip new file mode 100644 index 0000000..65a20c6 Binary files /dev/null and b/TelegramBotBase/TelegramBotBase.2.1.0.zip differ diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index a611ef2..a91ea59 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -3,7 +3,7 @@ netstandard2.0;net461 false - false + true false https://github.com/MajMcCloud/TelegramBotFramework https://github.com/MajMcCloud/TelegramBotFramework @@ -63,12 +63,16 @@ + + + + - - + + diff --git a/TelegramBotBase/TelegramBotBase.nuspec b/TelegramBotBase/TelegramBotBase.nuspec index cd83738..22df758 100644 --- a/TelegramBotBase/TelegramBotBase.nuspec +++ b/TelegramBotBase/TelegramBotBase.nuspec @@ -1,24 +1,27 @@ - - + + - $id$ - $version$ - $title$ - $author$ - $author$ + TelegramBotBase + 2.1.0 + TelegramBotBase + TelegramBotBase + false MIT https://github.com/MajMcCloud/TelegramBotFramework - false - $description$ - This is a context based application framework for the C# TelegramBot library. - Copyright 2019 - Telegram Bot Framework C# Addon Context Modules + Package Description + - moving from .Net Framework 4.7.2 to .Net Standard 2.1 for the Library and .Net Core 3.0 for the test project! + - - - + + + + + + + + + + - \ No newline at end of file