too tired to desc

too tired to desc
This commit is contained in:
Denny Dai 2015-06-26 13:19:40 +08:00
parent 72a36e5164
commit 88c6a081dd
6 changed files with 11 additions and 16 deletions

View File

@ -2,5 +2,5 @@
//init //init
require('classes/Telegram/Base.php'); require('classes/Telegram/Base.php');
$BOT = new DBot\Telegram\Base('unix:///tmp/tg.sck'); $BOT = new DBot\Telegram\Base('unix:///tmp/tg.sck');
require_once('init.php'); require_once('classes/Telegram/init.php');
?> ?>

View File

@ -1,6 +1,5 @@
<?php <?php
namespace DBot\Telegram; namespace DBot\Telegram;
class Base class Base
{ {
protected $_fp; protected $_fp;
@ -12,17 +11,13 @@ class Base
} }
stream_set_timeout($this->_fp, 1); stream_set_timeout($this->_fp, 1);
} }
public function __destruct() public function __destruct()
{ {
fclose($this->_fp); fclose($this->_fp);
} }
public function exec($command) public function exec($command)
{ {
fwrite($this->_fp, str_replace("\n", '\n', $command) . PHP_EOL); fwrite($this->_fp, str_replace("\n", '\n', $command) . PHP_EOL);
$answer = fgets($this->_fp); $answer = fgets($this->_fp);
if (is_string($answer)) { if (is_string($answer)) {
if (substr($answer, 0, 7) === 'ANSWER ') { if (substr($answer, 0, 7) === 'ANSWER ') {
@ -35,7 +30,6 @@ class Base
return true; return true;
} }
} }
return false; return false;
} }
} }

View File

@ -21,14 +21,14 @@ if($_GET['from'] != escapePeer(BOT_NAME)){
} }
//load plugins //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) { 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]); unset($load_plugins[$key]);
} }
} }
foreach ($load_plugins as $value) { foreach ($load_plugins as $value) {
require_once $value; require_once $value;
} }
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'help.php'; require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
define('PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('TAG', '#'); define('TAG', '#');
define('OWNER_NAME', 'Denny Dai'); define('OWNER_NAME', 'Denny Dai');
define('BOT_NAME', 'Dx. Dennx'); define('BOT_NAME', 'Dx. Dennx');

View File

@ -1,5 +1,5 @@
<?php <?php
PluginList("echo", "Echo what you typed."); PluginList("echo", "Echo what you typed.");
if (preg_match("/^".TAG."echo (.*)$/", $_GET['text'], $matches)) { if (preg_match("/^".TAG."echo (.*)$/", $_GET['text'], $matches)) {
$BOT->exec("msg ".$from." ".$matches[1]); $BOT->exec("msg ".$from." ".escapeString($matches[1]));
} }

View File

@ -12,9 +12,9 @@ if (preg_match("/^".TAG."trans (.*)$/", $_GET['text'], $matches)) {
$to = $matches[0]; $to = $matches[0];
$text = urlencode($matches[1]); $text = urlencode($matches[1]);
} }
$trans = file_get_contents('http://api.microsofttranslator.com/v2/ajax.svc/TranslateArray2?appId=%22TKT68kjRgkUbVtIKst6Vo0Hxnb6g2f0K3tUMyn1gZ7nc*%22&to="'.$to.'"&options={}&texts=["'.$text.'"]'); $trans = file_get_contents('http://api.microsofttranslator.com/v2/ajax.svc/TranslateArray2?appId=%22TWQET6TO9c7Iw1yXOahFm8zfEzty5DUHuaTHkl5SCrHUPgu3ABP7aflbz8teet6IS%22&to="'.$to.'"&options={}&texts=["'.$text.'"]');
preg_match('/"TranslatedText":"([^"]+)/i', $trans, $trans_result); preg_match("/\[{.*?\}]/is", $trans, $trans_json);
$msg = "Result: ".$trans_result[1]; $msg = "Result: ".json_decode($trans_json[0],true)[0]["TranslatedText"];
$BOT->exec("msg ".$from." ".escapeString($msg)); $BOT->exec("msg ".$from." ".escapeString($msg));
} }