forked from Ninjasoturi/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
92 lines (79 loc) · 2.3 KB
/
delete.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
<?php
// Write to log.
debug_log('DELETE()');
// For debug.
//debug_log($update);
//debug_log($data);
// Check access.
bot_access_check($update, 'access-bot');
// Count results.
$count = 0;
// Init text and keys.
$text = '';
$keys = [];
try {
$query = '
SELECT
raids.*, gyms.lat ,
gyms.lon ,
gyms.address ,
gyms.gym_name ,
gyms.ex_gym ,
users. NAME
FROM
raids
LEFT JOIN gyms ON raids.gym_id = gyms.id
LEFT JOIN users ON raids.user_id = users.user_id
WHERE
raids.end_time > UTC_TIMESTAMP()
ORDER BY
raids.end_time ASC
LIMIT 20
';
$statement = $dbh->prepare( $query );
$statement->execute();
while ($row = $statement->fetch()) {
// Set text and keys.
$text .= $row['gym_name'] . CR;
$now = utcnow();
$today = dt2date($now);
$raid_day = dt2date($row['start_time']);
$start = dt2time($row['start_time']);
$end = dt2time($row['end_time']);
$text .= get_local_pokemon_name($row['pokemon'], $row['pokemon_form']) . SP . '—' . SP . (($raid_day == $today) ? '' : ($raid_day . ', ')) . $start . SP . getTranslation('to') . SP . $end . CR . CR;
$keys[] = array(
'text' => $row['gym_name'],
'callback_data' => $row['id'] . ':raids_delete:0'
);
// Counter++
$count = $count + 1;
}
}
catch (PDOException $exception) {
error_log($exception->getMessage());
$dbh = null;
exit;
}
// Set message.
if($count == 0) {
$msg = '<b>' . getTranslation('no_active_raids_found') . '</b>';
} else {
// Get the inline key array.
$keys = inline_key_array($keys, 1);
// Add exit key.
$keys[] = [
[
'text' => getTranslation('abort'),
'callback_data' => '0:exit:0'
]
];
// Build message.
$msg = '<b>' . getTranslation('list_all_active_raids') . ':</b>' . CR;
$msg .= $text;
$msg .= '<b>' . getTranslation('select_gym_name') . '</b>' . CR;
}
// Build callback message string.
$callback_response = 'OK';
// Send message.
send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]);
?>