Skip to content

Commit ebe50f0

Browse files
author
Harry
committed
New update
1 parent 33d2509 commit ebe50f0

File tree

10 files changed

+164
-36
lines changed

10 files changed

+164
-36
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "predis"]
2-
path = predis
3-
url = https://github.com/nrk/predis

bot.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
<?php
22
/* Includes */
3-
require "predis/autoload.php";
43
include 'methods.php';
54
$config = include 'config.php';
6-
5+
include 'utils.php';
76
/* Configuraciones */
87
$bot = new api;
9-
$redis = new Predis\Client();
8+
$utils = new utils;
109
$GLOBALS['website'] = "https://api.telegram.org/bot".$config["token"];
10+
$mysqli = new mysqli($config["mysql"]["host"], $config["mysql"]["user"], $config["mysql"]["password"], $config["mysql"]["database"]);
1111

12-
/*---------------------------*/
1312

14-
function mdEscape($text) {
15-
$rep = array('*' => '\\*', '_' => '\\_', '[' => '\\[', '`' => '\\`');
16-
return str_replace(array_keys($rep), array_values($rep), $text);
17-
};
18-
19-
function get_vardump($var) {
20-
ob_start();
21-
var_dump($var);
22-
return ob_get_clean();
23-
};
13+
/*---------------------------*/
2414

2515
$updates = file_get_contents("php://input");
2616
if (!$updates) { return; };
@@ -29,12 +19,18 @@ function get_vardump($var) {
2919
$msg = $updates["message"];
3020
$msg["cb"] = $updates["callback_query"];
3121

22+
if ($mysqli->connect_error) {
23+
if ($config["report_mysql_errors"]) {
24+
$bot->sendMessage($config["owners"][0], "*Error while connecting MySQL*.", "markdown");
25+
};
26+
};
27+
3228
if ($config["var_dump"]) {
33-
$result = get_vardump($msg);
29+
$result = $utils->get_vardump($msg);
3430
if ($result) {
3531
$bot->sendMessage($config["owners"][0], $result);
3632
return;
37-
}
33+
};
3834
};
3935

4036
foreach ($config["plugins"] as $plugin) {

config.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<?php
22
return array(
3-
'token' => "187719141:AAFve8KloiFH6oTSIe3CJ8jlefBJxV15i3k",
3+
'token' => "187719141:AAGQ7eSi-fUdIakA32_J_ebYV9qIzmsHYZg",
44
'var_dump' => false,
55
'owners' => array(
66
189041244
77
),
88
'plugins' => array(
99
"start.php",
10+
"sendfile.php",
11+
"sendinline.php",
1012
"forward.php"
11-
)
13+
),
14+
'mysql' => array(
15+
'host' => 'localhost',
16+
'user' => 'id2316483_root',
17+
'password' => '80568054_gz',
18+
'database' => 'id2316483_telegram'
19+
),
20+
'report_mysql_errors' => true
1221
)
1322
?>

m.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
function a() {
3+
a,b = 1,2;
4+
}
5+
?>

methods.php

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
11
<?php
22

3-
function APIRequest($method) {
3+
function request($method) {
44
$url = $GLOBALS['website']."/".$method;
5-
return json_decode(file_get_contents($url));
6-
};
5+
$content = file_get_contents($url);
6+
return $content;
7+
}
8+
9+
function curl_upload($url, $post) {
10+
$ch = curl_init();
11+
curl_setopt($ch, CURLOPT_URL, $url);
12+
curl_setopt($ch, CURLOPT_POST,1);
13+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
14+
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
15+
$result=curl_exec ($ch);
16+
curl_close ($ch);
17+
return $result;
18+
}
719

820
class api {
921
function sendMessage($chat_id, $message, $parse_mode=NULL, $reply_markup=NULL, $reply_to_message_id=NULL) {
10-
$url = "sendMessage?chat_id=".$chat_id."&text=".urlencode($message);
22+
$method = "sendMessage?chat_id=".$chat_id."&text=".urlencode($message);
1123
if ($parse_mode) {
12-
$url .= "&parse_mode=".$parse_mode;
24+
$method .= "&parse_mode=".$parse_mode;
1325
}
1426
if ($reply_markup) {
15-
$url .= "&reply_markup=".json_encode($reply_markup);
27+
$method .= "&reply_markup=".json_encode($reply_markup);
1628
}
1729
if ($reply_to_message_id) {
18-
$url .= "&reply_to_message_id=".$reply_to_message_id;
30+
$method .= "&reply_to_message_id=".$reply_to_message_id;
1931
}
20-
return APIRequest($url);
32+
return array($method, request($method));
2133
}
2234

2335
function sendReply($msg, $message, $parse_mode=NULL, $reply_markup=NULL) {
2436
return $this->sendMessage($msg["chat"]["id"], $message, $parse_mode, $reply_markup, $msg["message_id"]);
2537
}
38+
39+
function deleteMessage($chat_id, $message_id) {
40+
$method = "deleteMessage?chat_id=".$chat_id."&message_id=".$message_id;
41+
return request($method);
42+
}
43+
44+
function sendDocument($chat_id, $document) {
45+
$url = $GLOBALS['website']."/sendDocument";
46+
$document = realpath($document);
47+
$document = new CURLFile($document);
48+
$post = array("chat_id" => $chat_id, "document" => $document);
49+
return curl_upload($url, $post);
50+
}
51+
52+
function setWebhook($token, $url) {
53+
$req = "https://api.telegram.org/bot".$token."/setWebhook?url=".$url;
54+
return file_get_contents($req);
55+
}
56+
57+
function deleteWebhook($token) {
58+
$req = "https://api.telegram.org/bot".$token."/deleteWebhook";
59+
return file_get_contents($req);
60+
}
2661
};
2762

