403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/landing/lib/Copilot/Connector/Chat/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/landing/lib/Copilot/Connector/Chat/Chat.php
<?php
declare(strict_types=1);

namespace Bitrix\Landing\Copilot\Connector\Chat;

use Bitrix\Main\Loader;
use Bitrix\Main\Security;
use Bitrix\Landing;
use Bitrix\Landing\Copilot\Model\SiteToChatTable;

class Chat
{
	private int $userId;

	public function __construct()
	{
		$this->userId = Landing\Manager::getUserId();
	}

	/**
	 * @param int $userId
	 * @return Chat
	 */
	public function setUserId(int $userId): self
	{
		if ($userId > 0)
		{
			$this->userId = $userId;
		}

		return $this;
	}

	public static function getCreateSiteChatBot(): ?ICopilotChatBot
	{
		return self::getChatBot(CreateSiteChatBot::class);
	}

	public static function getChangeBlockChatBot(): ?ICopilotChatBot
	{
		return self::getChatBot(ChangeBlockChatBot::class);
	}

	/**
	 * Correctly create ai-chat bot
	 * @param string $botClass
	 * @return ICopilotChatBot|null
	 */
	private static function getChatBot(string $botClass): ?ICopilotChatBot
	{
		if (!Loader::includeModule('ai'))
		{
			return null;
		}

		static $chatBots = [];
		if (!isset($chatBots[$botClass]))
		{
			/**
			 * @var ICopilotChatBot $chatBot
			 */
			$chatBot = new $botClass();
			$chatBot?->register();
			$chatBots[$botClass] = $chatBot;
		}

		return $chatBots[$botClass];
	}

	/**
	 * Create unique string for chat entity id
	 * @return string
	 */
	public static function createChatEntityId(): string
	{
		return 'site_copilot_' . Security\Random::getString(6);
	}

	public function setChatForSite(int $siteId, int $chatId): bool
	{
		$exists = SiteToChatTable::query()
			->where('SITE_ID', $siteId)
			->where('CHAT_ID', $chatId)
			->where('USER_ID', $this->userId)
			->fetch()
		;
		if ($exists)
		{
			return false;
		}

		$add = SiteToChatTable::add([
			'SITE_ID' => $siteId,
			'CHAT_ID' => $chatId,
			'USER_ID' => $this->userId,
		]);

		return $add->isSuccess();
	}

	public function getChatForSite(int $siteId): ?int
	{
		$exists = SiteToChatTable::query()
			->setSelect(['CHAT_ID'])
			->where('SITE_ID', $siteId)
			->where('USER_ID', $this->userId)
			->fetch()
		;
		if ($exists)
		{
			return (int)$exists['CHAT_ID'];
		}

		return null;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit