Adding additional bot command checks toa void invalid configurations
This commit is contained in:
parent
e3d1652a02
commit
834038ff44
@ -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;
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -21,4 +21,10 @@ public static class Telegram
|
||||
/// The maximum length of callback data. Will raise an exception of it exceeds it.
|
||||
/// </summary>
|
||||
public const int MaxCallBackDataBytes = 64;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The slash constant which indicates a bot command.
|
||||
/// </summary>
|
||||
public const string BotCommandIndicator = "/";
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user