using TelegramBotBase.Base; using TelegramBotBase.Form; namespace TelegramBotBase.Experiments.ActionManager.Navigation { public class EndsWithNavigation : IExternalAction { public Type FormType { get; } public string Value { get; set; } public Action SetProperty { get; set; } public EndsWithNavigation(Type formType, string value, Action setProperty) { FormType = formType; Value = value; SetProperty = setProperty; } public bool DoesFit(string raw_data) => raw_data.EndsWith(Value); public async Task DoAction(UpdateResult ur, MessageResult mr) { await mr.ConfirmAction(); var new_form = FormType.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase; if (mr.RawData != null) { SetProperty(new_form, mr.RawData); } await ur.Device.ActiveForm.NavigateTo(new_form); } } public class EndsWithNavigation : IExternalAction where TForm : FormBase { public string Value { get; set; } public Action SetProperty { get; set; } public EndsWithNavigation(string value, Action setProperty) { Value = value; SetProperty = setProperty; } public bool DoesFit(string raw_data) => raw_data.EndsWith(Value); public async Task DoAction(UpdateResult ur, MessageResult mr) { await mr.ConfirmAction(); var type = typeof(TForm); TForm new_form = type.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as TForm; if (mr.RawData != null) { SetProperty(new_form, mr.RawData); } await ur.Device.ActiveForm.NavigateTo(new_form); } } }