UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Bot;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Events\BotEnabledEvent;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Model\Bot;
|
||||
use OCA\Talk\Model\BotConversation;
|
||||
use OCA\Talk\Model\BotConversationMapper;
|
||||
use OCA\Talk\Model\BotServerMapper;
|
||||
use OCA\Talk\Service\BotService;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Setup extends Base {
|
||||
public function __construct(
|
||||
private Manager $roomManager,
|
||||
private BotServerMapper $botServerMapper,
|
||||
private BotConversationMapper $botConversationMapper,
|
||||
private BotService $botService,
|
||||
private IEventDispatcher $dispatcher,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
parent::configure();
|
||||
$this
|
||||
->setName('talk:bot:setup')
|
||||
->setDescription('Add a bot to a conversation')
|
||||
->addArgument(
|
||||
'bot-id',
|
||||
InputArgument::REQUIRED,
|
||||
'The ID of the bot to set up in a conversation'
|
||||
)
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::IS_ARRAY,
|
||||
'Conversation tokens to set the bot up for'
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$botId = (int)$input->getArgument('bot-id');
|
||||
$tokens = $input->getArgument('token');
|
||||
|
||||
try {
|
||||
$botServer = $this->botServerMapper->findById($botId);
|
||||
} catch (DoesNotExistException) {
|
||||
$output->writeln('<error>Bot could not be found by id: ' . $botId . '</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!$this->botService->isAppForBotEnabled($botServer)) {
|
||||
$output->writeln('<error>Bot app is disabled: ' . $botServer->getUrl() . '</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$returnCode = 0;
|
||||
foreach ($tokens as $token) {
|
||||
try {
|
||||
$room = $this->roomManager->getRoomByToken($token);
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Federated conversations can not have bots: ' . $token . '</error>');
|
||||
$returnCode = 2;
|
||||
continue;
|
||||
}
|
||||
} catch (RoomNotFoundException) {
|
||||
$output->writeln('<error>Conversation could not be found by token: ' . $token . '</error>');
|
||||
$returnCode = 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
$bot = new BotConversation();
|
||||
$bot->setBotId($botId);
|
||||
$bot->setToken($token);
|
||||
$bot->setState(Bot::STATE_ENABLED);
|
||||
|
||||
try {
|
||||
$this->botConversationMapper->insert($bot);
|
||||
$output->writeln('<info>Successfully set up for conversation ' . $token . '</info>');
|
||||
|
||||
$event = new BotEnabledEvent($room, $botServer);
|
||||
$this->dispatcher->dispatchTyped($event);
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof Exception && $e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||
$output->writeln('<error>Bot is already set up for the conversation ' . $token . '</error>');
|
||||
$returnCode = 3;
|
||||
} else {
|
||||
$output->writeln('<error>' . get_class($e) . ': ' . $e->getMessage() . '</error>');
|
||||
$returnCode = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $returnCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user