commit
d52fd41467
@ -54,5 +54,10 @@ namespace TelegramBotBase.Args
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object GetObject(String key)
|
||||||
|
{
|
||||||
|
return Values[key];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,10 @@ namespace TelegramBotBase.Args
|
|||||||
{
|
{
|
||||||
Values[key] = value;
|
Values[key] = value;
|
||||||
}
|
}
|
||||||
|
public void SetObject(String key, object value)
|
||||||
|
{
|
||||||
|
Values[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,7 +180,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task LoadControls(MessageResult message)
|
public virtual async Task LoadControls(MessageResult message)
|
||||||
{
|
{
|
||||||
//Looking for the control by id, if not listened, raise event for all
|
//Looking for the control by id, if not listened, raise event for all
|
||||||
if (message.RawData?.StartsWith("#c") ?? false)
|
if (message.RawData?.StartsWith("#c") ?? false)
|
||||||
@ -228,7 +228,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task ActionControls(MessageResult message)
|
public virtual async Task ActionControls(MessageResult message)
|
||||||
{
|
{
|
||||||
//Looking for the control by id, if not listened, raise event for all
|
//Looking for the control by id, if not listened, raise event for all
|
||||||
if (message.RawData.StartsWith("#c"))
|
if (message.RawData.StartsWith("#c"))
|
||||||
@ -278,7 +278,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task RenderControls(MessageResult message)
|
public virtual async Task RenderControls(MessageResult message)
|
||||||
{
|
{
|
||||||
foreach (var b in this.Controls)
|
foreach (var b in this.Controls)
|
||||||
{
|
{
|
||||||
@ -400,6 +400,10 @@ namespace TelegramBotBase.Form
|
|||||||
/// <param name="control"></param>
|
/// <param name="control"></param>
|
||||||
public void AddControl(ControlBase control)
|
public void AddControl(ControlBase control)
|
||||||
{
|
{
|
||||||
|
//Duplicate check
|
||||||
|
if (this.Controls.Contains(control))
|
||||||
|
throw new ArgumentException("Control has been already added.");
|
||||||
|
|
||||||
control.ID = this.Controls.Count + 1;
|
control.ID = this.Controls.Count + 1;
|
||||||
control.Device = this.Device;
|
control.Device = this.Device;
|
||||||
this.Controls.Add(control);
|
this.Controls.Add(control);
|
||||||
|
|||||||
@ -47,6 +47,11 @@ namespace TelegramBotBase.Controls.Hybrid
|
|||||||
|
|
||||||
public bool DeletePreviousMessage { get; set; } = true;
|
public bool DeletePreviousMessage { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the reply message from a user.
|
||||||
|
/// </summary>
|
||||||
|
public bool DeleteReplyMessage { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parsemode of the message.
|
/// Parsemode of the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -197,7 +202,7 @@ namespace TelegramBotBase.Controls.Hybrid
|
|||||||
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
await OnButtonClicked(new ButtonClickedEventArgs(button, index));
|
||||||
|
|
||||||
//Remove button click message
|
//Remove button click message
|
||||||
if (this.DeletePreviousMessage)
|
if (this.DeleteReplyMessage)
|
||||||
await Device.DeleteMessage(result.MessageId);
|
await Device.DeleteMessage(result.MessageId);
|
||||||
|
|
||||||
result.Handled = true;
|
result.Handled = true;
|
||||||
|
|||||||
@ -198,7 +198,7 @@ namespace TelegramBotBase
|
|||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
CustomConversionChecks(form, p, f);
|
Tools.Conversion.CustomConversionChecks(form, p, f);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@ -240,32 +240,6 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, System.Reflection.PropertyInfo f)
|
|
||||||
{
|
|
||||||
//Newtonsoft Int64/Int32 converter issue
|
|
||||||
if (f.PropertyType == typeof(Int32))
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
if(int.TryParse(p.Value.ToString(), out i))
|
|
||||||
{
|
|
||||||
f.SetValue(form, i);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Newtonsoft Double/Decimal converter issue
|
|
||||||
if(f.PropertyType == typeof(Decimal) | f.PropertyType == typeof(Nullable<Decimal>))
|
|
||||||
{
|
|
||||||
decimal d = 0;
|
|
||||||
if(decimal.TryParse(p.Value.ToString(), out d))
|
|
||||||
{
|
|
||||||
f.SetValue(form, d);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
38
TelegramBotBase/Tools/Conversion.cs
Normal file
38
TelegramBotBase/Tools/Conversion.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Tools
|
||||||
|
{
|
||||||
|
public static class Conversion
|
||||||
|
{
|
||||||
|
public static void CustomConversionChecks(FormBase form, KeyValuePair<string, object> p, System.Reflection.PropertyInfo f)
|
||||||
|
{
|
||||||
|
//Newtonsoft Int64/Int32 converter issue
|
||||||
|
if (f.PropertyType == typeof(Int32))
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
if (int.TryParse(p.Value.ToString(), out i))
|
||||||
|
{
|
||||||
|
f.SetValue(form, i);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Newtonsoft Double/Decimal converter issue
|
||||||
|
if (f.PropertyType == typeof(Decimal) | f.PropertyType == typeof(Nullable<Decimal>))
|
||||||
|
{
|
||||||
|
decimal d = 0;
|
||||||
|
if (decimal.TryParse(p.Value.ToString(), out d))
|
||||||
|
{
|
||||||
|
f.SetValue(form, d);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user