diff --git a/BOT.php b/BOT.php index 746ab71..ea7a603 100644 --- a/BOT.php +++ b/BOT.php @@ -5,8 +5,6 @@ require_once('functions.php'); $plugins = []; 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'); //load plugins diff --git a/classes/Telegram-Bot/Base.php b/classes/Telegram-Bot/Base.php new file mode 100644 index 0000000..8e7b5a9 --- /dev/null +++ b/classes/Telegram-Bot/Base.php @@ -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)); + } +} + diff --git a/classes/Telegram-Bot/init.php b/classes/Telegram-Bot/init.php new file mode 100644 index 0000000..cae12db --- /dev/null +++ b/classes/Telegram-Bot/init.php @@ -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']; \ No newline at end of file diff --git a/classes/Telegram/init.php b/classes/Telegram/init.php index 3e4b1e6..ade1636 100644 --- a/classes/Telegram/init.php +++ b/classes/Telegram/init.php @@ -1,5 +1,5 @@ <?php - +$BOT = new DBot\Base('unix:///tmp/tg.sck'); if($_GET['from'] != escapePeer(BOT_NAME)){ //is group? if ($_GET['to'] == escapePeer(BOT_NAME)) { diff --git a/config.php b/config.php index f595baf..ea37cbc 100644 --- a/config.php +++ b/config.php @@ -6,3 +6,8 @@ define('OWNER_NAME', 'Denny Dai'); define('BOT_NAME', 'Dx. Dennx'); define('HELP_BEGIN', "Welcome to use TG-BOT"); 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.'/'); \ No newline at end of file