diff --git a/BOT.php b/BOT.php index b114e09..746ab71 100644 --- a/BOT.php +++ b/BOT.php @@ -9,7 +9,6 @@ $BOT = new DBot\Base('unix:///tmp/tg.sck'); require_once(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'init.php'); - //load plugins $load_plugins = glob(PATH.'plugins'.DIRECTORY_SEPARATOR.'*.php'); foreach ($load_plugins as $key => $value) { diff --git a/classes/Telegram/Base.php b/classes/Telegram/Base.php index 819bfc2..63f60ac 100644 --- a/classes/Telegram/Base.php +++ b/classes/Telegram/Base.php @@ -32,4 +32,20 @@ class Base } return false; } + public function escapeStringArgument($argument) + { + return '"' . addslashes($argument) . '"'; + } + public function escapePeer($peer) + { + return str_replace(' ', '_', $peer); + } + + + public function msg($peer, $msg) + { + $peer = $this->escapePeer($peer); + $msg = $this->escapeStringArgument($msg); + return $this->exec('msg ' . $peer . ' ' . $msg); + } } \ No newline at end of file diff --git a/plugins/echo.php b/plugins/echo.php index 03e8fba..7894a92 100644 --- a/plugins/echo.php +++ b/plugins/echo.php @@ -1,5 +1,5 @@ exec("msg ".$from." ".escapeString($matches[1])); + $BOT->msg($from, $matches[1]); } \ No newline at end of file diff --git a/plugins/help.php b/plugins/help.php index 6b4248f..ba5a2dd 100644 --- a/plugins/help.php +++ b/plugins/help.php @@ -6,5 +6,5 @@ if (preg_match("/^".TAG."help$/", $_GET['text'])) { $plugin_list .= "\n".$value; } $plugin_list .= "\n\n".HELP_END; - $BOT->exec("msg ".$from." ".escapeString($plugin_list)); + $BOT->msg($from, $plugin_list); } \ No newline at end of file diff --git a/plugins/ipto.php b/plugins/ipto.php index 62c2d7f..77e1b4b 100644 --- a/plugins/ipto.php +++ b/plugins/ipto.php @@ -8,5 +8,5 @@ if (preg_match("/^".TAG."ipto (.*)$/", $_GET['text'], $matches)) { $msg .= "\nhex: 0x".dechex($arr[0]).".0x".dechex($arr[1]).".0x".dechex($arr[2]).'.0x'.dechex($arr[3]); $msg .= "\nfucking hex: 0x0000000000".dechex($arr[0]).".0x0000000000".dechex($arr[1]).".0x0000000000".dechex($arr[2]).'.0x0000000000'.dechex($arr[3]); $msg .= "\nYou can combine them with any combination. Such as: 0".decoct($arr[0]).'.0x0000000000'.dechex($arr[1]).'.'.$arr[2].'.0x'.dechex($arr[3]); - $BOT->exec("msg ".$from." ".escapeString($msg)); + $BOT->msg($from, $msg); } \ No newline at end of file diff --git a/plugins/trans.php b/plugins/trans.php index b633a5b..ac634a6 100644 --- a/plugins/trans.php +++ b/plugins/trans.php @@ -15,6 +15,6 @@ if (preg_match("/^".TAG."trans (.*)$/", $_GET['text'], $matches)) { $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)); + $BOT->msg($from, $msg); } \ No newline at end of file