setName('talk:bot:uninstall') ->setDescription('Uninstall a bot from the server') ->addArgument( 'id', InputArgument::OPTIONAL, 'The ID of the bot' ) ->addOption( 'url', null, InputOption::VALUE_REQUIRED, 'The URL of the bot (required when no ID is given, ignored otherwise)' ) ; } protected function execute(InputInterface $input, OutputInterface $output): int { $botId = (int)$input->getArgument('id'); try { if ($botId === 0) { $url = $input->getOption('url'); if ($url === null) { $output->writeln('URL is required when no ID is given'); return 1; } $bot = $this->botServerMapper->findByUrl($url); } else { $bot = $this->botServerMapper->findById($botId); } } catch (DoesNotExistException) { $output->writeln('Bot not found'); return 1; } $this->botConversationMapper->deleteByBotId($bot->getId()); $this->botServerMapper->deleteById($bot->getId()); $output->writeln('Bot uninstalled'); return 0; } }