404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.147.59.237: ~ $
x+O԰blob 20256<?php

include dirname(__FILE__, 2) . "/database/DatabaseHandler.php";
include dirname(__FILE__, 1) . "/Bot.php";
include dirname(__FILE__, 2) . "/translate/Exception.php";
include dirname(__FILE__, 2) . "/translate/Translation.php";
include dirname(__FILE__, 2) . "/translate/Translator.php";
include dirname(__FILE__, 2) . "/tts/voicerss_tts.php";
include dirname(__FILE__, 2) . "/user/User.php";
class MessageProcessor
{
	public $user;
	public $message;
	public $message_id;
	public $chat_id;
	public $adminId;
	public $sobhanId;
	public $callback_data;
	public $callback_id;
	public $inlineText;
	public $inline_message_id;
	public $sign;
	public $adminCallbackUserId;
	public $userCallBackId;
	public $debugsManager;
	public $bot;
	public $botUsername;
	public $method;
	public $params;
	public $debug;
	public $BOT_TOKEN;
	private $WEBHOOK_URL;
	public $buttonService;



	function __construct($botUsername, $botToken, $webhookUrl, $sign, $adminId)
	{
		$this->bot = new Bot($botUsername, $botToken, $webhookUrl);
		$this->botUsername = $botUsername;
		$this->WEBHOOK_URL = $webhookUrl;
		$this->BOT_TOKEN = $botToken;
		$this->sign = $sign;
		$this->debug = false;
		$this->adminCallbackUserId = 305982822;
		$this->adminId = $adminId;
		$this->sobhanId = 611059896;
		$this->debugsManager = new DebugsManager();
	}

	public function apiRequest($method, $params){
		$this->method = $method;
		$this->params = $params;
		return $this->getBot()->apiRequest($method, $params);
	}

	public function getBot(): Bot {
		return $this->bot;
	}

	public function apiRequestWebhook($method, $params){
		$this->method = $method;
		$this->params = $params;
		return $this->bot->apiRequest($method, $params);
	}

	public function getDebugsManager() {
		return $this->debugsManager;
	}
	public function navigateHome($chatID, $messageID){
		echo "show main callback buttons";
	}
	function convertPersianNumbersToEnglish($input)
    {
        $persian = ['۰', '۱', '۲', '۳', '۴', '٤', '۵', '٥', '٦', '۶', '۷', '۸', '۹'];
        $english = [ 0 ,  1 ,  2 ,  3 ,  4 ,  4 ,  5 ,  5 ,  6 ,  6 ,  7 ,  8 ,  9 ];
        return str_replace($persian, $english, $input);
    }
	public function process($update)
	{
		switch ($this->getMessageType($update)) {
			case "video":
				$this->setUpMessageData($update);
				$this->processVideo($update);
				break;
			case "voice":
				$this->setUpMessageData($update);
				$this->processVoice($update);
				break;
			case "photo":
				$this->setUpMessageData($update);
				$this->processPhoto($update);
				break;
			case "text":
				$this->setUpMessageData($update);
				$this->processText($update);
				break;
			case "callback":
				$this->setUpCallbBackData($update);
				$this->processCallback($update);

				break;
			case "inlineQuery":
				$this->setUpInlineQueryData($update);
				$this->processInlineQuery($update);
				break;
			default:
				$this->setUpMessageData($update);
				$this->processOther($update);
				break;
		}
		if ($this->isAdmin()) {
			$messageId = $update['message']['message_id'];
			$this->getButtonService()->removeAllButtons();
			$markedUpButtons = $this->getButtonService()->getADButton($messageId);
			$this->sendMarkedupMessage("add ads from  $messageId",$markedUpButtons);

		}
		if ($this->debug) {
			$this->apiRequest("sendMessage", array(
				'chat_id' => 44903244,
				'disable_notification' => false,
				"text" => urldecode("<b>hi debug</b>"),
				"parse_mode" => "html"

			));
		}
	}
	public function getButtonService(): ButtonService
	{
		return $this->buttonService;
	}
	public function getMessageType($update)
	{

		if (isset($update['message']['text'])) {
			return "text";
		} else if (isset($update['message']['voice'])) {
			return "voice";
		} else if (isset($update['message']['video'])) {
			return "video";
		} else if (!empty($update['message']['photo'])) {
			return "photo";
		} else if (isset($update['callback_query'])) {
			return "callback";
		} else if (isset($update['inline_query'])) {
			return "inlineQuery";
		}
	}
	public function setUpCallbBackData($update)
	{
		$updatedMessage = $update['callback_query'];
		// process incoming message

		$this->message = $updatedMessage['message'];
		$this->user = $this->message['from'];
		$this->userCallBackId = $this->user['id'];
		$this->message_id = $this->message['message_id'];
		$this->chat_id = $this->message['chat']['id'];
		$this->callback_data = $update['callback_query']['data'];
		$this->callback_id = $update['callback_query']['id'];
	}
	public function setUpInlineQueryData($update)
	{
		// process incoming message
		$this->message = $update['inline_query'];
		$this->user = $this->message['from'];
		$this->inline_message_id = $this->message['id'];
		//$this->chat_id = $this->message ['chat'] ['id'];
		$this->inlineText = $this->message['query'];
	}
	public function setUpMessageData($update)
	{

		// process incoming message
		$this->message = $update['message'];
		$this->user = $this->message['from'];
		$this->message_id = $this->message['message_id'];
		$this->chat_id = $this->message['chat']['id'];
	}
	public function getDB()
	{
	}
	public function processVideo($update)
	{
		// 		$testMessage = var_export ( $update, true );
		// 		file_put_contents ( "testbot.html", $testMessage, FILE_APPEND | LOCK_EX );

		// $dbPostHandler = new DatabaseHandler($this->botUsername);
		// $result = $dbPostHandler->addPostToDatabase($this->message, $this->botUsername, $this->user['id']);
		// $this->apiRequest("sendMessage", array(
		// 	'chat_id' => $this->chat_id,
		// 	'text' => $result
		// ));

		//                $fileLink = $this->getFileLink($update['message']['video']['file_id']);
		$this->apiRequest("forwardMessage", array(
			'chat_id' => $this->adminId,
			'from_chat_id' => $this->user['id'],
			'message_id' => $this->message_id,
		));
		// if($this->isAdmin())
		$this->sendMessageLog("Video msgid:" . $this->message_id . " from chatID" . $this->user['id']);
		//		echo "</br>show message request caption";
	}

	public function processVoice($update)
	{
		// 		$this->apiRequest ( "sendMessage", array (
		// 				'chat_id' => 44903244,
		// 				'disable_notification' => false,
		// 				"text" => $this->user ['id'] . "@@@" . $this->user ['username'] . "--" . $this->user ['first_name'] . " " . $this->user ['last_name'] . ": sent Voice "
		// 		) );
		$fileLink = $this->getFileLink($update['message']['voice']['file_id']);
		$this->apiRequest("forwardMessage", array(
			'chat_id' => $this->adminId,
			'from_chat_id' => $this->user['id'],
			'message_id' => $this->message_id,
		));
		$repliedTomessage = $this->message['reply_to_message'];
		if (!empty($repliedTomessage) && $this->user['id'] == 44903244  && isset($repliedTomessage['forward_from'])) {
			$this->sendVoice($this->message['voice']['file_id'], $repliedTomessage['forward_from']['id']);
		}
		// 		$this->apiRequest ( "sendVoice", array (
		// 				'chat_id' => 44903244,
		// 				"voice" => $this->message['voice']['file_id']
		// 		) );
	}

	public function processOther($update)
	{
		$this->apiRequest("forwardMessage", array(
			'chat_id' => $this->adminId,
			'from_chat_id' => $this->user['id'],
			'message_id' => $this->message_id,
		));
		// 			$testMessage = var_export ( $message, true );
		// 			file_put_contents ( "testbot.html", $testMessage, FILE_APPEND | LOCK_EX );
		// if()
		// 		$this->apiRequest ( "sendMessage", array (
		// 					'chat_id' => $this->chat_id,
		// 					"text" => 'I understand only text messages '
		// 			) );
	}
	public function forwardMessageLog()
	{
		$this->apiRequest("forwardMessage", array(
			'chat_id' => $this->adminId,
			'from_chat_id' => $this->user['id'],
			'message_id' => $this->message_id
		));
	}
	public function forwardMessageFromTo($msgID, $fromChatID, $targetUserID)
	{
		$result = $this->apiRequest("forwardMessage", array(
			'chat_id' => $targetUserID,
			'from_chat_id' => $fromChatID,
			'message_id' => $msgID
		));
		if(!$result){
			// $this->sendMessageLog("cant forward");
		}
		return $result;
	}
	public function forwardMessage($distUserId)
	{
		$this->apiRequest("forwardMessage", array(
			'chat_id' => $distUserId,
			'from_chat_id' => $this->user['id'],
			'message_id' => $this->message_id
		));
	}
	public function getFileLink($fileId)
	{
		$fileInfo = $this->getFileInfo($fileId);
		return $fileInfo = "https://api.telegram.org/file/bot".$this->TOKEN."/" . $fileInfo['file_path'];
	}
	public function getFileInfo($fileId)
	{
		return $this->apiRequest("getFile", array(
			'file_id' => $fileId
		));
	}
	public function isAdmin()
	{
		return ($this->adminId == $this->chat_id || $this->sobhanId == $this->chat_id  /*|| $this->userCallBackId == $this->adminCallbackUserId*/);
	}
	public function sendMessage($msg, $userId, $messageId = "")
	{
		if (empty($userId))
			$userId = $this->chat_id;
		return $this->apiRequest("sendMessage", array(
			'chat_id' => $userId,
			"text" => $msg,
			"reply_to_message_id" => $messageId
		));
	}
	public function getUserProfile($userid)
	{
		return	$this->apiRequest("getUserProfilePhotos", array(
			'user_id' => $userid,
		));
	}
	
	public function sendPhoto($file_id, $userid)
	{
		$this->apiRequest("sendPhoto", array(
			'chat_id' => $userid,
			'photo' => $file_id
		));
	}

	public function sendPhotoMarkedUp($file_id, $userid, $markup)
	{
		$this->apiRequest("sendPhoto", array(
			'chat_id' => $userid,
			'photo' => $file_id,
			"reply_markup" => $markup,

		));
	}

