From c8936d07487b853cef9d2c475bf82d3e3b2c8491 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Mon, 29 Mar 2021 23:51:39 +0200 Subject: [PATCH] Adding more details to PromptDialog - replacing the default EventArgs within the Completed event with a more detailed one - adding new PromptDialogCompletedEventArgs class for easier details access --- .../Args/PromptDialogCompletedEventArgs.cs | 14 +++++++++++++ TelegramBotBase/Form/PromptDialog.cs | 20 +++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 TelegramBotBase/Args/PromptDialogCompletedEventArgs.cs diff --git a/TelegramBotBase/Args/PromptDialogCompletedEventArgs.cs b/TelegramBotBase/Args/PromptDialogCompletedEventArgs.cs new file mode 100644 index 0000000..14f9cf8 --- /dev/null +++ b/TelegramBotBase/Args/PromptDialogCompletedEventArgs.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TelegramBotBase.Args +{ + public class PromptDialogCompletedEventArgs + { + public object Tag { get; set; } + + public String Value { get; set; } + + } +} diff --git a/TelegramBotBase/Form/PromptDialog.cs b/TelegramBotBase/Form/PromptDialog.cs index f2a26cd..ec9e61c 100644 --- a/TelegramBotBase/Form/PromptDialog.cs +++ b/TelegramBotBase/Form/PromptDialog.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Telegram.Bot.Types; using Telegram.Bot.Types.ReplyMarkups; +using TelegramBotBase.Args; using TelegramBotBase.Attributes; using TelegramBotBase.Base; @@ -14,10 +15,21 @@ namespace TelegramBotBase.Form [IgnoreState] public class PromptDialog : ModalDialog { + /// + /// The message the users sees. + /// public String Message { get; set; } + /// + /// The returned text value by the user. + /// public String Value { get; set; } + /// + /// An additional optional value. + /// + public object Tag { get; set; } + private EventHandlerList __Events { get; set; } = new EventHandlerList(); private static object __evCompleted { get; } = new object(); @@ -86,13 +98,13 @@ namespace TelegramBotBase.Form message.Handled = true; - OnCompleted(new EventArgs()); + OnCompleted(new PromptDialogCompletedEventArgs() { Tag = this.Tag, Value = this.Value }); await this.CloseForm(); } - public event EventHandler Completed + public event EventHandler Completed { add { @@ -104,9 +116,9 @@ namespace TelegramBotBase.Form } } - public void OnCompleted(EventArgs e) + public void OnCompleted(PromptDialogCompletedEventArgs e) { - (this.__Events[__evCompleted] as EventHandler)?.Invoke(this, e); + (this.__Events[__evCompleted] as EventHandler)?.Invoke(this, e); } }