-
Notifications
You must be signed in to change notification settings - Fork 3
/
abo_bot.php
100 lines (80 loc) · 3.38 KB
/
abo_bot.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
<?php
require_once dirname(__FILE__) . '/config.php';
include dirname(__FILE__) . '/Telegram.php';
$telegram = new Telegram($BotToken);
$result = $telegram->getData();
//log every interaction with the bot
//file_put_contents('admin/request.txt', date('Y-m-d H:i:s') . ': ' . var_export($result, true) . PHP_EOL, FILE_APPEND);
$text = $telegram->Text();
$chat_id = $telegram->ChatID();
$userId = $telegram->UserID();
$userName = $telegram->Username();
$userFullName = trim($telegram->FirstName() . ' ' . $telegram->LastName());
$content = array();
switch ($text) {
case '/start':
include_once("admin/msg.php");
$content['text'] = $botStartMsg;
$content['reply_markup'] = get_no_abo_buttons();
break;
case '/abo':
$query = $mysqli->query("SELECT * FROM ".$tbl." WHERE userid = $userId ");
$row_cnt = $query->num_rows;
$row = $query->fetch_array();
$now = date_create(date('Y-m-d H:i:s',time()));
$endtime = date_create(date('Y-m-d H:i:s',strtotime($row["endtime"])));
if ($row_cnt == 0 || $now > $endtime) {
include_once("admin/msg.php");
$content['text'] = $botUserFalse;
$content['reply_markup'] = get_no_abo_buttons();
if($userName) {
if($row_cnt == 0) {
$mysqli->query("INSERT INTO ".$tbl." SET userid = $userId, TelegramUser = '@$userName', buyerName = '$userFullName', interaktion = NOW(), info = 2");
} else {
$mysqli->query("UPDATE ".$tbl." SET TelegramUser = '@$userName', buyerName = '$userFullName', interaktion = NOW(), info = 2 WHERE userid = $userId");
}
}
} else {
if($use_map == "PMSF") {
$loginName = $row["buyerEmail"];
} else {
$loginName = $row["TelegramUser"];
}
$passwd = $row["pass"];
$date = $row["endtime"];
if($AccessAllChannels === false) {
$InputChannel = array();
$InputChannel = $row["channels"];
} else {
$InputChannel = NULL;
}
include_once("admin/msg.php");
$content['text'] = $botUserTrue;
$content['reply_markup'] = get_no_abo_buttons();
$mysqli->query("UPDATE ".$tbl." SET TelegramUser = '@$userName', buyerName = '$userFullName', interaktion = NOW() WHERE userid = $userId");
}
break;
default:
break;
}
//antworte nur wenn was zum antworten da ist
if ($content && $userId == $chat_id) {
$content['chat_id'] = $chat_id;
$content['parse_mode'] = 'html';
$content['disable_web_page_preview'] = 'true';
file_put_contents('admin/response.txt', date('Y-m-d H:i:s') . ': ' . var_export($content, true) . PHP_EOL, FILE_APPEND);
$telegram->sendMessage($content);
}
function get_no_abo_buttons() {
global $WebsiteUrl;
$keyboard = array(
'inline_keyboard' => array(
array(
//array('text' => 'inline', 'switch_inline_query' => 'true'),
array('text' => 'Mein Abo', 'callback_data' => '/abo'),
array('text' => 'Abo abschließen', 'url' => $WebsiteUrl),
)
)
);
return json_encode($keyboard);
}