2863
?>

plugins/forward.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
<?php
22
$pre_process = function ($msg) {
3-
global $bot;
3+
global $bot; global $utils;
4+
if ($msg["chat"]["type"] != "private") { return; };
45
if (isset($msg["forward_from_chat"])) {
5-
$username = $msg["forward_from_chat"]["username"]?"@".mdEscape($msg["forward_from_chat"]["username"]):"";
6+
$username = $msg["forward_from_chat"]["username"]?"@".$utils->nm($msg["forward_from_chat"]["username"]):"";
67
$type = $msg["forward_from_chat"]["type"]?"\n*Type*: ".$msg["forward_from_chat"]["type"]:"";
7-
$bot->sendReply($msg, $username."\n*Id*: ".$msg["forward_from_chat"]["id"]."\n*Title*: ".mdEscape($msg["forward_from_chat"]["title"]).$type, "markdown");
8+
$bot->sendReply($msg, $username."\n*Id*: ".$msg["forward_from_chat"]["id"]."\n*Title*: ".$utils->nm($msg["forward_from_chat"]["title"]).$type, "markdown");
89
return;
910
};
1011

1112
if (isset($msg["forward_from"])) {
1213
$msg["from"] = $msg["forward_from"];
1314
};
1415

15-
if (isset($msg["text"]) && isset($msg["from"])) {
16+
if (isset($msg["from"])) {
1617
$last_name = $msg["from"]["last_name"]?"\n*Last*: ".$msg["from"]["last_name"]:"";
17-
$username = $msg["from"]["username"]?"@".mdEscape($msg["from"]["username"]):"";
18+
$username = $msg["from"]["username"]?"@".$utils->nm($msg["from"]["username"]):"";
1819
$language_code = $msg["from"]["language_code"]?"\n*Lang*: ".$msg["from"]["language_code"]:"";
19-
$bot->sendReply($msg, $username."\n*Id*: ".$msg["from"]["id"]."\n*First*: ".mdEscape($msg["from"]["first_name"]).$last_name.$language_code, "markdown");
20+
$is_bot = $msg["from"]["is_bot"]?"true":"false";
21+
$bot->sendReply($msg, $username."\n*Id*: ".$msg["from"]["id"]."\n*First*: ".$utils->nm($msg["from"]["first_name"]).$last_name.$language_code."\n*Is_bot*: ".$is_bot, "markdown");
2022
};
23+
return;
2124
};
2225

2326
return array(

plugins/sendfile.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
$exe = function($msg, $matches) {
3+
global $bot; global $utils;
4+
$val = $utils->is_bot_creator($msg["from"]["id"]);
5+
if ($val) {
6+
$bot->sendDocument($msg["chat"]["id"], $matches[1][0]);
7+
} else {
8+
$bot->sendMessage($msg["chat"]["id"], "You are not creator. (".$val.")");
9+
}
10+
};
11+
12+
return array(
13+
"exe" => $exe,
14+
"patterns" => array(
15+
"/\/sendfile (.+)/"
16+
)
17+
)
18+
?>

plugins/sendinline.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
$exe = function($msg, $matches) {
3+
global $bot; global $utils;
4+
if ($matches[1][0] == "isend") {
5+
$arr = json_decode($matches[4][0]);
6+
$arr_cpy = array("inline_keyboard" => $arr);
7+
$dat = $bot->sendMessage($matches[2][0], $matches[3][0], "markdown", $arr_cpy);
8+
//$bot->sendMessage($msg["chat"]["id"], $dat[0]."\n".$matches[3][0]." TYPE: ".$arr);
9+
} elseif ($matches[1][0] == "ksend") {
10+
$arr = json_decode($matches[4][0]);
11+
$arr_cpy = array("keyboard" => $arr);
12+
$dat = $bot->sendMessage($matches[2][0], $matches[3][0], "markdown", $arr_cpy);
13+
}
14+
};
15+
16+
return array(
17+
"exe" => $exe,
18+
"patterns" => array(
19+
"/^\/(isend) (\S+) (.+)\n\n(.+)$/s",
20+
"/^\/(ksend) (\S+) (.+)\n\n(.+)$/s"
21+
)
22+
)
23+
24+
25+
/* Ejemplo de comando inline:
26+
27+
/isend 189041244 👨‍💻 Canales de interés 💻
28+
29+
[
30+
[
31+
{"text":"🔍 Google","url":"t.me/google"}
32+
],
33+
[
34+
{"text":"🍉 TeamFruit","url":"t.me/teamfruit"},
35+
{"text":"📱 Trucos Telegram","url":"t.me/TrucosTelegram"}
36+
]
37+
]
38+
39+
*/
40+
41+
?>

predis

Lines changed: 0 additions & 1 deletion
This file was deleted.

utils.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
class utils {
4+
function nm($text) {
5+
$rep = array('*' => '\\*', '_' => '\\_', '[' => '\\[', '`' => '\\`');
6+
return str_replace(array_keys($rep), array_values($rep), $text);
7+
}
8+
9+
function get_vardump($var) {
10+
ob_start();
11+
var_dump($var);
12+
return ob_get_clean();
13+
}
14+
15+
function is_bot_creator($user_id) {
16+
global $config;
17+
for ($i=0; $i<sizeof($config["owners"]); $i++) {
18+
if ($config["owners"][$i] == $user_id) {
19+
return true;
20+
}
21+
}
22+
return false;
23+
}
24+
}
25+
?>

0 commit comments

Comments
 (0)