-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbothook.php
103 lines (83 loc) · 1.59 KB
/
bothook.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
include_once('conf.php');
spl_autoload_register(function($class) {
include_once 'classes/' . $class . '.php';
});
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chat_id = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
// Available bot commands
$commands = [
// General Commands
'help',
// Server Commands
'server',
//Alias for /server uptime
'uptime',
// Alias for /server uname
'uname',
// Alias for /server who
'who',
// Alias for /server disk
'disk',
];
$arguments = [
// Server
'server'=>[
'uptime',
'uname',
'who',
'disk',
],
'help'=>[
'server',
],
];
// Aliases for commands
$alias = [
'uptime'=>'server',
'uname'=>'server',
'who'=>'server',
'disk'=>'server',
];
$args = explode(' ', trim($message));
$command = ltrim(array_shift($args), '/');
$method = '';
if (isset($args[0]) && in_array($args[0], $arguments[$command])) {
$method = array_shift($args);
}
else {
if (in_array($command, array_keys($alias))) {
$method = $command;
$command = $alias[$command];
}
}
switch ($command) {
case 'server':
$class = 'Server';
break;
case 'help':
$class = 'Help';
break;
default:
$class = 'Bot';
}
$hook = new $class($conf, $chat_id);
if (!$hook->isTrusted()) {
$hook->unauthorized();
die();
}
if (!in_array($command, $commands)) {
$hook->unknown();
}
else {
if (isset($arguments[$command]) && in_array($method, $arguments[$command])) {
$hook->{$method}($args);
die();
} else if (in_array($command, $commands)) {
$hook->{$command}($args);
} else {
$hook->unknown();
}
}