BotCommands and refactoring
- refactoring SystemCalls to BotCommand (due new Telegram Bot update) - Adding UploadBotCommands method to BotBase - refactoring and simplifying BotBase constructors - adding getBotCommands and SetBotCommands to MessageClient
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
@@ -15,6 +16,7 @@ namespace TelegramBotBase.Base
|
||||
public class MessageClient
|
||||
{
|
||||
|
||||
|
||||
public String APIKey { get; set; }
|
||||
|
||||
public Telegram.Bot.TelegramBotClient TelegramClient { get; set; }
|
||||
@@ -40,7 +42,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
this.APIKey = APIKey;
|
||||
this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, proxy);
|
||||
|
||||
|
||||
|
||||
Prepare();
|
||||
}
|
||||
@@ -142,6 +144,27 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will return the current list of bot commands.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<BotCommand[]> GetBotCommands()
|
||||
{
|
||||
return await this.TelegramClient.GetMyCommandsAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will set your bot commands to the given list.
|
||||
/// </summary>
|
||||
/// <param name="botcommands"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SetBotCommands(List<BotCommand> botcommands)
|
||||
{
|
||||
await this.TelegramClient.SetMyCommandsAsync(botcommands);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#region "Events"
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this a system call ? Starts with a slash '/' and a command
|
||||
/// Is this a command ? Starts with a slash '/' and a command
|
||||
/// </summary>
|
||||
public bool IsSystemCall
|
||||
public bool IsBotCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -87,11 +87,11 @@ namespace TelegramBotBase.Base
|
||||
/// <summary>
|
||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 => 123,456,789)
|
||||
/// </summary>
|
||||
public List<String> SystemCallParameters
|
||||
public List<String> BotCommandParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsSystemCall)
|
||||
if (!IsBotCommand)
|
||||
return new List<string>();
|
||||
|
||||
//Split by empty space and skip first entry (command itself), return as list
|
||||
@@ -100,13 +100,13 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns just the System call command (i.e. /start 1 2 3 => /start)
|
||||
/// Returns just the command (i.e. /start 1 2 3 => /start)
|
||||
/// </summary>
|
||||
public String SystemCommand
|
||||
public String BotCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsSystemCall)
|
||||
if (!IsBotCommand)
|
||||
return null;
|
||||
|
||||
return this.MessageText.Split(' ')[0];
|
||||
|
||||
Reference in New Issue
Block a user