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
|
|
|
* @property message |
28
|
|
|
*/ |
29
|
|
|
class eveStatus |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
public $config; |
32
|
|
|
public $discord; |
33
|
|
|
public $logger; |
34
|
|
|
public $message; |
35
|
|
|
private $excludeChannel; |
36
|
|
|
private $triggers; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $config |
40
|
|
|
* @param $discord |
41
|
|
|
* @param $logger |
42
|
|
|
*/ |
43
|
|
|
public function init($config, $discord, $logger) |
44
|
|
|
{ |
45
|
|
|
$this->config = $config; |
46
|
|
|
$this->discord = $discord; |
47
|
|
|
$this->logger = $logger; |
48
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
49
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'tq'; |
50
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Tq'; |
51
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'status'; |
52
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Status'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $msgData |
57
|
|
|
* @param $message |
58
|
|
|
* @return null |
59
|
|
|
*/ |
60
|
|
|
public function onMessage($msgData, $message) |
61
|
|
|
{ |
62
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
63
|
|
|
|
64
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
65
|
|
|
{ |
66
|
|
|
return null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->message = $message; |
70
|
|
|
|
71
|
|
|
$message = $msgData['message']['message']; |
72
|
|
|
$user = $msgData['message']['from']; |
73
|
|
|
|
74
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
75
|
|
|
if (isset($data['trigger'])) { |
76
|
|
|
|
77
|
|
|
$crestData = json_decode(downloadData('https://crest-tq.eveonline.com/'), true); |
78
|
|
|
|
79
|
|
|
$tqStatus = isset($crestData['serviceStatus']) ? $crestData['serviceStatus'] : 'offline'; |
80
|
|
|
$tqOnline = (int) $crestData['userCount']; |
81
|
|
|
|
82
|
|
|
$msg = "**TQ Status:** {$tqStatus} with {$tqOnline} users online."; |
83
|
|
|
$this->logger->addInfo("eveStatus: Sending eve status info to {$user}"); |
84
|
|
|
$this->message->reply($msg); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function information() |
92
|
|
|
{ |
93
|
|
|
return array( |
94
|
|
|
'name' => 'tq', |
95
|
|
|
'trigger' => $this->triggers, |
96
|
|
|
'information' => 'Shows the current status of Tranquility' |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
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.