Merge pull request #9 from MajMcCloud/development

Development
This commit is contained in:
Florian Dahn 2021-07-14 23:11:32 +03:00 committed by GitHub
commit d52fd41467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 32 deletions

View File

@ -54,5 +54,10 @@ namespace TelegramBotBase.Args
return false; return false;
} }
public object GetObject(String key)
{
return Values[key];
}
} }
} }

View File

@ -32,6 +32,10 @@ namespace TelegramBotBase.Args
{ {
Values[key] = value; Values[key] = value;
} }
public void SetObject(String key, object value)
{
Values[key] = value;
}
} }
} }

View File

@ -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);

View File

@ -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;

View File

@ -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,33 +240,7 @@ 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;
}
}
/// <summary> /// <summary>

View 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;
}
}
}
}