	public function sendVoice($file_id, $userid)
	{
		$this->apiRequest("sendVoice", array(
			'chat_id' => $userid,
			'voice' => $file_id
		));
	}
	public function sendVoiceMarkedUp($file_id, $userid, $markedUpButtons)
	{
		$this->apiRequest("sendVoice", array(
			'chat_id' => $userid,
			'voice' => $file_id,
			"reply_markup" => $markedUpButtons,

		));
	}
	public function sendMessageLog($msgLog)
	{
		if (isset($this->message['from']['first_name']))
			$firstName = $this->message['from']['first_name'];
		else {
			$firstName = "";
		}
		if (isset($this->message['from']['last_name']))
			$lastName = $this->message['from']['last_name'];
		else
			$lastName = "";
		if (isset($this->message['from']['username']))
			$username = $this->message['from']['username'];
		else
			$username = "";

		$this->apiRequest("sendMessage", array(
			'chat_id' => $this->adminId,
			"text" => "Log: " . $this->message['from']['id'] . $username . "--" . $firstName . " " . $lastName
				. PHP_EOL . PHP_EOL . "<a href=''>" . $msgLog . "</a>",
			"parse_mode" => "html",
			"disable_web_page_preview" => true

		));
		// 				,
		// 				"reply_markup" =>$markup
	}
	public function askUser($questionText, $approveId, $userId = 44903244, $answer1 = "بلی", $answer2 = "خیر")
	{
		$keyboard = array(
			'inline_keyboard' => [[
				['text' =>  $answer1, 'callback_data' => $approveId],
				['text' =>  $answer2, 'callback_data' => EnumAnswer::NO . ":" . $approveId]
			]],
		);
		$markup = json_encode($keyboard, true);

		$this->apiRequest("sendMessage", array(
			'chat_id' => $userId,
			"text" => $questionText,
			"parse_mode" => "html",
			"disable_web_page_preview" => true

		));
		// 				,
		// 				
	}
	public function cancelMessage($msgText, $message_id)
	{
		$this->apiRequest("editMessageText", array(
			'chat_id' => $this->chat_id,
			"message_id" =>  $message_id,
			"text" => $msgText,
			"parse_mode" => "html",
			"reply_markup" => $markup,
			"disable_web_page_preview" => true

		));
	}
	public function deleteMessage()
	{
		$this->apiRequest("deleteMessage", array(
			'chat_id' => $this->chat_id,
			"message_id" =>  $this->message['message_id'],
		));
	}
	public function editAskUserMultipleChoiceQuestion($questionText, $answerArray, $task = "select")
	{
		if (!empty($answerArray)) {
			foreach ($answerArray as $key => $answer) {
				$inlineKeyboardRow[$key][] = [
					'text' =>  $answer['text'],
					'callback_data' => $answer['id']
				];
			}
			$keyboard = [
				'inline_keyboard' => $inlineKeyboardRow
			];
			$markup = json_encode($keyboard, true);
			$this->apiRequest("editMessageText", array(
				'chat_id' => $this->chat_id,
				"message_id" =>  $this->message['message_id'],
				"text" => $questionText,
				"parse_mode" => "html",
				"reply_markup" => $markup,
				"disable_web_page_preview" => true

			));
		} else
			$this->apiRequest("editMessageText", array(
				'chat_id' => $this->chat_id,
				"message_id" =>  $this->message['message_id'],
				"text" => $questionText,
				"parse_mode" => "html",
				"disable_web_page_preview" => true
			));
	}

