From 88c6a081ddcc157d55dcce30a53e87a89ba13865 Mon Sep 17 00:00:00 2001 From: Denny Dai Date: Fri, 26 Jun 2015 13:19:40 +0800 Subject: [PATCH] too tired to desc too tired to desc --- BOT.php | 2 +- classes/Telegram/Base.php | 8 +------- init.php => classes/Telegram/init.php | 6 +++--- config.inc.php | 3 ++- plugins/echo.php | 2 +- plugins/trans.php | 6 +++--- 6 files changed, 11 insertions(+), 16 deletions(-) rename init.php => classes/Telegram/init.php (65%) diff --git a/BOT.php b/BOT.php index 0430e9c..219f1ff 100644 --- a/BOT.php +++ b/BOT.php @@ -2,5 +2,5 @@ //init require('classes/Telegram/Base.php'); $BOT = new DBot\Telegram\Base('unix:///tmp/tg.sck'); -require_once('init.php'); +require_once('classes/Telegram/init.php'); ?> \ No newline at end of file diff --git a/classes/Telegram/Base.php b/classes/Telegram/Base.php index 5a0bc8f..5d158cf 100644 --- a/classes/Telegram/Base.php +++ b/classes/Telegram/Base.php @@ -1,6 +1,5 @@ _fp, 1); } - public function __destruct() { fclose($this->_fp); } - - public function exec($command) { fwrite($this->_fp, str_replace("\n", '\n', $command) . PHP_EOL); - $answer = fgets($this->_fp); if (is_string($answer)) { if (substr($answer, 0, 7) === 'ANSWER ') { @@ -35,7 +30,6 @@ class Base return true; } } - return false; } -} +} \ No newline at end of file diff --git a/init.php b/classes/Telegram/init.php similarity index 65% rename from init.php rename to classes/Telegram/init.php index b3d7619..1c743a0 100644 --- a/init.php +++ b/classes/Telegram/init.php @@ -21,14 +21,14 @@ if($_GET['from'] != escapePeer(BOT_NAME)){ } //load plugins - $load_plugins = glob(dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'*.php'); + $load_plugins = glob(PATH.'plugins'.DIRECTORY_SEPARATOR.'*.php'); foreach ($load_plugins as $key => $value) { - if ($value == dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'help.php') { + if ($value == PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php') { unset($load_plugins[$key]); } } foreach ($load_plugins as $value) { require_once $value; } - require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'help.php'; + require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php'; } \ No newline at end of file diff --git a/config.inc.php b/config.inc.php index e2f1473..917dcf2 100644 --- a/config.inc.php +++ b/config.inc.php @@ -1,6 +1,7 @@ exec("msg ".$from." ".$matches[1]); + $BOT->exec("msg ".$from." ".escapeString($matches[1])); } \ No newline at end of file diff --git a/plugins/trans.php b/plugins/trans.php index aa75f0c..b633a5b 100644 --- a/plugins/trans.php +++ b/plugins/trans.php @@ -12,9 +12,9 @@ if (preg_match("/^".TAG."trans (.*)$/", $_GET['text'], $matches)) { $to = $matches[0]; $text = urlencode($matches[1]); } - $trans = file_get_contents('http://api.microsofttranslator.com/v2/ajax.svc/TranslateArray2?appId=%22TKT68kjRgkUbVtIKst6Vo0Hxnb6g2f0K3tUMyn1gZ7nc*%22&to="'.$to.'"&options={}&texts=["'.$text.'"]'); - preg_match('/"TranslatedText":"([^"]+)/i', $trans, $trans_result); - $msg = "Result: ".$trans_result[1]; + $trans = file_get_contents('http://api.microsofttranslator.com/v2/ajax.svc/TranslateArray2?appId=%22TWQET6TO9c7Iw1yXOahFm8zfEzty5DUHuaTHkl5SCrHUPgu3ABP7aflbz8teet6IS%22&to="'.$to.'"&options={}&texts=["'.$text.'"]'); + preg_match("/\[{.*?\}]/is", $trans, $trans_json); + $msg = "Result: ".json_decode($trans_json[0],true)[0]["TranslatedText"]; $BOT->exec("msg ".$from." ".escapeString($msg)); } \ No newline at end of file