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

11
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'); require_once(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'init.php');
//load plugins //load plugins
$load_plugins = glob(PATH.'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 == PATH.'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) {
$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; require_once $value;
break;
} }
}
require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php'; require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
?> ?>

View File

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

View File

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

View File

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

View File

@ -1,6 +1,10 @@
<?php <?php
PluginList("help", "Ask for help");
if (preg_match("/^".preg_quote(TAG, '/')."help$/", $text)) { 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"; $plugin_list = HELP_BEGIN."\n";
foreach ($plugins as $value) { foreach ($plugins as $value) {
$plugin_list .= "\n".$value; $plugin_list .= "\n".$value;

View File

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

View File

@ -1,7 +1,6 @@
<?php <?php
PluginList("trans", "translate"); PluginSet("translate");
if (preg_match("/^".preg_quote(TAG, '/')."trans (.*)$/", $text, $matches)) { $matches = explode(" ", $plugin_text, 2);
$matches = explode(" ", $matches[1], 2);
if (!isset($matches[1])) { if (!isset($matches[1])) {
$to = "en"; $to = "en";
$text = urlencode($matches[0]); $text = urlencode($matches[0]);
@ -16,5 +15,3 @@ if (preg_match("/^".preg_quote(TAG, '/')."trans (.*)$/", $text, $matches)) {
preg_match("/\[{.*?\}]/is", $trans, $trans_json); preg_match("/\[{.*?\}]/is", $trans, $trans_json);
$msg = "Result: ".json_decode($trans_json[0],true)[0]["TranslatedText"]; $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 <?php
PluginList("tts", "Text To Speech"); PluginSet("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($plugin_text));
$mp3 = file_get_contents("http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=".urlencode($matches[1]));
$file = fopen($from.".mp3","w"); $file = fopen($from.".mp3","w");
echo fwrite($file,$mp3); echo fwrite($file,$mp3);
fclose($file); fclose($file);
$BOT->send_audio($from, "/home/wwwroot/1.vps.dennx.com/".$from.".mp3"); $BOT->send_audio($from, "/home/wwwroot/1.vps.dennx.com/".$from.".mp3");
//unlink($matches[1].".mp3"); //unlink($matches[1].".mp3");
}