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
|
|
|
use discord\discord; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class periodicStatusCheck |
30
|
|
|
*/ |
31
|
|
|
class periodicStatusCheck |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
public $config; |
34
|
|
|
public $discord; |
35
|
|
|
public $logger; |
36
|
|
|
public $guild; |
37
|
|
|
protected $keyID; |
38
|
|
|
protected $vCode; |
39
|
|
|
protected $prefix; |
40
|
|
|
private $toDiscordChannel; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param $config |
44
|
|
|
* @param $discord |
45
|
|
|
* @param $logger |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function init($config, $discord, $logger) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$this->config = $config; |
50
|
|
|
$this->discord = $discord; |
51
|
|
|
$this->logger = $logger; |
52
|
|
|
$this->guild = $config['bot']['guild']; |
53
|
|
|
$this->toDiscordChannel = $config['plugins']['notifications']['channelID']; |
54
|
|
|
//Refresh check at bot start |
55
|
|
|
setPermCache('statusLastChecked', time() - 5); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* |
60
|
|
|
*/ |
61
|
|
|
public function tick() |
62
|
|
|
{ |
63
|
|
|
$lastChecked = getPermCache('statusLastChecked'); |
64
|
|
|
|
65
|
|
|
if ($lastChecked <= time()) { |
66
|
|
|
$this->checkStatus(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function checkStatus() |
71
|
|
|
{ |
72
|
|
|
if ($this->toDiscordChannel === 0) { |
73
|
|
|
setPermCache('statusLastChecked', time() + 300); |
74
|
|
|
$this->logger->addInfo('statusCheck: TQ Status Check Failed - Add a channel ID to the notifications section in the config.'); |
75
|
|
|
return null; |
76
|
|
|
} |
77
|
|
|
// What was the servers last reported state |
78
|
|
|
$lastStatus = getPermCache('statusLastState'); |
79
|
|
|
|
80
|
|
|
//Crest |
81
|
|
|
$crestData = json_decode(downloadData('https://crest-tq.eveonline.com/'), true); |
82
|
|
|
$crestStatus = isset($crestData['serviceStatus']) ? $crestData['serviceStatus'] : 'offline'; |
83
|
|
|
$tqOnline = (int) $crestData['userCount']; |
84
|
|
|
|
85
|
|
|
if ($lastStatus === $crestStatus) { |
86
|
|
|
// No change |
87
|
|
|
setPermCache('statusLastChecked', time() + 300); |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$msg = "**TQ Status Change:** {$crestStatus} with {$tqOnline} users online."; |
92
|
|
|
$channelID = $this->toDiscordChannel; |
93
|
|
|
priorityQueueMessage($msg, $channelID, $this->guild); |
94
|
|
|
setPermCache('statusLastState', $crestStatus); |
95
|
|
|
if ($crestStatus === 'online') { |
96
|
|
|
setPermCache('serverState', $crestStatus); |
97
|
|
|
setPermCache('statusLastChecked', time() + 300); |
98
|
|
|
$this->logger->addInfo("statusCheck: TQ Status Change Detected. New status - {$crestStatus}"); |
99
|
|
|
return null; |
100
|
|
|
} |
101
|
|
|
setPermCache('statusLastChecked', time() + 90); |
102
|
|
|
$this->logger->addInfo("statusCheck: TQ Status Change Detected. New status - {$crestStatus}"); |
103
|
|
|
return null; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.