Replacing BotCommands with BotCommandsScope

This commit is contained in:
FlorianDahn
2022-02-08 18:07:59 +01:00
parent 8fa952e68b
commit d7a5c149b1
3 changed files with 141 additions and 17 deletions
+23 -8
View File
@@ -23,7 +23,12 @@ namespace TelegramBotBase.Builder
MessageClient _client = null;
List<BotCommand> _botcommands = new List<BotCommand>();
/// <summary>
/// Contains different Botcommands for different areas.
/// </summary>
Dictionary<BotCommandScope, List<BotCommand>> _BotCommandScopes { get; set; } = new Dictionary<BotCommandScope, List<BotCommand>>();
//List<BotCommand> _botcommands = new List<BotCommand>();
IStateMachine _statemachine = null;
@@ -116,6 +121,15 @@ namespace TelegramBotBase.Builder
return this;
}
public IStartFormSelectionStage MinimalMessageLoop()
{
_messageloopfactory = new Factories.MessageLoops.MinimalMessageLoop();
return this;
}
public IStartFormSelectionStage CustomMessageLoop(IMessageLoopFactory messageLoopClass)
{
_messageloopfactory = messageLoopClass;
@@ -212,7 +226,7 @@ namespace TelegramBotBase.Builder
public ISessionSerializationStage OnlyStart()
{
_botcommands.Start("Starts the bot");
_BotCommandScopes.Start("Starts the bot");
return this;
@@ -220,15 +234,15 @@ namespace TelegramBotBase.Builder
public ISessionSerializationStage DefaultCommands()
{
_botcommands.Start("Starts the bot");
_botcommands.Help("Should show you some help");
_botcommands.Settings("Should show you some settings");
_BotCommandScopes.Start("Starts the bot");
_BotCommandScopes.Help("Should show you some help");
_BotCommandScopes.Settings("Should show you some settings");
return this;
}
public ISessionSerializationStage CustomCommands(Action<List<BotCommand>> action)
public ISessionSerializationStage CustomCommands(Action<Dictionary<BotCommandScope, List<BotCommand>>> action)
{
action?.Invoke(_botcommands);
action?.Invoke(_BotCommandScopes);
return this;
}
@@ -309,7 +323,8 @@ namespace TelegramBotBase.Builder
bb.Sessions.Client = bb.Client;
bb.BotCommands = _botcommands;
bb.BotCommandScopes = _BotCommandScopes;
//bb.BotCommands = _botcommands;
bb.StateMachine = _statemachine;
@@ -33,7 +33,9 @@ namespace TelegramBotBase.Builder.Interfaces
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
ISessionSerializationStage CustomCommands(Action<List<BotCommand>> action);
ISessionSerializationStage CustomCommands(Action<Dictionary<BotCommandScope, List<BotCommand>>> action);
}
}