Skip to content

Commit 2f7405c

Browse files
authored
añadiendo plugins función
1 parent 72d84d4 commit 2f7405c

File tree

1 file changed

+24
-41
lines changed

1 file changed

+24
-41
lines changed

bot.php

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,45 @@ function mdEscape($text) {
1313
return str_replace(array_keys($rep), array_values($rep), $text);
1414
};
1515

16+
function get_vardump($var) {
17+
ob_start();
18+
var_dump($var);
19+
return ob_get_clean();
20+
};
21+
1622
$updates = file_get_contents("php://input");
1723
$updates = json_decode($updates, TRUE);
1824

1925
$msg = $updates["message"];
20-
21-
$teclado = array(
22-
"inline_keyboard" => array(
23-
array(
24-
array(
25-
"text" => "Canal moderatorz",
26-
"url" => "https://telegram.me/Moderatorz"
27-
),
28-
array(
29-
"text" => "Trucos Telegram",
30-
"url" => "https://telegram.me/trucostelegram"
31-
)
32-
),
33-
array(
34-
array(
35-
"text" => "Google",
36-
"url" => "https://google.com"
37-
)
38-
)
39-
)
40-
);
26+
$msg["cb"] = $updates["callback_query"];
4127

4228
if ($config["var_dump"]) {
43-
ob_start();
44-
var_dump($msg);
45-
$result = ob_get_clean();
29+
$result = get_vardump($msg);
4630
if ($result) {
47-
$bot->sendMessage($config["owners"][0], $result, false, false, false);
31+
$bot->sendMessage($config["owners"][0], $result);
4832
return;
4933
}
5034
};
5135

52-
if (isset($msg["forward_from_chat"])) {
53-
$username = $msg["forward_from_chat"]["username"]?"@".mdEscape($msg["forward_from_chat"]["username"]):"";
54-
$type = $msg["forward_from_chat"]["type"]?"\n*Type*: ".$msg["forward_from_chat"]["type"]:"";
55-
$bot->sendReply($msg, $username."\n*Id*: ".$msg["forward_from_chat"]["id"]."\n*Title*: ".mdEscape($msg["forward_from_chat"]["title"]).$type, "markdown", false);
56-
return;
57-
};
58-
59-
if (isset($msg["forward_from"])) {
60-
$msg["from"] = $msg["forward_from"];
61-
};
62-
63-
if (isset($msg["text"]) && isset($msg["from"])) {
64-
$last_name = $msg["from"]["last_name"]?"\n*Last*: ".$msg["from"]["last_name"]:"";
65-
$username = $msg["from"]["username"]?"@".mdEscape($msg["from"]["username"]):"";
66-
$language_code = $msg["from"]["language_code"]?"\n*Lang*: ".$msg["from"]["language_code"]:"";
67-
$bot->sendReply($msg, $username."\n*Id*: ".$msg["from"]["id"]."\n*First*: ".mdEscape($msg["from"]["first_name"]).$last_name.$language_code, "markdown", false);
36+
for ($i=0; $i<sizeof($config["plugins"]); $i++) {
37+
$actual_plugin = include "plugins/".$config["plugins"][$i];
38+
if (isset($actual_plugin["pre_process"])) {
39+
call_user_func($actual_plugin["pre_process"], $bot, $msg, $matches);
40+
};
41+
if (isset($actual_plugin["exe"])) {
42+
for ($m=0; $m<sizeof($actual_plugin["patterns"]); $m++) {
43+
preg_match($actual_plugin["patterns"][$m], $msg["text"], $matches, PREG_OFFSET_CAPTURE);
44+
if ($matches) {
45+
call_user_func($actual_plugin["exe"], $bot, $msg, $matches);
46+
break;
47+
}
48+
}
49+
};
6850
};
6951

7052
ini_set('display_errors', 1);
7153
ini_set('display_startup_errors', 1);
7254
error_reporting(E_ALL);
7355

56+
7457
?>

0 commit comments

Comments
 (0)