usage: msg($peer, $text)

This commit is contained in:
Denny Dai 2015-06-26 13:59:37 +08:00
parent fce895bb21
commit c3ada33e3b
6 changed files with 20 additions and 5 deletions

View File

@ -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) {

View File

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

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." ".escapeString($matches[1]));
$BOT->msg($from, $matches[1]);
}

View File

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

View File

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

View File

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