-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtime.php
107 lines (100 loc) · 3.89 KB
/
time.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
101
102
103
104
105
106
107
<?php
/**
* Copyright (C) 2016-2017 Hunter Ashton
* This file is part of BruhhBot.
* BruhhBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* BruhhBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with BruhhBot. If not, see <http://www.gnu.org/licenses/>.
*/
/* server timezone */
define('CONST_SERVER_TIMEZONE', 'UTC');
/* server dateformat */
define('CONST_SERVER_DATEFORMAT', 'l, j - H:i:s');
function gettime($update, $MadelineProto, $area)
{
if (is_peeruser($update, $MadelineProto)) {
$peer = cache_get_info(
$update,
$MadelineProto,
$update['update']['message']['from_id']
)['bot_api_id'];
$ch_id = $peer;
$cont = true;
}
if (is_supergroup($update, $MadelineProto)) {
$chat = parse_chat_data($update, $MadelineProto);
$peer = $chat['peer'];
$ch_id = $chat['id'];
$cont = true;
}
if ($cont) {
$msg_id = $update['update']['message']['id'];
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
];
$response = Requests::get(
'https://maps.googleapis.com/maps/api/geocode/json?address='
.str_replace(' ', '%20', $area)
);
$status = $response->status_code;
// var_dump($status);
$headers = ['Accept' => 'application/json'];
$responsej = json_decode($response->body, true);
// var_dump(json_decode($response->body, true));
if ($responsej['status'] == 'OK') {
// var_dump($responsej['results'][0]['geometry']['location']);
$lat = $responsej['results'][0]['geometry']['location']['lat'];
$lng = $responsej['results'][0]['geometry']['location']['lng'];
$timestamp = time();
$api_response = Requests::get(
'https://maps.googleapis.com/maps/api/timezone/json?location='.
"$lat,$lng×tamp=$timestamp"
);
$api_responsej = json_decode($api_response->body, true);
$ctime = now($api_responsej['timeZoneId']);
$timezone = $api_responsej['timeZoneId'];
$str = $MadelineProto->responses['gettime']['success'];
$repl = [
'timezone' => $timezone,
'ctime' => $ctime,
];
$message = $MadelineProto->engine->render($str, $repl);
$message = str_replace('_', ' ', $message);
$default['message'] = $message;
} else {
$str = $MadelineProto->responses['gettime']['fail'];
$repl = [
'area' => $area,
];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
}
if (isset($default['message'])) {
$sentMessage = $MadelineProto->messages->sendMessage(
$default
);
\danog\MadelineProto\Logger::log($sentMessage);
}
}
}
function now($str_user_timezone,
$str_server_timezone = CONST_SERVER_TIMEZONE,
$str_server_dateformat = CONST_SERVER_DATEFORMAT
) {
// set timezone to user timezone
date_default_timezone_set($str_user_timezone);
$date = new DateTime('now');
$date->setTimezone(new DateTimeZone($str_user_timezone));
$str_server_now = $date->format($str_server_dateformat);
// return timezone to server default
date_default_timezone_set($str_server_timezone);
return $str_server_now;
}