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
This commit is contained in:
parent
92f12735c8
commit
c8936d0748
14
TelegramBotBase/Args/PromptDialogCompletedEventArgs.cs
Normal file
14
TelegramBotBase/Args/PromptDialogCompletedEventArgs.cs
Normal file
@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Attributes;
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
@ -14,10 +15,21 @@ namespace TelegramBotBase.Form
|
|||||||
[IgnoreState]
|
[IgnoreState]
|
||||||
public class PromptDialog : ModalDialog
|
public class PromptDialog : ModalDialog
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The message the users sees.
|
||||||
|
/// </summary>
|
||||||
public String Message { get; set; }
|
public String Message { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The returned text value by the user.
|
||||||
|
/// </summary>
|
||||||
public String Value { get; set; }
|
public String Value { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An additional optional value.
|
||||||
|
/// </summary>
|
||||||
|
public object Tag { get; set; }
|
||||||
|
|
||||||
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
||||||
|
|
||||||
private static object __evCompleted { get; } = new object();
|
private static object __evCompleted { get; } = new object();
|
||||||
@ -86,13 +98,13 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
message.Handled = true;
|
message.Handled = true;
|
||||||
|
|
||||||
OnCompleted(new EventArgs());
|
OnCompleted(new PromptDialogCompletedEventArgs() { Tag = this.Tag, Value = this.Value });
|
||||||
|
|
||||||
await this.CloseForm();
|
await this.CloseForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public event EventHandler<EventArgs> Completed
|
public event EventHandler<PromptDialogCompletedEventArgs> Completed
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
{
|
{
|
||||||
@ -104,9 +116,9 @@ namespace TelegramBotBase.Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCompleted(EventArgs e)
|
public void OnCompleted(PromptDialogCompletedEventArgs e)
|
||||||
{
|
{
|
||||||
(this.__Events[__evCompleted] as EventHandler<EventArgs>)?.Invoke(this, e);
|
(this.__Events[__evCompleted] as EventHandler<PromptDialogCompletedEventArgs>)?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user