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
require('classes/Telegram/Base.php');
$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
namespace DBot\Telegram;
class Base
{
protected $_fp;
@ -12,17 +11,13 @@ class Base
}
stream_set_timeout($this->_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;
}
}
}

View File

@ -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';
}

View File

@ -1,6 +1,7 @@
<?php
define('PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('TAG', '#');
define('OWNER_NAME', 'Denny Dai');
define('BOT_NAME', 'Dx. Dennx');
define('HELP_BEGIN', "Welcome to use TG-BOT");
define('HELP_END', "GitHub: https://github.com/dennydai/D-bot\nAuthor: @DennyDai");
define('HELP_END', "GitHub: https://github.com/dennydai/D-bot\nAuthor: @DennyDai");

View File

@ -1,5 +1,5 @@
<?php
PluginList("echo", "Echo what you typed.");
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];
$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));
}