-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (62 loc) · 2.31 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
<?php
require_once 'vendor/autoload.php';
use Telegram\Bot\Api;
$botToken = '';
$commandsDir = __DIR__ . '/commands';
$processedMessagesFile = __DIR__ . '/processed_messages.txt';
$telegram = new Api($botToken);
try {
$processedMessages = file_exists($processedMessagesFile) ? unserialize(file_get_contents($processedMessagesFile)) : [];
$updates = $telegram->getUpdates();
foreach ($updates as $update) {
$message = $update->getMessage();
if (!$message || isset($processedMessages[$message->getMessageId()])) {
continue;
}
$messageTimestamp = $message->getDate();
$currentTime = time();
$timeDifference = $currentTime - $messageTimestamp;
if ($timeDifference >= 300) {
continue;
}
$text = $message->getText();
if (str_starts_with($text, '/')) {
$parts = explode(' ', $text);
$command = $parts[0];
$params = array_slice($parts, 1);
processCommand($telegram, $command, $params, $message);
} else {
require_once $commandsDir . '/autorespond.php';
handleAutorespondCommand($telegram, [], $message);
}
$processedMessages[$message->getMessageId()] = true;
}
file_put_contents($processedMessagesFile, serialize($processedMessages));
} catch (\Telegram\Bot\Exceptions\TelegramResponseException $e) {
echo "Telegram Hata: " . $e->getMessage();
} catch (\Exception $e) {
echo "Hata: " . $e->getMessage();
}
function processCommand($telegram, $command, $params, $message)
{
global $commandsDir;
$commandFile = $commandsDir . '/' . substr($command, 1) . '.php';
if (file_exists($commandFile)) {
require_once $commandFile;
$functionName = 'handle' . ucfirst(substr($command, 1)) . 'Command';
if (function_exists($functionName)) {
call_user_func($functionName, $telegram, $params, $message);
} else {
$telegram->sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => 'Geçersiz Metod: ' . $command
]);
}
} else {
$telegram->sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => 'Geçersiz Komut: ' . $command
]);
}
}
?>