/** * Title * * Description * * @access public */ function say($ph, $level=0) { global $commandLine; global $voicemode; /* if ($commandLine) { echo utf2win($ph); } else { echo $ph; } */ $rec=array(); $rec['MESSAGE']=$ph; $rec['ADDED']=date('Y-m-d H:i:s'); $rec['ROOM_ID']=0; $rec['MEMBER_ID']=0; if ($level>0) { $rec['IMPORTANCE']=$level; } SQLInsert('shouts', $rec); if ($level>=(int)getGlobal('minMsgLevel')) { //$voicemode!='off' && $lang='en'; if (defined('SETTINGS_SITE_LANGUAGE')) { $lang=SETTINGS_SITE_LANGUAGE; } if (defined('SETTINGS_VOICE_LANGUAGE')) { $lang=SETTINGS_VOICE_LANGUAGE; } $google_file=GoogleTTS($ph, $lang); if ($google_file) { @touch($google_file); playSound($google_file, 1, $level); } else { //getObject("alice")->raiseEvent("say", array("say"=>$ph)); safe_exec('cscript '.DOC_ROOT.'/rc/sapi.js '.$ph, 1, $level); } } postToTwitter($ph); global $noPatternMode; if (!$noPatternMode) { include_once(DIR_MODULES.'patterns/patterns.class.php'); $pt=new patterns(); $pt->checkAllPatterns(); } }
/** * Title * * Description * * @access public */ function say($ph, $level = 0, $member_id = 0) { global $commandLine; global $voicemode; global $noPatternMode; global $ignorePushover; global $ignorePushbullet; global $ignoreGrowl; global $ignoreTwitter; /* if ($commandLine) { echo utf2win($ph); } else { echo $ph; } */ $rec = array(); $rec['MESSAGE'] = $ph; $rec['ADDED'] = date('Y-m-d H:i:s'); $rec['ROOM_ID'] = 0; $rec['MEMBER_ID'] = $member_id; if ($level > 0) { $rec['IMPORTANCE'] = $level; } $rec['ID'] = SQLInsert('shouts', $rec); if ($member_id) { //if (!$noPatternMode) { include_once DIR_MODULES . 'patterns/patterns.class.php'; $pt = new patterns(); $pt->checkAllPatterns($member_id); //} return; } if (defined('SETTINGS_HOOK_BEFORE_SAY') && SETTINGS_HOOK_BEFORE_SAY != '') { eval(SETTINGS_HOOK_BEFORE_SAY); } global $ignoreVoice; if ($level >= (int) getGlobal('minMsgLevel') && !$ignoreVoice && !$member_id) { //$voicemode!='off' && $lang = 'en'; if (defined('SETTINGS_SITE_LANGUAGE')) { $lang = SETTINGS_SITE_LANGUAGE; } if (defined('SETTINGS_VOICE_LANGUAGE')) { $lang = SETTINGS_VOICE_LANGUAGE; } if (!defined('SETTINGS_TTS_GOOGLE') || SETTINGS_TTS_GOOGLE) { $google_file = GoogleTTS($ph, $lang); } else { $google_file = false; } if (!defined('SETTINGS_SPEAK_SIGNAL') || SETTINGS_SPEAK_SIGNAL == '1') { $passed = time() - (int) getGlobal('lastSayTime'); if ($passed > 20) { // play intro-sound only if more than 20 seconds passed from the last one setGlobal('lastSayTime', time()); playSound('dingdong', 1, $level); } } if ($google_file) { @touch($google_file); playSound($google_file, 1, $level); } else { safe_exec('cscript ' . DOC_ROOT . '/rc/sapi.js ' . $ph, 1, $level); } } if (!$noPatternMode) { include_once DIR_MODULES . 'patterns/patterns.class.php'; $pt = new patterns(); $pt->checkAllPatterns($member_id); } if (defined('SETTINGS_PUSHOVER_USER_KEY') && SETTINGS_PUSHOVER_USER_KEY && !$ignorePushover) { include_once ROOT . 'lib/pushover/pushover.inc.php'; if (defined('SETTINGS_PUSHOVER_LEVEL')) { if ($level >= SETTINGS_PUSHOVER_LEVEL) { postToPushover($ph); } } elseif ($level > 0) { postToPushover($ph); } } if (defined('SETTINGS_PUSHBULLET_KEY') && SETTINGS_PUSHBULLET_KEY && !$ignorePushbullet) { include_once ROOT . 'lib/pushbullet/pushbullet.inc.php'; if (defined('SETTINGS_PUSHBULLET_PREFIX') && SETTINGS_PUSHBULLET_PREFIX) { $prefix = SETTINGS_PUSHBULLET_PREFIX . ' '; } else { $prefix = ''; } if (defined('SETTINGS_PUSHBULLET_LEVEL')) { if ($level >= SETTINGS_PUSHBULLET_LEVEL) { postToPushbullet($prefix . $ph); } } elseif ($level > 0) { postToPushbullet($prefix . $ph); } } if (defined('SETTINGS_GROWL_ENABLE') && SETTINGS_GROWL_ENABLE && $level >= SETTINGS_GROWL_LEVEL && !$ignoreGrowl) { include_once ROOT . 'lib/growl/growl.gntp.php'; $growl = new Growl(SETTINGS_GROWL_HOST, SETTINGS_GROWL_PASSWORD); $growl->setApplication('MajorDoMo', 'Notifications'); //$growl->registerApplication('http://localhost/img/logo.png'); $growl->notify($ph); } if (defined('SETTINGS_TWITTER_CKEY') && SETTINGS_TWITTER_CKEY && !$ignoreTwitter) { postToTwitter($ph); } if (defined('SETTINGS_HOOK_AFTER_SAY') && SETTINGS_HOOK_AFTER_SAY != '') { eval(SETTINGS_HOOK_AFTER_SAY); } }
/** * Title * * Description * * @access public */ function say($ph, $level = 0) { global $commandLine; global $voicemode; /* if ($commandLine) { echo utf2win($ph); } else { echo $ph; } */ $rec = array(); $rec['MESSAGE'] = $ph; $rec['ADDED'] = date('Y-m-d H:i:s'); $rec['ROOM_ID'] = 0; $rec['MEMBER_ID'] = 0; if ($level > 0) { $rec['IMPORTANCE'] = $level; } $rec['ID'] = SQLInsert('shouts', $rec); if (defined('SETTINGS_HOOK_BEFORE_SAY') && SETTINGS_HOOK_BEFORE_SAY != '') { eval(SETTINGS_HOOK_BEFORE_SAY); } if ($level >= (int) getGlobal('minMsgLevel')) { //$voicemode!='off' && $lang = 'en'; if (defined('SETTINGS_SITE_LANGUAGE')) { $lang = SETTINGS_SITE_LANGUAGE; } if (defined('SETTINGS_VOICE_LANGUAGE')) { $lang = SETTINGS_VOICE_LANGUAGE; } if (!defined('SETTINGS_TTS_GOOGLE') || SETTINGS_TTS_GOOGLE) { $google_file = GoogleTTS($ph, $lang); } else { $google_file = false; } if (!defined('SETTINGS_SPEAK_SIGNAL') || SETTINGS_SPEAK_SIGNAL == '1') { $passed = SQLSelectOne("SELECT (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(ADDED)) as PASSED FROM shouts WHERE ID!='" . $rec['ID'] . "' ORDER BY ID DESC LIMIT 1"); if ($passed['PASSED'] > 20) { // play intro-sound only if more than 30 seconds passed from the last one playSound('dingdong', 1, $level); } } if ($google_file) { @touch($google_file); playSound($google_file, 1, $level); } else { safe_exec('cscript ' . DOC_ROOT . '/rc/sapi.js ' . $ph, 1, $level); } } global $noPatternMode; if (!$noPatternMode) { include_once DIR_MODULES . 'patterns/patterns.class.php'; $pt = new patterns(); $pt->checkAllPatterns(); } if (defined('SETTINGS_HOOK_AFTER_SAY') && SETTINGS_HOOK_AFTER_SAY != '') { eval(SETTINGS_HOOK_AFTER_SAY); } if (defined('SETTINGS_PUSHOVER_USER_KEY') && SETTINGS_PUSHOVER_USER_KEY) { include_once ROOT . 'lib/pushover/pushover.inc.php'; if (defined('SETTINGS_PUSHOVER_LEVEL')) { if ($level >= SETTINGS_PUSHOVER_LEVEL) { postToPushover($ph); } } elseif ($level > 0) { postToPushover($ph); } } if (defined('SETTINGS_GROWL_ENABLE') && SETTINGS_GROWL_ENABLE && $level >= SETTINGS_GROWL_LEVEL) { include_once ROOT . 'lib/growl/growl.gntp.php'; $growl = new Growl(SETTINGS_GROWL_HOST, SETTINGS_GROWL_PASSWORD); $growl->setApplication('MajorDoMo', 'Notifications'); //$growl->registerApplication('http://localhost/img/logo.png'); $growl->notify($ph); } postToTwitter($ph); }
public function onRun($currentTick) { if (count($this->plugin->storage->arenaList > 0)) { foreach ($this->plugin->storage->arenaList as $arena) { $loop = false; $block = false; if ($arena->gameState == ArenaState::WAITING) { if (count($arena->playersInArena) >= $arena->minPlayers) { $arena->gameState = ArenaState::STARTING; $arena->timer = $arena->timeInLobbyUntilStart; ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-" . $arena->timeInLobbyUntilStart); } } else { if ($arena->gameState == ArenaState::STARTING) { $arena->timer -= 1; if ($arena->timer > 0) { if ($arena->timer == 60) { ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-60"); } else { if ($arena->timer == 30) { ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-30"); } else { if ($arena->timer == 10) { ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-10"); } else { if ($arena->timer == 5) { // for (Player pl : $arena->playersInArena) { // pl.playSound(pl.getLocation(), Sound.ORB_PICKUP, 1, 0); // } ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-5"); } else { if ($arena->timer == 4) { // for (Player pl : $arena->playersInArena) { // pl.playSound(pl.getLocation(), // Sound.ORB_PICKUP, 1, 0); // } ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-4"); } else { if ($arena->timer == 3) { // for (Player pl : $arena->playersInArena) { // pl.playSound(pl.getLocation(), // Sound.ORB_PICKUP, 1, 1); // } ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-3"); } else { if ($arena->timer == 2) { // for (Player pl : $arena->playersInArena) { // pl.playSound(pl.getLocation(), // Sound.ORB_PICKUP, 1, 1); // } ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-2"); } else { if ($arena->timer == 1) { // for (Player pl : $arena->playersInArena) { // pl.playSound(pl.getLocation(), // Sound.ORB_PICKUP, 1, 2); // } ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaIsStarting"], "1-1"); } } } } } } } } } else { $arena->gameState = ArenaState::INGAME; $arena->timer = $arena->gameTime; ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["lobbyArenaStarted"], "secs-" . $arena->waitingTimeSeeker); for ($i = $arena->amountSeekersOnStart; $i > 0; $i--) { $loop = true; $seeker = mt_rand(0, count($arena->playersInArena) - 1); foreach ($arena->playersInArena as $playerCheck) { if ($this->plugin->storage->choosenSeeker[$playerCheck] != null) { if ($this->plugin->storage->choosenSeeker[$playerCheck]) { $seeker = $playerCheck; unset($this->plugin->storage->choosenSeeker[$playerCheck]); } else { if ($seeker == $playerCheck) { $i++; $loop = false; } } } } if ($loop) { if (!in_array($seeker, $arena->seekers)) { ArenaHandler::sendFMessage($arena, "%TAG%NPlayer %A%seeker%%N has been choosen as seeker!", "seeker-" . $seeker->getName()); $arena->seekers[] = $seeker; $seeker->teleport($arena->seekersWarp); $seeker . getInventory()->clearAll(); $this->plugin->storage->seekertime[$seeker] = $arena->waitingTimeSeeker; } else { $i++; } } } foreach ($arena->playersInArena as $arenaPlayer) { if (!in_array($arenaPlayer, $arena->seekers)) { $arenaPlayer->getInventory()->clearAll(); $block = $arena->disguiseBlocks[mt_rand(0, count($arena->disguiseBlocks))]; if ($this->plugin->storage->choosenBlock[$arenaPlayer] != null) { $block = $this->plugin->storage->choosenBlock[$arenaPlayer]; unset($this->plugin->storage->choosenBlock[$arenaPlayer]); } DisguiseAPI::disguiseToAll($arenaPlayer, $block->getID()); $arenaPlayer->teleport($arena->hidersWarp); $blockCount = Item::get(5); $blockCount->setDurability($block->getMaxDurability()); $arenaPlayer . getInventory()->setItem(8, $blockCount); $arenaPlayer . getInventory()->setArmorItem(0, $block); $this->plugin->storage->pBlock[$arenaPlayer] = $block; if ($block . getDurability() != 0) { MessageM::sendFMessage($arenaPlayer, "%TAG%NYou're disguised as a(n) '%A%block%%N' block.", "block-" . block . getType()->name() . replaceAll("_", "") . replaceAll("BLOCK", "") . toLowerCase() . ":" . block . getDurability()); } else { MessageM . sendFMessage($arenaPlayer, $this->plugin->storage->message->get("normal")["ingameBlock"], "block-" . $block . getType()->name() . replaceAll("_", "") . replaceAll("BLOCK", "") . toLowerCase()); } } } } } } foreach ($arena->seekers as $player) { if ($player->getInventory()->getItem(0) == null || $player->getInventory()->getItem(0)->getID() != Item::DIAMOND_SWORD) { $player->getInventory() . setItem(0, Item::DIAMOND_SWORD); $player->getInventory() . setArmorItem(0, Item::IRON_HELMET); $player->getInventory() . setArmorItem(1, Item::IRON_CHESTPLATE); $player->getInventory() . setArmorItem(2, Item::IRON_LEGGINGS); $player->getInventory() . setArmorItem(3, Item::IRON_BOOTS); //$player->playSound(player.getLocation(), Sound.ANVIL_USE, 1, 1); } if ($this->plugin->storage->seekertime[$player] != null) { $this->plugin->storage->seekertime[$player] -= 1; if ($this->plugin->storage->seekertime[$player] <= 0) { $player->teleport($arena->hidersWarp); unset($this->plugin->storage->seekertime[$player]); ArenaHandler::sendFMessage(arena, $this->plugin->storage->message->get("normal")["ingameSeekerSpawned"], "playername-" . player . getName()); } } } if ($arena->gameState == ArenaState::INGAME) { $arena->timer -= 1; if ($arena->timer > 0) { if ($arena->timer == $arena->gameTime - $arena->timeUntilHidersSword) { $sword = Item::WOOD_SWORD; //$sword->addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); foreach ($arena->playersInArena as $arenaPlayer) { if (!in_array($arenaPlayer, $arena->seekers)) { $arenaPlayer->getInventory()->addItem($sword); MessageM . sendFMessage($arenaPlayer, $this->plugin->storage->message->get("normal")["ingameGivenSword"]); } } } if ($arena->timer == 190) { ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-190"); } else { if ($arena->timer == 60) { ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-60"); } else { if ($arena->timer == 30) { ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-30"); } else { if ($arena->timer == 10) { ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-10"); } else { if ($arena->timer == 5) { //$arena->lobbyWarp.getWorld().playSound($arena->lobbyWarp, Sound.ORB_PICKUP, 1, 0); ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-5"); } else { if ($arena->timer == 4) { //$arena->lobbyWarp.getWorld().playSound($arena->lobbyWarp, Sound.ORB_PICKUP, 1, 0); ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-4"); } else { if ($arena->timer == 3) { //$arena->lobbyWarp.getWorld().playSound($arena->lobbyWarp, Sound.ORB_PICKUP, 1, 1); ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-3"); } else { if ($arena->timer == 2) { //$arena->lobbyWarp.getWorld().playSound($arena->lobbyWarp, Sound.ORB_PICKUP, 1, 1); ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-2"); } else { if ($arena->timer == 1) { $arena->lobbyWarp . getWorld() . playSound($arena->lobbyWarp, Sound . ORB_PICKUP, 1, 2); ArenaHandler::sendFMessage($arena, $this->plugin->storage->message->get("normal")["ingameArenaEnd"], "1-1"); } } } } } } } } } } else { ArenaHandler::hidersWin(arena); return; } foreach ($arena->playersInArena as $arenaPlayer) { if (!$arena->seekers . contains($arenaPlayer)) { $pLoc = new Position($arenaPlayer->getX() - 0.5, $arenaPlayer->getY(), $arenaPlayer->getZ() - 0.5, $arenaPlayer->getLevel()); $moveLoc = $this->plugin->storage->moveLoc[$arenaPlayer]; $block = $arenaPlayer->getInventory()->getItem(8); if ($block == null && $this->plugin->storage->pBlock[$arenaPlayer] != null) { $block = $this->plugin->storage->pBlock[$arenaPlayer]; $arenaPlayer->getInventory()->setItem(8, $block); } if ($moveLoc != null) { if ($moveLoc->getX() == $pLoc->getX() && $moveLoc->getY() == $pLoc->getY() && $moveLoc->getZ() == $pLoc->getZ()) { if ($block->getSize() > 1) { $block->setAmount($block->getSize() - 1); } else { $pBlock = $player->getLocation()->getBlock(); if ($pBlock->getType()->equals(Item::AIR) || $pBlock->getType()->equals(Item::WATER) || $pBlock->getType()->equals(Block::STILL_WATER)) { if ($pBlock->getType()->equals(Item::WATER) || $pBlock->getType()->equals(Item::STATIONARY_WATER)) { $this->plugin->storage->hiddenLocWater . put($player, true); } else { $this->plugin->storage->hiddenLocWater . put($player, false); } $arrayOfPlayer = array(); if (DisguiseAPI . isDisguised($player)) { DisguiseAPI . undisguiseToAll(player); $j = count($arrayOfPlayer = $this->plugin->getServer()->getgetOnlinePlayers()); for ($i = 0; $i < $j; $i++) { $pl = $arrayOfPlayer[$i]; if ($pl->getID() != $player->getID()) { $pl->hidePlayer($player); $pl->sendBlockChange($pBlock->getLocation(), $block->getType(), $block->getDurability()); } } //$block->addUnsafeEnchantment(Enchantment::DURABILITY, 10); //$player->playSound($pLoc, Sound.ORB_PICKUP, 1, 1); $this->plugin->storage->hiddenLoc[$player] = $moveLoc; MessageM . sendFMessage($player, $this->plugin->storage->message->get("normal")["ingameNowSolid"], $block->toString()); } $j = count($arrayOfPlayer = $this->plugin->getServer()->getgetOnlinePlayers()); for ($i = 0; $i < $j; $i++) { $pl = $arrayOfPlayer[$i]; if ($pl->getID() != $player->getID()) { $pl->hidePlayer($player); $pl->sendBlockChange($pBlock->getLocation(), $block->getType(), $block->getDurability()); } } } else { MessageM . sendFMessage($player, ConfigC::warning_ingameNoSolidPlace, ""); } } } else { $block->setAmount(5); if (!DisguiseAPI::isDisguised($player)) { SolidBlockHandler::makePlayerUnsolid($player); } } } } } } foreach ($arena->playersInArena as $arenaPlayer) { $arenaPlayer->setLevel($arena->timer); $arenaPlayer->setGameMode(0); } //ScoreboardHandler::updateScoreboard($arena); } $this->plugin->signsHandler->updateSigns(); } }
function processMessage() { $skip = false; $data = $this->telegramBot->getData(); $this->debug($data); $bot_name = $this->config['TLG_BOTNAME']; $text = $this->telegramBot->Text(); $callback = $this->telegramBot->Callback_Data(); if ($callback) { $chat_id = $data["callback_query"]["from"]["id"]; $username = $data["callback_query"]["message"]["chat"]["username"]; $fullname = $data["callback_query"]["from"]["first_name"] . ' ' . $data["callback_query"]["from"]["last_name"]; } else { $chat_id = $this->telegramBot->ChatID(); $username = $this->telegramBot->Username(); $fullname = $this->telegramBot->FirstName() . ' ' . $this->telegramBot->LastName(); } // поиск в базе пользователя $user = SQLSelectOne("SELECT * FROM tlg_user WHERE USER_ID LIKE '" . DBSafe($chat_id) . "';"); if ($chat_id < 0 && substr($text, 0, strlen('@' . $bot_name)) === '@' . $bot_name) { $this->debug("Direct message to bot: " . $bot_name . " ({$text})"); $text = str_replace('@' . $bot_name, '', $text); $source_user = SQLSelectOne("SELECT * FROM tlg_user WHERE TRIM(NAME) LIKE '" . DBSafe(trim($username)) . "'"); if ($source_user['ID']) { $user = $source_user; $this->debug("New user check: " . serialize($user)); } else { $this->debug("Cannot find user: "******"Chatid: " . $chat_id . "; Bot-name: " . $bot_name . "; Message: " . $text); } if ($text == "/start" || $text == "/start@" . $bot_name) { // если нет добавляем if (!$user['ID']) { $user['USER_ID'] = $chat_id; $user['CREATED'] = date('Y/m/d H:i:s'); $user['ID'] = SQLInsert('tlg_user', $user); $this->log("Added new user: "******" - " . $chat_id); } $reply = "Вы зарегистрированы! Обратитесь к администратору для получения доступа к функциям."; $content = array('chat_id' => $chat_id, 'text' => $reply); $this->sendContent($content); $this->updateInfo($user); return; } // пользователь не найден if (!$user['ID']) { $this->debug("Unknow user: "******"; Message: " . $text); return; } $document = $this->telegramBot->Document(); $audio = $this->telegramBot->Audio(); $video = $this->telegramBot->Video(); $voice = $this->telegramBot->Voice(); $sticker = $this->telegramBot->Sticker(); $photo_id = $this->telegramBot->PhotoIdBigSize(); $location = $this->telegramBot->Location(); if ($callback) { $cbm = $this->telegramBot->Callback_Message(); $message_id = $cbm["message_id"]; // get events for callback $events = SQLSelect("SELECT * FROM tlg_event WHERE TYPE_EVENT=9 and ENABLE=1;"); foreach ($events as $event) { if ($event['CODE']) { $this->log("Execute code event " . $event['TITLE']); try { eval($event['CODE']); } catch (Exception $e) { registerError('telegram', sprintf('Exception in "%s" method ' . $e->getMessage(), $text)); } } if ($skip) { $this->log("Skip next processing events callback"); break; } } return; } if ($location) { $latitude = $location["latitude"]; $longitude = $location["longitude"]; $this->log("Get location from " . $chat_id . " - " . $latitude . "," . $longitude); if ($user['MEMBER_ID']) { $sqlQuery = "SELECT * FROM users WHERE ID = '" . $user['MEMBER_ID'] . "'"; $userObj = SQLSelectOne($sqlQuery); if ($userObj['LINKED_OBJECT']) { $this->log("Update location to user '" . $userObj['LINKED_OBJECT'] . "'"); setGlobal($userObj['LINKED_OBJECT'] . '.Coordinates', $latitude . ',' . $longitude); setGlobal($userObj['LINKED_OBJECT'] . '.CoordinatesUpdated', date('H:i')); setGlobal($userObj['LINKED_OBJECT'] . '.CoordinatesUpdatedTimestamp', time()); } } // get events for location $events = SQLSelect("SELECT * FROM tlg_event WHERE TYPE_EVENT=8 and ENABLE=1;"); foreach ($events as $event) { if ($event['CODE']) { $this->log("Execute code event " . $event['TITLE']); try { eval($event['CODE']); } catch (Exception $e) { registerError('telegram', sprintf('Exception in "%s" method ' . $e->getMessage(), $text)); } } if ($skip) { $this->log("Skip next processing events location"); break; } } return; } //permission download file if ($user['DOWNLOAD'] == 1) { $type = 0; //папку с файлами в настройках $storage = $this->config['TLG_STORAGE'] . DIRECTORY_SEPARATOR; if ($photo_id) { $file = $this->telegramBot->getFile($photo_id); $this->log("Get photo from " . $chat_id . " - " . $file["result"]["file_path"]); $file_path = $storage . $chat_id . DIRECTORY_SEPARATOR . $file["result"]["file_path"]; $type = 2; } if ($document) { $file = $this->telegramBot->getFile($document["file_id"]); $this->log("Get document from " . $chat_id . " - " . $document["file_name"]); //print_r($file); if (!isset($file['error_code'])) { $file_path = $storage . $chat_id . DIRECTORY_SEPARATOR . "document" . DIRECTORY_SEPARATOR . $document["file_name"]; if (file_exists($file_path)) { $file_path = $storage . $chat_id . DIRECTORY_SEPARATOR . "document" . DIRECTORY_SEPARATOR . $this->telegramBot->UpdateID() . "_" . $document["file_name"]; } } else { $file_path = ""; $this->log($file['description']); } $type = 6; } if ($audio) { $file = $this->telegramBot->getFile($audio["file_id"]); //print_r($file); $this->log("Get audio from " . $chat_id . " - " . $file["result"]["file_path"]); $path_parts = pathinfo($file["result"]["file_path"]); $filename = $path_parts["basename"]; //use title and performer if (isset($audio['title'])) { $filename = $audio['title'] . "." . $path_parts['extension']; } if (isset($audio['performer'])) { $filename = $audio['performer'] . "-" . $filename; } $file_path = $storage . $chat_id . DIRECTORY_SEPARATOR . "audio" . DIRECTORY_SEPARATOR . $filename; $type = 4; } if ($voice) { $file = $this->telegramBot->getFile($voice["file_id"]); //print_r($file); $this->log("Get voice from " . $chat_id . " - " . $file["result"]["file_path"]); $file_path = $storage . $chat_id . DIRECTORY_SEPARATOR . $file["result"]["file_path"]; $type = 3; } if ($video) { $file = $this->telegramBot->getFile($video["file_id"]); //print_r($file); $this->log("Get video from " . $chat_id . " - " . $file["result"]["file_path"]); $file_path = $storage . $chat_id . DIRECTORY_SEPARATOR . $file["result"]["file_path"]; $type = 5; } if ($sticker) { $file = $this->telegramBot->getFile($sticker["file_id"]); $this->log("Get sticker from " . $chat_id . " - " . $sticker["file_id"]); $file_path = $storage . 'stickers' . DIRECTORY_SEPARATOR . $file["result"]["file_path"]; $sticker_id = $sticker["file_id"]; $type = 7; } if ($file_path) { // качаем файл $path_parts = pathinfo($file_path); if (!is_dir($path_parts['dirname'])) { mkdir($path_parts['dirname'], 0777, true); } $this->telegramBot->downloadFile($file["result"]["file_path"], $file_path); } if ($voice && $user['PLAY'] == 1) { //проиграть голосовое сообщение $this->log("Play voice from " . $chat_id . " - " . $file_path); @touch($file_path); playSound($file_path, 1, $level); } if ($file_path || $sticker_id) { // get events $events = SQLSelect("SELECT * FROM tlg_event WHERE TYPE_EVENT=" . $type . " and ENABLE=1;"); foreach ($events as $event) { if ($event['CODE']) { $this->log("Execute code event " . $event['TITLE']); try { eval($event['CODE']); } catch (Exception $e) { registerError('telegram', sprintf('Exception in "%s" method ' . $e->getMessage(), $text)); } } if ($skip) { $this->log("Skip next processing events type = " . $type); break; } } } $file_path = ""; } if ($text == "") { return; } $this->log($chat_id . " (" . $username . ", " . $fullname . ")=" . $text); // get events for text message $events = SQLSelect("SELECT * FROM tlg_event WHERE TYPE_EVENT=1 and ENABLE=1;"); foreach ($events as $event) { if ($event['CODE']) { $this->log("Execute code event " . $event['TITLE']); try { eval($event['CODE']); } catch (Exception $e) { registerError('telegram', sprintf('Exception in "%s" method ' . $e->getMessage(), $text)); } } if ($skip) { $this->log("Skip next processing events message"); break; } } // пропуск дальнейшей обработки если с обработчике событий установили $skip if ($skip) { $this->log("Skip next processing message"); return; } if ($user['ID']) { //смотрим разрешения на обработку команд if ($user['CMD'] == 1) { $sql = "SELECT * FROM tlg_cmd where '" . DBSafe($text) . "' LIKE CONCAT(tlg_cmd.TITLE,'%') and (ACCESS=3 OR ((select count(*) from tlg_user_cmd where tlg_user_cmd.USER_ID=" . $user['ID'] . " and tlg_cmd.ID=tlg_user_cmd.CMD_ID)>0 and ACCESS>0))"; //$this->debug($sql); $cmd = SQLSelectOne($sql); if ($cmd['ID']) { $this->log("Find command"); //нашли команду if ($cmd['CODE']) { $this->log("Execute user`s code command"); try { $success = eval($cmd['CODE']); $this->log("Command:" . $text . " Result:" . $success); if ($success == false) { //нет в выполняемом куске кода return //$content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Ошибка выполнения кода команды ".$text); //$this->telegramBot->sendMessage($content); } else { $keyb = $this->getKeyb($user); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => $success, 'parse_mode' => 'HTML'); $this->sendContent($content); $this->log("Send result to " . $chat_id . ". Command:" . $text . " Result:" . $success); } } catch (Exception $e) { registerError('telegram', sprintf('Exception in "%s" method ' . $e->getMessage(), $text)); $keyb = $this->getKeyb($user); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Ошибка выполнения кода команды " . $text); $this->sendContent($content); } return; } // если нет кода, который надо выполнить, то передаем дальше на обработку } else { $this->log("Command not found"); } } if ($user['PATTERNS'] == 1) { say(htmlspecialchars($text), 0, $user['MEMBER_ID'], 'telegram' . $user['ID']); } } }