Esempio n. 1
0
        private void HandleCommand(Message message)
        {
            ICommandStrategy strategy = null;
            var command = message.GetCommand();
            switch (command)
            {
                case "/start": strategy = new StartCommand(_db.Value, _bot.Value); break;
                case "/help": strategy = new HelpCommand(_commandHelper.Value, _bot.Value); break;
                case "/settings": strategy = new SettingsCommand(_bot.Value); break;
                case "/add": strategy = new AddCommand(_bot.Value, _db.Value); break;
                case "/list": strategy = new ListCommand(_bot.Value, _db.Value, _commandHelper.Value); break;
                default:
                    if (Config.BotAdmins.Contains(message.Chat.Id) && Config.AdminCommands.Contains(command))
                    {
                        switch (command)
                        {
                            case "/admin": strategy = new AdminCommand(_bot.Value); break;
                            case "/allowuser": strategy = new AllowUserCommand(_bot.Value, _db); break;
                            case "/disallowuser": strategy = new DisallowUserCommand(_bot.Value, _db); break;
                        }
                        break;
                    }

                    if (_commandHelper.Value.CheckPermission(message.Chat.Id))
                    {
                        switch (command)
                        {
                            case "/wol": strategy = new WolCommand(_bot.Value); break;
                            case "/alias": strategy = new AliasCommand(_db.Value, _bot.Value, _commandHelper.Value); break;
                        }
                    }

                    if (_db.Value.GetCommandByChat(message.Chat.Id, message.Text) != null)
                        strategy = new CustomUserCommand(_db.Value, _bot.Value);
                    break;
            }
            new CommandContext(strategy ?? new UnknownCommand(_bot.Value)).Execute(message);
        }