Big Change about Plugins

This commit is contained in:
Denny Dai 2015-06-30 15:05:22 +08:00
parent 3cc20a8a89
commit f94b5403f4
8 changed files with 38 additions and 32 deletions

13
BOT.php
View File

@ -8,15 +8,26 @@ require(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'Base.php');
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) {
if ($value == PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php') {
unset($load_plugins[$key]);
}
}
foreach ($load_plugins as $value) {
require_once $value;
$plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4);
if (preg_match("/^".preg_quote(TAG, '/').$plugin_name." (.*)$/", $text, $matches)) {
$plugin_text = $matches[1];
$plugin_sendto = $from;
require_once $value;
break;
}
}
require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
?>

View File

@ -1,5 +1,5 @@
<?php
define('TYPE', 'Telegram');
define('TYPE', 'Telegram-Bot');
define('PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('TAG', '#');
define('OWNER_NAME', 'Denny Dai');

View File

@ -7,7 +7,7 @@ function escapePeer($peer){
return str_replace(' ', '_', $peer);
}
function PluginList($commands, $name){
global $plugins;
$plugins[] .= TAG.$commands." ".$name;
function PluginSet($desc){
global $plugins,$plugin_name;
$plugins[] .= TAG.$plugin_name." ".$desc;
}

View File

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

View File

@ -1,6 +1,10 @@
<?php
PluginList("help", "Ask for help");
if (preg_match("/^".preg_quote(TAG, '/')."help$/", $text)) {
foreach ($load_plugins as $value) {
$plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4);
$lines=file($value);
eval($lines[1]);
}
$plugin_list = HELP_BEGIN."\n";
foreach ($plugins as $value) {
$plugin_list .= "\n".$value;

View File

@ -1,12 +1,10 @@
<?php
PluginList("ipto", "Change the form of IP address");
if (preg_match("/^".preg_quote(TAG, '/')."ipto (.*)$/", $text, $matches)) {
$arr = explode('.',$matches[1]);
$msg = 'IP: '.$arr[0].'.'.$arr[1].'.'.$arr[2].'.'.$arr[3];
$msg .= "\nint: ".($arr[0] * pow(256,3) + $arr[1] * pow(256,2) + $arr[2] * 256 + $arr[3]);
$msg .= "\noct: 0".decoct($arr[0]).".0".decoct($arr[1]).".0".decoct($arr[2]).'.0'.decoct($arr[3]);
$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->msg($from, $msg);
}
PluginSet("Change the form of IP address");
$arr = explode('.',$plugin_text);
$msg = 'IP: '.$arr[0].'.'.$arr[1].'.'.$arr[2].'.'.$arr[3];
$msg .= "\nint: ".($arr[0] * pow(256,3) + $arr[1] * pow(256,2) + $arr[2] * 256 + $arr[3]);
$msg .= "\noct: 0".decoct($arr[0]).".0".decoct($arr[1]).".0".decoct($arr[2]).'.0'.decoct($arr[3]);
$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->msg($plugin_sendto, $msg);

View File

@ -1,7 +1,6 @@
<?php
PluginList("trans", "translate");
if (preg_match("/^".preg_quote(TAG, '/')."trans (.*)$/", $text, $matches)) {
$matches = explode(" ", $matches[1], 2);
PluginSet("translate");
$matches = explode(" ", $plugin_text, 2);
if (!isset($matches[1])) {
$to = "en";
$text = urlencode($matches[0]);
@ -15,6 +14,4 @@ if (preg_match("/^".preg_quote(TAG, '/')."trans (.*)$/", $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->msg($from, $msg);
}
$BOT->msg($from, $msg);

View File

@ -1,10 +1,8 @@
<?php
PluginList("tts", "Text To Speech");
if (preg_match("/^".preg_quote(TAG, '/')."tts (.*)$/", $text, $matches)) {
$mp3 = file_get_contents("http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=".urlencode($matches[1]));
PluginSet("tts", "Text To Speech");
$mp3 = file_get_contents("http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=".urlencode($plugin_text));
$file = fopen($from.".mp3","w");
echo fwrite($file,$mp3);
fclose($file);
$BOT->send_audio($from, "/home/wwwroot/1.vps.dennx.com/".$from.".mp3");
//unlink($matches[1].".mp3");
}
//unlink($matches[1].".mp3");