	public function editMessageText($messageID,$chatID,$messageText,$markup)
	{
		$this->apiRequest("editMessageText", array(
			'chat_id' => $chatID,
			"message_id" =>  $messageID,
			"text" => $messageText,
			"parse_mode" => "html",
			"reply_markup" => $markup,
			"disable_web_page_preview" => true

		));
	}
	public function editMultpleButtonsMessage($messageText,$markup)
	{
		return $this->apiRequest("editMessageText", array(
			'chat_id' => $this->chat_id,
			"message_id" =>  $this->message_id,
			"text" => $messageText,
			"parse_mode" => "html",
			"reply_markup" => $markup,
			"disable_web_page_preview" => true

		));
	}
	public function setWebhook(){
		$this->apiRequest( 'setWebhook', array (
				'url' => $this->WEBHOOK_URL
		) );
	}
	public function askUserMultipleChoiceQuestion($questionText, $answerArray, $userId, $messageId = "")
	{
		if (!isset($userId))
			$userId = $this->chat_id;
		foreach ($answerArray as $key => $answer) {
			$inlineKeyboardRow[$key][] = ['text' =>  $answer['text'], 'callback_data' => $answer['id'] . ":" . $answer['text']];
		}
		$keyboard = [
			'inline_keyboard' => $inlineKeyboardRow
		];
		$markup = json_encode($keyboard, true);

		$this->apiRequest("sendMessage", array(
			'chat_id' => $userId,
			"text" => $questionText,
			"parse_mode" => "html",
			"reply_markup" => $markup,
			"disable_web_page_preview" => true,
			"reply_to_message_id" => $messageId

		));
	}
	public function askMultipleChoiceQuestion($questionText, $answerArray, $userId)
	{
		if (!isset($userId))
			$userId = $this->chat_id;
		if (!is_array($answerArray))
			return false;
		foreach ($answerArray as $key => $answer) {
			$inlineKeyboardRow[$key][] = ['text' =>  $answer['text'], 'callback_data' => $answer['id'] . ":" . $answer['id']];
		}
		$keyboard = [
			'inline_keyboard' => $inlineKeyboardRow
		];
		$markup = json_encode($keyboard, true);

		$this->apiRequest("sendMessage", array(
			'chat_id' => $userId,
			"text" => $questionText,
			"parse_mode" => "html",
			"reply_markup" => $markup,
			"disable_web_page_preview" => true

		));
	}
	public function editAskMultipleChoiceQuestion($questionText, $answerArray)
	{
		if (!isset($userId))
			$userId = $this->chat_id;
		foreach ($answerArray as $key => $answer) {
			$inlineKeyboardRow[$key][] = ['text' =>  $answer['text'], 'callback_data' => "task:" . $answer['id']];
		}
		$keyboard = [
			'inline_keyboard' => $inlineKeyboardRow
		];
		$markup = json_encode($keyboard, true);

		$this->apiRequest("editMessageText", array(
			'chat_id' => $this->chat_id,
			"message_id" =>  $this->message['message_id'],
			"text" => $questionText,
			"parse_mode" => "html",
			"reply_markup" => $markup,
			"disable_web_page_preview" => true

		));
	}
	public function askMultipleChoiceImageQuestion($questionText, $answerArray, $userId, $imageUrl)
	{
		if (!isset($userId))
			$userId = $this->chat_id;
		foreach ($answerArray as $key => $answer) {
			$inlineKeyboardRow[$key][] = ['text' =>  $answer['text'], 'callback_data' => "task:" . $answer['id']];
		}
		$keyboard = [
			'inline_keyboard' => $inlineKeyboardRow
		];
		$markup = json_encode($keyboard, true);

		$this->apiRequest("sendPhoto", array(
			'chat_id' => $userId,
			"photo" => $imageUrl,
			"caption" => $questionText,
			"reply_markup" => $markup
		));
	}
	public function processPhoto($update)
	{



		$repliedTomessage = $this->message['reply_to_message'];
		if (!empty($repliedTomessage) && isset($repliedTomessage['forward_from'])) {
			// $this->apiRequestWebhook ( "sendPhoto", array (
			// 		'chat_id' => $repliedTomessage ['forward_from']['id'],
			// 		"photo" => $this->message['photo']['file_id']
			// ) );
			$size = sizeof($this->message['photo']);
			$fileId = $this->message['photo'][$size - 1]['file_id'];
			$this->sendPhoto($fileId, $repliedTomessage['forward_from']['id']);
		} else {
 			$this->apiRequest("forwardMessage", array(
				'chat_id' => $this->adminId,
				'from_chat_id' => $this->user['id'],
				'message_id' => $this->message_id,
			)); 
		}
	}
	public function sendMarkedupMessageToAdmin($text, $markup)
	{
		$this->apiRequest("sendMessage", array(
			'chat_id' => $this->adminId,
			"text" => $text,
			"parse_mode" => "html",
			"disable_web_page_preview" => true,
			"reply_markup" => $markup
		));
	}
	public function sendMarkedupMessage($text, $markup)
	{
		$this->apiRequest("sendMessage", array(
			'chat_id' => $this->chat_id,
			"text" => $text,
			"parse_mode" => "html",
			"disable_web_page_preview" => true,
			"reply_markup" => $markup
		));
	}
	public function sendMarkedupMessageWeb($text, $markup)
	{
		$this->apiRequestWebhook("sendMessage", array(
			'chat_id' => $this->chat_id,
			"text" => $text,
			"parse_mode" => "html",
			"disable_web_page_preview" => true,
			"reply_markup" => $markup
		));
	}
	public function sendYoutubeLink($youtubeLink)
	{
		$this->apiRequest("sendMessage", array(
			'chat_id' => $this->chat_id,
			"text" => $youtubeLink
		));
	}

