summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-08-07 15:35:38 +0200
committerJoas Schilling <coding@schilljs.com>2023-08-08 10:46:58 +0200
commite2de469be47a9a93bb830a1e7c56147ab2da3784 (patch)
treef6f78a0c28b3c72051d1ae60476c693c560978b6
parent13c5ced6ac827ae7e51415be01274eadb4a945b0 (diff)
fix: Block bot commands on incompatible versions
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/Command/Bot/Install.php9
-rw-r--r--lib/Command/Bot/ListBots.php9
-rw-r--r--lib/Service/BotService.php7
3 files changed, 25 insertions, 0 deletions
diff --git a/lib/Command/Bot/Install.php b/lib/Command/Bot/Install.php
index 1f0ba5160..c481a7d01 100644
--- a/lib/Command/Bot/Install.php
+++ b/lib/Command/Bot/Install.php
@@ -29,6 +29,8 @@ use OC\Core\Command\Base;
use OCA\Talk\Model\Bot;
use OCA\Talk\Model\BotServer;
use OCA\Talk\Model\BotServerMapper;
+use OCP\Http\Client\IClientService;
+use OCP\Util;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -37,6 +39,7 @@ use Symfony\Component\Console\Output\OutputInterface;
class Install extends Base {
public function __construct(
private BotServerMapper $botServerMapper,
+ private IClientService $clientService,
) {
parent::__construct();
}
@@ -76,6 +79,12 @@ class Install extends Base {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
+ $client = $this->clientService->newClient();
+ if (!method_exists($client, 'postAsync')) {
+ $output->writeln('<error>You need Nextcloud Server version 27.1 or higher for Bot support (detected: ' . implode('.', Util::getVersion()) . ').</error>');
+ return 1;
+ }
+
$name = $input->getArgument('name');
$secret = $input->getArgument('secret');
$url = $input->getArgument('url');
diff --git a/lib/Command/Bot/ListBots.php b/lib/Command/Bot/ListBots.php
index 4f5251c93..9f65a0a0c 100644
--- a/lib/Command/Bot/ListBots.php
+++ b/lib/Command/Bot/ListBots.php
@@ -29,6 +29,8 @@ use OC\Core\Command\Base;
use OCA\Talk\Model\BotConversation;
use OCA\Talk\Model\BotConversationMapper;
use OCA\Talk\Model\BotServerMapper;
+use OCP\Http\Client\IClientService;
+use OCP\Util;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -37,6 +39,7 @@ class ListBots extends Base {
public function __construct(
private BotConversationMapper $botConversationMapper,
private BotServerMapper $botServerMapper,
+ private IClientService $clientService,
) {
parent::__construct();
}
@@ -55,6 +58,12 @@ class ListBots extends Base {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
+ $client = $this->clientService->newClient();
+ if (!method_exists($client, 'postAsync')) {
+ $output->writeln('<error>You need Nextcloud Server version 27.1 or higher for Bot support (detected: ' . implode('.', Util::getVersion()) . ').</error>');
+ return 1;
+ }
+
$bots = $this->botServerMapper->getAllBots();
$token = $input->getArgument('token');
diff --git a/lib/Service/BotService.php b/lib/Service/BotService.php
index e371c6ac0..59cfa5e37 100644
--- a/lib/Service/BotService.php
+++ b/lib/Service/BotService.php
@@ -45,6 +45,7 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
+use OCP\Util;
use Psr\Log\LoggerInterface;
class BotService {
@@ -65,6 +66,12 @@ class BotService {
}
public function afterChatMessageSent(ChatParticipantEvent $event, MessageParser $messageParser): void {
+ $client = $this->clientService->newClient();
+ if (!method_exists($client, 'postAsync')) {
+ $this->logger->error('You need Nextcloud Server version 27.1 or higher for Bot support (detected: ' . implode('.', Util::getVersion()) . ')');
+ return;
+ }
+
$bots = $this->getBotsForToken($event->getRoom()->getToken());
if (empty($bots)) {
return;