-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
51 lines (38 loc) · 1.62 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
<?php
require __DIR__ . '/vendor/autoload.php';
use Longman\TelegramBot\TelegramLog;
use Psr\Log\LogLevel;
use QuizBot\QuizBot;
use QuizBot\Commands\LintoCommand;
Dotenv\Dotenv::createImmutable(__DIR__)->load();
$mysql_credentials = [
'host' => getenv('MYSQL_HOST'),
'user' => getenv('MYSQL_USER'),
'password' => getenv('MYSQL_PASSWORD'),
'database' => getenv('MYSQL_DB'),
];
$logger = new SimpleLog\Logger(__DIR__.getenv('LOG'), 'telegram_bot', getenv('LOG_LEVEL'));
TelegramLog::initialize($logger);
$logger->info('Got a webhook call');
set_error_handler(function($errno, $message, $file, $line) use ($logger) {
$levels = [
E_ERROR => LogLevel::EMERGENCY, E_WARNING => LogLevel::WARNING, E_NOTICE => LogLevel::WARNING,
E_STRICT => LogLevel::WARNING
];
$logger->log($levels[$errno], '(' . $file . ':' . $line . ') ' . $message);
return true;
}, E_ALL);
try {
$bot = new QuizBot( getenv('TOKEN'), getenv('BOTNAME'));
$bot->enableAdmins([intval(getenv('ADMIN')), intval(getenv('SECOND_ADMIN'))]);
$bot->enableMySql($mysql_credentials);
$bot->addCommandsPath(__DIR__ . '/quizbot/commands/');
if(php_sapi_name() === 'cli' && $argv[1] === 'stats') {
$lintoCommand = new LintoCommand($bot);
$lintoCommand->setChatId(getenv('ADMIN'))->execute();
die;
}
$bot->handle();
} catch (\Throwable $e) {
$logger->log(LogLevel::EMERGENCY, '(' . $e->getFile() . ':' . $e->getLine() . ') ' . $e->getMessage());
}