diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index c7d865a..5a50823 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -265,7 +265,7 @@ public sealed class BotBase { foreach (var scope in BotCommandScopes) { - if (scope.Value.Any(a => "/" + a.Command == command)) + if (scope.Value.Any(a => Constants.Telegram.BotCommandIndicator + a.Command == command)) { return true; } diff --git a/TelegramBotBase/Commands/Extensions.cs b/TelegramBotBase/Commands/Extensions.cs index 6a19ce1..e5b186d 100644 --- a/TelegramBotBase/Commands/Extensions.cs +++ b/TelegramBotBase/Commands/Extensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Telegram.Bot.Types; @@ -20,6 +21,16 @@ public static class Extensions scope = BotCommandScope.Default(); } + if (string.IsNullOrEmpty(command)) + { + throw new ArgumentNullException(nameof(command), $"{nameof(command)} parameter can not be null or empty"); + } + + if(command.StartsWith(Constants.Telegram.BotCommandIndicator)) + { + throw new ArgumentException($"{nameof(command)} parameter does not have to start with a slash, please remove.", $"{nameof(command)}"); + } + var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type); if (item.Value != null) diff --git a/TelegramBotBase/Constants/Telegram.cs b/TelegramBotBase/Constants/Telegram.cs index f91642d..10b0eec 100644 --- a/TelegramBotBase/Constants/Telegram.cs +++ b/TelegramBotBase/Constants/Telegram.cs @@ -21,4 +21,10 @@ public static class Telegram /// The maximum length of callback data. Will raise an exception of it exceeds it. /// public const int MaxCallBackDataBytes = 64; + + + /// + /// The slash constant which indicates a bot command. + /// + public const string BotCommandIndicator = "/"; } \ No newline at end of file