1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The MIT License (MIT) |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Robert Sardinia |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
15
|
|
|
* copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class time |
28
|
|
|
* @property message |
29
|
|
|
*/ |
30
|
|
|
class time |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
public $config; |
33
|
|
|
public $discord; |
34
|
|
|
public $logger; |
35
|
|
|
public $message; |
36
|
|
|
private $excludeChannel; |
37
|
|
|
private $triggers; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param $config |
41
|
|
|
* @param $discord |
42
|
|
|
* @param $logger |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function init($config, $discord, $logger) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->config = $config; |
47
|
|
|
$this->discord = $discord; |
48
|
|
|
$this->logger = $logger; |
49
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
50
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'time'; |
51
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Time'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param $msgData |
56
|
|
|
* @param $message |
57
|
|
|
* @return null |
58
|
|
|
*/ |
59
|
|
|
public function onMessage($msgData, $message) |
60
|
|
|
{ |
61
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
62
|
|
|
|
63
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
64
|
|
|
{ |
65
|
|
|
return null; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->message = $message; |
69
|
|
|
$user = $msgData['message']['from']; |
70
|
|
|
|
71
|
|
|
$message = $msgData['message']['message']; |
72
|
|
|
|
73
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
74
|
|
|
if (isset($data['trigger'])) { |
75
|
|
|
$date = date('d-F-Y'); |
76
|
|
|
$fullDate = date('Y-m-d H:i:s'); |
77
|
|
|
$datetime = new DateTime($fullDate); |
78
|
|
|
$est = $datetime->setTimezone(new DateTimeZone('America/New_York')); |
79
|
|
|
$est = $est->format('H:i:s'); |
80
|
|
|
$pst = $datetime->setTimezone(new DateTimeZone('America/Los_Angeles')); |
81
|
|
|
$pst = $pst->format('H:i:s'); |
82
|
|
|
$utc = $datetime->setTimezone(new DateTimeZone('UTC')); |
83
|
|
|
$utc = $utc->format('H:i:s'); |
84
|
|
|
$cet = $datetime->setTimezone(new DateTimeZone('Europe/Copenhagen')); |
85
|
|
|
$cet = $cet->format('H:i:s'); |
86
|
|
|
$msk = $datetime->setTimezone(new DateTimeZone('Europe/Moscow')); |
87
|
|
|
$msk = $msk->format('H:i:s'); |
88
|
|
|
$aus = $datetime->setTimezone(new DateTimeZone('Australia/Sydney')); |
89
|
|
|
$aus = $aus->format('H:i:s'); |
90
|
|
|
|
91
|
|
|
$this->logger->addInfo("Time: Sending time info to {$user}"); |
92
|
|
|
$this->message->reply("**EVE Time:** {$utc} -- **EVE Date:** {$date} -- **PST/Los Angeles:** {$pst} -- **EST/New York:** {$est} -- **CET/Copenhagen:** {$cet} -- **MSK/Moscow:** {$msk} -- **AEST/Sydney:** {$aus}"); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function information() |
100
|
|
|
{ |
101
|
|
|
return array( |
102
|
|
|
'name' => 'time', |
103
|
|
|
'trigger' => $this->triggers, |
104
|
|
|
'information' => 'This shows the time for various timezones compared to EVE Time. To use simply type <!time>' |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.