Adding Int32, Int64 and StringAction
This commit is contained in:
parent
57f2139dba
commit
51d9faa807
@ -0,0 +1,13 @@
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public static class Int32Action_Extensions
|
||||
{
|
||||
|
||||
public static void AddInt32Action(this ExternalActionManager manager, string method, Func<int, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
manager.Add(new Int32Action(method, action));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public class Int32Action : IExternalAction
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
int? _lastValue { get; set; }
|
||||
|
||||
Func<int, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public Int32Action(string method, Func<int, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
int i;
|
||||
|
||||
if (int.TryParse(cd.Value, out i))
|
||||
_lastValue = i;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue.Value, ur, mr);
|
||||
|
||||
public static CallbackData GetCallback(string method, long l) => new CallbackData(method, l.ToString());
|
||||
|
||||
}
|
||||
|
||||
public class Int32Action<TForm> : IExternalAction
|
||||
where TForm : FormBase
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
int? _lastValue { get; set; }
|
||||
|
||||
Func<int, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public Int32Action(string method, Func<int, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
int i;
|
||||
|
||||
if (int.TryParse(cd.Value, out i))
|
||||
_lastValue = i;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue.Value, ur, mr);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public static class Int64Action_Extensions
|
||||
{
|
||||
|
||||
public static void AddInt64Action(this ExternalActionManager manager, string method, Func<long, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
manager.Add(new Int64Action(method, action));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public class Int64Action : IExternalAction
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
long? _lastValue { get; set; }
|
||||
|
||||
Func<long, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public Int64Action(string method, Func<long, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
long l;
|
||||
|
||||
if (long.TryParse(cd.Value, out l))
|
||||
_lastValue = l;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue.Value, ur, mr);
|
||||
|
||||
public static CallbackData GetCallback(string method, long l) => new CallbackData(method, l.ToString());
|
||||
|
||||
}
|
||||
|
||||
public class Int64Action<TForm> : IExternalAction
|
||||
where TForm : FormBase
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
long? _lastValue { get; set; }
|
||||
|
||||
Func<long, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public Int64Action(string method, Func<long, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
long g;
|
||||
|
||||
if (long.TryParse(cd.Value, out g))
|
||||
_lastValue = g;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue.Value, ur, mr);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public static class StringAction_Extensions
|
||||
{
|
||||
|
||||
public static void AddStringAction(this ExternalActionManager manager, string method, Func<String, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
manager.Add(new StringAction(method, action));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public class StringAction : IExternalAction
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
String? _lastValue { get; set; }
|
||||
|
||||
Func<string, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public StringAction(string method, Func<string, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
_lastValue = cd.Value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue, ur, mr);
|
||||
|
||||
public static CallbackData GetCallback(string method, long l) => new CallbackData(method, l.ToString());
|
||||
|
||||
}
|
||||
|
||||
public class StringAction<TForm> : IExternalAction
|
||||
where TForm : FormBase
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
String? _lastValue { get; set; }
|
||||
|
||||
Func<String, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public StringAction(string method, Func<String, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
_lastValue = cd.Value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue, ur, mr);
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user