	public function processCallback($update)
	{
		// 		$testMessage = var_export ( $update, true );
		// 			file_put_contents ( "testbot.html", $testMessage, FILE_APPEND | LOCK_EX );
		$this->apiRequest("sendMessage", array(
			'chat_id' => "@sinzed",
			"text" => 'I understand only text messages2 '
		));
	}
	public function processInlineQuery($update)
	{
		$testMessage = var_export($update, true);
		// 			file_put_contents ( "testbot.html", $testMessage, FILE_APPEND | LOCK_EX );
		$this->apiRequest("sendMessage", array(
			'chat_id' => "@sinzed",
			"text" => 'I understand only text messages2 ' . $testMessage
		));
	}
	public function isPersianLanguage($word)
	{
		return preg_match('/[^A-Za-z0-9]/', $word)
			&& !preg_match('/ü/', $word)
			&& !preg_match('/Ü/', $word)
			&& !preg_match('/ä/', $word)
			&& !preg_match('/Ä/', $word)
			&& !preg_match('/ö/', $word)
			&& !preg_match('/Ö/', $word)
			&& !preg_match('/ß/', $word);
	}
	public function addWaterMark($photo)
	{
		// Load the stamp and the photo to apply the watermark to
		$stamp = imagecreatefrompng('stamp.png');
		$im = imagecreatefromjpeg($photo);

		// Set the margins for the stamp and get the height/width of the stamp image
		$marge_right = 10;
		$marge_bottom = 10;
		$sx = imagesx($stamp);
		$sy = imagesy($stamp);

		// Copy the stamp image onto our photo using the margin offsets and the photo
		// width to calculate positioning of the stamp.
		imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

		// Output and free memory
		header('Content-type: image/png');
		$extensstion = rand(10, 100000);
		imagepng($im, "images/newimage$extensstion.png");
		imagedestroy($im);

		return "https://www.towist.com/autopost/bots/images/newimage$extensstion.png";
	}
	public function isSingleWord($text)
	{
		return sizeof(explode(" ", $text)) == 1;
	}
	public function getSpeech($text, $lang = 'de-de')
	{
		$keys[] = "b0506608a6794c6ba2161a959e5dcc9d";
		$keys[] = "ace37a4b5c2245b1a5db87bd16039940";
		$keys[] = "d4088bb9b0414fdda8fe330ddecfcb96";
		$keys[] = "53c6b9675e774eb89ae98ec5219176a0";
		$keys[] = "abbf9bf025c34f759488816a34ba070c";
		$keys[] = "44469874e088474eaed17692919b959f";
		$keys[] = "9ea01742b0154b0ab22d31f6c54d7d68";
		$keys[] = "b7ab116fdee94e45b7b91c438af4b9b2";
		$keys[] = "7c9672f9bd5e44a98a335cb309941beb";
		$tts = new VoiceRSS;
		$voice = $tts->speech([
			'key' => $keys[array_rand($keys, 1)],
			'hl' => $lang,
			'src' => $text,
			'r' => '-5',
			'c' => 'mp3',
			'f' => '44khz_16bit_stereo',
			'ssml' => 'false',
			'b64' => 'false'
		]);
		return $voice;
	}

	function processText()
	{
		echo "nothing to do in abstract model";
	}
}
`v

Filemanager

Name Type Size Permission Actions
239c0d168b86c8b43e70c7bc9a2d7b2d397de8 File 726 B 0444
573b9a8cdfd1280ae40f6434ad1514fd48b8b5 File 163 B 0755
5e50c2181587b3dd6ade790615192ad7087f49 File 882 B 0444
6662938ff98eff39490055ded8b9ef66faecc0 File 19.8 KB 0444
749fc53ad4c70ac608d7684878c86d7e14d032 File 49 B 0755
adf73a7ef6f90958e80054fbc948e4cfb4822b File 300 B 0755
c21a2a9dea41e5f5a1210dd6b4c4ae32a97254 File 1.06 KB 0755
ce3eed1121f10f997ba088b4f1e6e3e4c68c17 File 685 B 0755
dc4c1fe7bbeef3c9f129f539e24ce753f8b482 File 91 B 0755