Bot Api Version
Bot Api Version
This commit is contained in:
parent
1ab6510772
commit
e321324785
2
BOT.php
2
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
|
||||
|
26
classes/Telegram-Bot/Base.php
Normal file
26
classes/Telegram-Bot/Base.php
Normal 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));
|
||||
}
|
||||
}
|
||||
|
14
classes/Telegram-Bot/init.php
Normal file
14
classes/Telegram-Bot/init.php
Normal 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'];
|
@ -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)) {
|
||||
|
@ -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.'/');
|
Loading…
Reference in New Issue
Block a user