forked from pokepark/PokemonQuestBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·200 lines (161 loc) · 6.22 KB
/
index.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
// Include files.
require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/core/class/constants.php');
require_once(__DIR__ . '/core/class/debug.php');
require_once(__DIR__ . '/core/class/functions.php');
require_once(__DIR__ . '/core/class/geo_api.php');
require_once(__DIR__ . '/logic.php');
// Start logging.
debug_log("QUEST-BOT '" . BOT_ID . "'");
// Check API Key and get input from telegram
include_once(CORECLASS_PATH . '/apikey.php');
// DDOS protection
include_once(CORECLASS_PATH . '/ddos.php');
// Get language
include_once(CORECLASS_PATH . '/language.php');
// Update var is false.
$log_prefix = '<';
if (!$update) {
$log_prefix = '!';
}
// Write to log.
debug_log($update, $log_prefix);
// Establish mysql connection.
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$db->set_charset('utf8mb4');
my_query('SET time_zone="'.TIMEZONE.'"');
// Error connecting to db.
if ($db->connect_errno) {
// Write connection error to log.
debug_log("Failed to connect to Database!" . $db->connect_error(), '!');
// Echo data.
sendMessage($update['message']['chat']['id'], "Failed to connect to Database!\nPlease contact " . MAINTAINER . " and forward this message...\n");
}
// Run cleanup if requested
include_once(CORECLASS_PATH . '/cleanup_run.php');
// Update the user
if ($ddos_count == 0 || $ddos_count > 2) {
// Update the user.
$userUpdate = update_user($update);
// Write to log.
debug_log('Update user: ' . $userUpdate);
}
// Callback query received.
if (isset($update['callback_query'])) {
// Init empty data array.
$data = [];
// Callback data found.
if ($update['callback_query']['data']) {
// Split bot folder name away from actual data.
$botnameData = explode(':', $update['callback_query']['data'], 2);
$botname = $botnameData[0];
$thedata = $botnameData[1];
// Write to log
debug_log('Bot Name: ' . $botname);
debug_log('The Data: ' . $thedata);
// Split callback data and assign to data array.
$splitData = explode(':', $thedata);
$data['id'] = $splitData[0];
$data['action'] = $splitData[1];
$data['arg'] = $splitData[2];
}
// Write data to log.
debug_log($data, '* DATA= ');
// Set module path by sent action name.
$module = ROOT_PATH . '/mods/' . basename($data['action']) . '.php';
// Write module to log.
debug_log($module);
// Check if the module file exists.
if (file_exists($module)) {
// Dynamically include module file and exit.
include_once($module);
exit();
// Module file is missing.
} else {
// Write to log.
debug_log('No action');
}
// Inline query received.
} else if (isset($update['inline_query'])) {
// Check access to the bot
bot_access_check($update);
// List quests and exit.
quest_list($update);
exit();
// Location received.
} else if (isset($update['message']['location'])) {
// Check access to the bot
bot_access_check($update);
// Create raid and exit.
if(QUEST_VIA_LOCATION == true) {
include_once(ROOT_PATH . '/mods/quest_geo.php');
}
exit();
// File received.
} else if (isset($update['message']['document'])) {
include_once(ROOT_PATH . '/mods/setup_file.php');
// Cleanup collection from channel/supergroup messages.
} else if ((isset($update['channel_post']) && $update['channel_post']['chat']['type'] == "channel") || (isset($update['message']) && $update['message']['chat']['type'] == "supergroup")) {
// Write to log.
debug_log('Collecting cleanup preparation information...');
// Init ID.
$id = 0;
// Channel
if(isset($update['channel_post'])) {
// Get chat_id and message_id
$chat_id = $update['channel_post']['chat']['id'];
$message_id = $update['channel_post']['message_id'];
// Get id from text.
$id = substr(strrchr($update['channel_post']['text'], substr(strtoupper(BOT_ID), 0, 1) . '-ID = '), 7);
// Supergroup
} else if ($update['message']['chat']['type'] == "supergroup") {
// Get chat_id and message_id
$chat_id = $update['message']['chat']['id'];
$message_id = $update['message']['message_id'];
// Get id from text.
$id = substr(strrchr($update['message']['text'], substr(strtoupper(BOT_ID), 0, 1) . '-ID = '), 7);
}
// Write cleanup info to database.
debug_log('Calling cleanup preparation now!');
debug_log('Cleanup_ID: ' . $id);
if($id != 0) {
insert_cleanup($chat_id, $message_id, $id);
}
// Message is required to check for commands.
} else if (isset($update['message']) && $update['message']['chat']['type'] == 'private') {
// Check access to the bot
bot_access_check($update);
// Init command.
$command = NULL;
// Check message text for a leading slash.
if (substr($update['message']['text'], 0, 1) == '/') {
// Get command name.
$com = strtolower(str_replace('/', '', str_replace(BOT_NAME, '', explode(' ', $update['message']['text'])[0])));
$altcom = strtolower(str_replace('/' . basename(ROOT_PATH), '', str_replace(BOT_NAME, '', explode(' ', $update['message']['text'])[0])));
// Set command paths.
$command = ROOT_PATH . '/commands/' . basename($com) . '.php';
$altcommand = ROOT_PATH . '/commands/' . basename($altcom) . '.php';
$startcommand = ROOT_PATH . '/commands/start.php';
// Write to log.
debug_log('Command-File: ' . $command);
debug_log('Alternative Command-File: ' . $altcommand);
debug_log('Start Command-File: ' . $startcommand);
// Check if command file exits.
if (is_file($command)) {
// Dynamically include command file and exit.
include_once($command);
exit();
} else if (is_file($altcommand)) {
// Dynamically include command file and exit.
include_once($altcommand);
exit();
} else if ($com == basename(ROOT_PATH)) {
// Include start file and exit.
include_once($startcommand);
exit();
} else {
sendMessage($update['message']['chat']['id'], '<b>' . getTranslation('not_supported') . '</b>');
}
}
}