Доработаны паттерны команд
This commit is contained in:
@@ -67,15 +67,25 @@ internal sealed class CommandsRegistry
|
||||
/// </summary>
|
||||
private static Regex ToRegex(string template)
|
||||
{
|
||||
var escaped = Regex.Escape(template)
|
||||
.Replace("\\{", "{").Replace("\\}", "}");
|
||||
|
||||
var pattern = "^" + Regex.Replace(escaped, @"\{(\w+)(\?)?\}", m =>
|
||||
// Заменяем все {name} и {name?} на регулярные группы
|
||||
var pattern = "^" + Regex.Replace(template, @"\s*\{(\w+)(\?)?\}", m =>
|
||||
{
|
||||
var name = m.Groups[1].Value;
|
||||
var optional = m.Groups[2].Success;
|
||||
return optional ? $"(?<{name}>\\S+)?" : $"(?<{name}>\\S+)";
|
||||
}) + "$";
|
||||
|
||||
var argPattern = $"(?:\"(?<{name}>[^\"]+)\"|(?<{name}>\\S+))";
|
||||
|
||||
if (optional)
|
||||
{
|
||||
// необязательный параметр: пробел + значение целиком необязательны
|
||||
return $"(?:\\s+{argPattern})?";
|
||||
}
|
||||
else
|
||||
{
|
||||
// обязательный параметр: пробел обязателен
|
||||
return $"\\s+{argPattern}";
|
||||
}
|
||||
}) + "\\s*$"; // допускаем пробелы/переносы в конце
|
||||
|
||||
return new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
|
||||
var mapped = TelegramUpdateMapper.Map(MessengerType, update, _client);
|
||||
if (mapped is not null)
|
||||
await onUpdate(mapped);
|
||||
if (update.CallbackQuery is not null)
|
||||
{
|
||||
await _.AnswerCallbackQuery(update.CallbackQuery.Id);
|
||||
}
|
||||
},
|
||||
|
||||
errorHandler: async (_, ex, ct2) =>
|
||||
|
||||
@@ -54,8 +54,8 @@ public sealed class DetailsPage : StatefullPage<string>
|
||||
await ctx.Navigation.GoToAsync<FilesPage>(ctx, ct);
|
||||
}
|
||||
|
||||
internal static string Command => "/create_request {title}";
|
||||
internal static string CommandDescription => "создание заявки /create_request {title";
|
||||
internal static string Command => "/create_request {title?}";
|
||||
internal static string CommandDescription => "создание заявки /create_request {title}";
|
||||
internal static CommandHandler CommandHandler = async (ctx, args, ct) =>
|
||||
{
|
||||
string? title = "";
|
||||
|
||||
Reference in New Issue
Block a user