This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmulti-poll.example.php
94 lines (74 loc) · 2.57 KB
/
multi-poll.example.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
<?php
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Telegram;
use WinTenDev\Utils\Arrays;
use WinTenDev\Utils\Console;
require_once 'vendor/autoload.php';
Console::println('Execute autoload');
Console::println('Loading bot configuration');
$bots = include __DIR__ . '/Resources/Config/bots.php';
Console::println('Get input param from CLI');
$input = $argv[1];
if($input == ''){
throw new Exception('Parameter ID is needed.', 1);
}
Console::println('Loaded => ' . json_encode($input));
Console::println('Getting ready..');
foreach (glob('Resources/*/*.php') as $files) {
Console::println("Loading $files");
include_once $files;
}
$filtered = Arrays::arrayFilter($bots, ['id' => $input]);
if (count($filtered) == 1) {
global $bot_username;
global $bot_name;
global $bot_token;
global $is_beta;
global $is_restricted;
$bot_username = $filtered[0]['bot_username'];
$bot_name = $filtered[0]['bot_name'];
$bot_token = $filtered[0]['bot_token'];
$is_beta = $filtered[0]['is_beta'];
$is_restricted = $filtered[0]['is_restricted'];
Console::println("BotUsername: $bot_username");
$path_commands = [
__DIR__ . '/Commands/SystemCommands',
__DIR__ . '/Commands/UserCommands/Additional',
__DIR__ . '/Commands/UserCommands/Bot',
__DIR__ . '/Commands/UserCommands/CekResi',
__DIR__ . '/Commands/UserCommands/Chat',
__DIR__ . '/Commands/UserCommands/FedBan',
__DIR__ . '/Commands/UserCommands/GitTools',
__DIR__ . '/Commands/UserCommands/Group',
__DIR__ . '/Commands/UserCommands/Labs',
__DIR__ . '/Commands/UserCommands/Member',
__DIR__ . '/Commands/UserCommands/Security',
__DIR__ . '/Commands/UserCommands/Sudoer',
__DIR__ . '/Commands/UserCommands/Tagging',
__DIR__ . '/Commands/UserCommands/Texting',
];
try {
Console::println('Creating instance..');
$telegram = new Telegram($bot_token, $bot_username);
// Set custom Upload and Download paths
$telegram->setDownloadPath(__DIR__ . '/Data/Download');
$telegram->setUploadPath(__DIR__ . '/Data/Upload');
// Handle telegram webhook request
Console::println('Loading Bot command');
$telegram->addCommandsPaths($path_commands);
$telegram->useGetUpdatesWithoutDatabase();
// Enable Limiter
$telegram->enableLimiter();
// Handle Poll Request
Console::println('Bot is must ready!');
while (true) {
$telegram->handleGetUpdates();
}
} catch (TelegramException $e) {
echo '<br>Error: ' . $e->getMessage();
echo '<br>Stacktrace: ' . $e->getTraceAsString();
// Logs::toChannel($e->getMessage());
}
} else {
Console::println('Something went wrong..');
}