remove outdated class, and merge functions file

This commit is contained in:
dennydai 2016-01-01 22:56:39 +08:00
parent bf791fa8f0
commit 634b0390ab
5 changed files with 52 additions and 136 deletions

View File

@ -2,38 +2,40 @@
//init
$Pre_Type = $_SERVER['QUERY_STRING'];
require_once('config.php');
require_once('functions.php');
$plugins = array();
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]);
$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 ($TAGs as $TAG) {
foreach ($load_plugins as $value) {
$plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4);
if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}elseif (preg_match("/^(".preg_quote($TAG, '/').$plugin_name.")|(".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.")$/", $text)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}
}
foreach ($TAGs as $TAG) {
foreach ($load_plugins as $value) {
$plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4);
if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}elseif (preg_match("/^(".preg_quote($TAG, '/').$plugin_name.")|(".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.")$/", $text)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}
}
}
require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
}
require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
//function
function PluginSet($desc){
global $plugins,$plugin_name,$TAG;
$plugins[] .= $TAG.$plugin_name." ".$desc;
}
?>

View File

@ -2,38 +2,40 @@
//init
$Pre_Type = substr(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/')+1), 0, -4);
require_once('config.php');
require_once('functions.php');
$plugins = array();
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]);
$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 ($TAGs as $TAG) {
foreach ($load_plugins as $value) {
$plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4);
if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}elseif (preg_match("/^(".preg_quote($TAG, '/').$plugin_name.")|(".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.")$/", $text)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}
}
foreach ($TAGs as $TAG) {
foreach ($load_plugins as $value) {
$plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4);
if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}elseif (preg_match("/^(".preg_quote($TAG, '/').$plugin_name.")|(".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.")$/", $text)) {
$plugin_text = $matches[2];
$plugin_sendto = $from;
require_once $value;
break;
}
}
}
require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
}
require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php';
//function
function PluginSet($desc){
global $plugins,$plugin_name,$TAG;
$plugins[] .= $TAG.$plugin_name." ".$desc;
}
?>

View File

@ -1,55 +0,0 @@
<?php
class Base
{
protected $_fp;
public function __construct($Socket)
{
$this->_fp = stream_socket_client($Socket);
if ($this->_fp === false) {
throw new ClientException('Could not connect to socket "' . $Socket . '"');
}
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 ') {
$bytes = (int) substr($answer, 7);
if ($bytes > 0) {
$Response = trim(fread($this->_fp, $bytes + 1));
return $Response;
}
}elseif ($answer === PHP_EOL) {
return true;
}
}
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);
}
public function send_audio($peer, $file)
{
$peer = $this->escapePeer($peer);
return $this->exec('send_audio ' . $peer . ' ' . $file);
}
}

View File

@ -1,20 +0,0 @@
<?php
$BOT = new Base('unix:///tmp/tg.sck');
if($_GET['from'] != escapePeer(BOT_NAME)){
//is group?
if ($_GET['to'] == escapePeer(BOT_NAME)) {
$isgroup = false;
}else{
$isgroup = true;
}
//reply to...
if ($isgroup) {
$from = $_GET['to'];
}else{
$from = $_GET['from'];
$BOT->exec("msg ".escapePeer(OWNER_NAME)." ".json_encode($_GET));
}
$text = $_GET['text'];
}

View File

@ -1,13 +0,0 @@
<?php
function escapeString($var){
return '"' . addslashes($var) . '"';
}
function escapePeer($peer){
return str_replace(' ', '_', $peer);
}
function PluginSet($desc){
global $plugins,$plugin_name,$TAG;
$plugins[] .= $TAG.$plugin_name." ".$desc;
}