Bot Api Version

Bot Api Version
This commit is contained in:
Denny Dai 2015-06-29 22:13:58 +08:00
parent 1ab6510772
commit e321324785
5 changed files with 46 additions and 3 deletions

View File

@ -5,8 +5,6 @@ require_once('functions.php');
$plugins = []; $plugins = [];
require(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'Base.php'); require(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'Base.php');
$BOT = new DBot\Base('unix:///tmp/tg.sck');
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

View File

@ -0,0 +1,26 @@
<?php
namespace DBot;
class Base
{
public function exec($command, $data = null)
{
$context = array();
if (is_array($data))
{
$opts = array (
'http' => array (
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded",
'content' => http_build_query($data)
)
);
$context = stream_context_create($opts);
}
return file_get_contents(TB_API_URL.$command, false, $context);
}
public function msg($id, $msg)
{
return $this->exec('sendMessage', array('chat_id' => $id, 'text' => $msg));
}
}

View File

@ -0,0 +1,14 @@
<?php
$BOT = new DBot\Base;
$GET = json_decode(file_get_contents("php://input"),true);
//is group?
if ($GET['message']['chat']['id'] > 0) {
$isgroup = false;
}else{
$isgroup = true;
}
//reply to...
$from = $GET['message']['chat']['id'];
$text = $GET['message']['text'];

View File

@ -1,5 +1,5 @@
<?php <?php
$BOT = new DBot\Base('unix:///tmp/tg.sck');
if($_GET['from'] != escapePeer(BOT_NAME)){ if($_GET['from'] != escapePeer(BOT_NAME)){
//is group? //is group?
if ($_GET['to'] == escapePeer(BOT_NAME)) { if ($_GET['to'] == escapePeer(BOT_NAME)) {

View File

@ -6,3 +6,8 @@ define('OWNER_NAME', 'Denny Dai');
define('BOT_NAME', 'Dx. Dennx'); define('BOT_NAME', 'Dx. Dennx');
define('HELP_BEGIN', "Welcome to use TG-BOT"); define('HELP_BEGIN', "Welcome to use TG-BOT");
define('HELP_END', "GitHub: https://github.com/dennydai/D-bot\nAuthor: @DennyDai"); define('HELP_END', "GitHub: https://github.com/dennydai/D-bot\nAuthor: @DennyDai");
//For Telegram-Bot
define('TB_TOKEN', '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11');
define('TB_API_URL', 'https://api.telegram.org/bot'.TB_TOKEN.'/');