using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
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 BotCommand() { 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, null);
///
/// Adding the default /help command with a description.
///
///
///
public static void Help(this Dictionary> cmds, String description) => Add(cmds, "help", description, null);
///
/// Adding the default /settings command with a description.
///
///
///
public static void Settings(this Dictionary> cmds, String description) => Add(cmds, "settings", description, null);
///
/// Clears all default commands.
///
///
public static void ClearDefaultCommands(this Dictionary> cmds) => Clear(cmds, null);
///
/// 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());
}
}