using System.Collections.Generic; using System.Linq; using Telegram.Bot.Types; namespace TelegramBotBase.Commands; public static class Extensions { /// /// Adding the command with a description. /// /// /// /// public static void Add(this Dictionary> cmds, string command, string description, BotCommandScope scope = null) { if (scope == null) { scope = BotCommandScope.Default(); } var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type); if (item.Value != null) { item.Value.Add(new BotCommand { Command = command, Description = description }); } else { cmds.Add(scope, new List { new() { Command = command, Description = description } }); } } /// /// Adding the command with a description. /// /// /// /// public static void Clear(this Dictionary> cmds, BotCommandScope scope = null) { if (scope == null) { scope = BotCommandScope.Default(); } var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type); if (item.Key != null) { cmds[item.Key] = null; } else { cmds[scope] = null; } } /// /// Adding the default /start command with a description. /// /// /// public static void Start(this Dictionary> cmds, string description) { Add(cmds, "start", description); } /// /// Adding the default /help command with a description. /// /// /// public static void Help(this Dictionary> cmds, string description) { Add(cmds, "help", description); } /// /// Adding the default /settings command with a description. /// /// /// public static void Settings(this Dictionary> cmds, string description) { Add(cmds, "settings", description); } /// /// Clears all default commands. /// /// public static void ClearDefaultCommands(this Dictionary> cmds) { Clear(cmds); } /// /// Clears all commands of a specific device. /// /// public static void ClearChatCommands(this Dictionary> cmds, long deviceId) { Clear(cmds, new BotCommandScopeChat { ChatId = deviceId }); } /// /// Adding a chat command with a description. /// /// /// /// public static void AddChatCommand(this Dictionary> cmds, long deviceId, string command, string description) { Add(cmds, command, description, new BotCommandScopeChat { ChatId = deviceId }); } /// /// Adding a group command with a description. /// /// /// /// public static void AddGroupCommand(this Dictionary> cmds, string command, string description) { Add(cmds, command, description, new BotCommandScopeAllGroupChats()); } /// /// Clears all group commands. /// /// public static void ClearGroupCommands(this Dictionary> cmds) { Clear(cmds, new BotCommandScopeAllGroupChats()); } /// /// Adding group admin command with a description. /// /// /// /// public static void AddGroupAdminCommand(this Dictionary> cmds, string command, string description) { Add(cmds, command, description, new BotCommandScopeAllChatAdministrators()); } /// /// Clears all group admin commands. /// /// public static void ClearGroupAdminCommand(this Dictionary> cmds) { Clear(cmds, new BotCommandScopeAllChatAdministrators()); } /// /// Adding a privat command with a description. /// /// /// /// public static void AddPrivateChatCommand(this Dictionary> cmds, string command, string description) { Add(cmds, command, description, new BotCommandScopeAllPrivateChats()); } /// /// Clears all private commands. /// /// public static void ClearPrivateChatCommand(this Dictionary> cmds) { Clear(cmds, new BotCommandScopeAllPrivateChats()); } }