- Updated system call management

- parameters are now easier available
- example project added parameter example
This commit is contained in:
FlorianDahn
2019-03-18 12:03:55 +07:00
parent e5ae3be86e
commit 3856271e30
6 changed files with 79 additions and 11 deletions
+40
View File
@@ -61,6 +61,46 @@ namespace TelegramBotBase.Base
}
}
/// <summary>
/// Is this a system call ? Starts with a slash and command
/// </summary>
public bool IsSystemCall
{
get
{
return (this.MessageText.StartsWith("/"));
}
}
/// <summary>
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 => 123,456,789)
/// </summary>
public List<String> SystemCallParameters
{
get
{
if (!IsSystemCall)
return new List<string>();
//Split by empty space and skip first entry (command itself), return as list
return this.MessageText.Split(' ').Skip(1).ToList();
}
}
/// <summary>
/// Returns just the System call command (i.e. /start 1 2 3 => /start)
/// </summary>
public String SystemCommand
{
get
{
if (!IsSystemCall)
return null;
return this.MessageText.Split(' ')[0];
}
}
public bool Handled { get; set; } = false;
public String RawData
+7 -2
View File
@@ -14,9 +14,13 @@ namespace TelegramBotBase.Base
{
public String Command { get; set; }
public List<String> Parameters { get; set; }
public long DeviceId { get; set; }
public DeviceSession Device {get;set;}
public DeviceSession Device { get; set; }
public bool Handled { get; set; } = false;
public SystemCallEventArgs()
@@ -25,9 +29,10 @@ namespace TelegramBotBase.Base
}
public SystemCallEventArgs(String Command, long DeviceId, DeviceSession Device)
public SystemCallEventArgs(String Command, List<String> Parameters, long DeviceId, DeviceSession Device)
{
this.Command = Command;
this.Parameters = Parameters;
this.DeviceId = DeviceId;
this.Device = Device;
}
+5 -6
View File
@@ -60,7 +60,7 @@ namespace TelegramBotBase
/// <summary>
/// How often could a form navigate to another (within one user action/call/message)
/// </summary>
private const int NavigationMaximum = 10;
private const int NavigationMaximum = 10;
/// <summary>
/// Simple start of your Bot with the APIKey
@@ -162,13 +162,13 @@ namespace TelegramBotBase
ds.LastAction = DateTime.Now;
ds.LastMessage = e.MessageId;
//Is this a systemcall ?
if (e.Message.Text != null && this.SystemCalls.Contains(e.Message.Text))
if (e.IsSystemCall && this.SystemCalls.Contains(e.SystemCommand))
{
var sce = new SystemCallEventArgs(e.Message.Text, ds.DeviceId, ds);
var sce = new SystemCallEventArgs(e.SystemCommand, e.SystemCallParameters, ds.DeviceId, ds);
OnSystemCall(sce);
//return;
return;
}
FormBase activeForm = null;
@@ -340,7 +340,6 @@ namespace TelegramBotBase
public void OnSystemCall(SystemCallEventArgs e)
{
(this.__Events[__evSystemCall] as EventHandler<SystemCallEventArgs>)?.Invoke(this, e);
}
/// <summary>
+2 -2
View File
@@ -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("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]