setName('talk:bot:state') ->setDescription('Change the state or feature list for a bot') ->addArgument( 'bot-id', InputArgument::REQUIRED, 'Bot ID to change the state for' ) ->addArgument( 'state', InputArgument::REQUIRED, 'New state for the bot (0 = disabled, 1 = enabled, 2 = no setup via GUI)' ) ->addOption( 'feature', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Specify the list of features for the bot' . "\n" . ' - webhook: The bot receives posted chat messages as webhooks' . "\n" . ' - response: The bot can post messages and reactions as a response' . "\n" . ' - none: When all features should be disabled for the bot' ) ; } protected function execute(InputInterface $input, OutputInterface $output): int { $botId = (int)$input->getArgument('bot-id'); $state = (int)$input->getArgument('state'); $featureFlags = null; if (!empty($input->getOption('feature'))) { $featureFlags = Bot::featureLabelsToFlags($input->getOption('feature')); } if (!in_array($state, [Bot::STATE_DISABLED, Bot::STATE_ENABLED, Bot::STATE_NO_SETUP], true)) { $output->writeln('Provided state is invalid'); return 1; } try { $bot = $this->botServerMapper->findById($botId); } catch (DoesNotExistException) { $output->writeln('Bot could not be found by id: ' . $botId . ''); return 1; } $bot->setState($state); if ($featureFlags !== null) { $bot->setFeatures($featureFlags); } $this->botServerMapper->update($bot); if ($featureFlags !== null) { $output->writeln('Bot state set to ' . $state . ' with features: ' . Bot::featureFlagsToLabels($featureFlags) . ''); } else { $output->writeln('Bot state set to ' . $state . ''); } return 0; } }