forked from piterskiy/etuts-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_commands.php
34 lines (31 loc) · 1.14 KB
/
handle_commands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
function run_commands($text, $chat_id, $message_id, $message) {
global $db;
preg_match_all('/\/\w+/', $text, $commands);
$command_class = substr($commands[0][0].'_command',1);
if (class_exists($command_class)) {
$permission = get_class_vars($command_class)['permission'];
$is_author = $db->check_user_permission(AUTHOR);
$is_admin = $db->check_user_permission(ADMIN);
if ($permission == AUTHOR && !($is_author || $is_admin)) {
reply('ببخشید اما شما نویسنده ی سایت نیستید!');
} else if ($permission == ADMIN && !$is_admin) {
reply('برای استفاده از این دستور باید ادمین کانال باشید');
} else {
$command = new $command_class();
$command->run($chat_id, $text, $message_id, $message, IDLE);
}
}
}
function is_cancel_command($text, $chat_id, $message_id, $message) {
if (contains_word($text, "/cancel")) {
$command = new cancel_command();
$command->run($chat_id, $text, $message_id, $message, IDLE);
return true;
}
return false;
}
require "./commands/base_command.php";
foreach (glob("./commands/command_*.php") as $filename) {
require ($filename);
}