1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Discord\Discord; |
4
|
|
|
|
5
|
|
|
class sysInfo |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
public $config; |
8
|
|
|
public $discord; |
9
|
|
|
public $logger; |
10
|
|
|
private $excludeChannel; |
11
|
|
|
private $message; |
12
|
|
|
private $triggers; |
13
|
|
|
|
14
|
|
|
public function init($config, $discord, $logger) |
15
|
|
|
{ |
16
|
|
|
$this->config = $config; |
17
|
|
|
$this->discord = $discord; |
18
|
|
|
$this->logger = $logger; |
19
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
20
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'sys'; |
21
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Sys'; |
22
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'sysinfo'; |
23
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'system'; |
24
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'System'; |
25
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Sysinfo'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function onMessage($msgData, $message) |
29
|
|
|
{ |
30
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
31
|
|
|
|
32
|
|
|
if(in_array($channelID, $this->excludeChannel, true)) |
33
|
|
|
{ |
34
|
|
|
return null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->message = $message; |
38
|
|
|
|
39
|
|
|
$message = $msgData['message']['message']; |
40
|
|
|
$user = $msgData['message']['from']; |
41
|
|
|
|
42
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
43
|
|
|
if(isset($data['trigger'])) |
44
|
|
|
{ |
45
|
|
|
$messageString = strstr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
46
|
|
|
if(is_numeric($messageString)) |
47
|
|
|
{ |
48
|
|
|
$messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', array(':id' => $messageString)); |
49
|
|
|
} |
50
|
|
|
$cleanString = urlencode($messageString); |
51
|
|
|
$sysID = urlencode(getSystemID($cleanString)); |
52
|
|
|
|
53
|
|
|
//Check if we get a system back, otherwise check for partials |
54
|
|
|
if(empty($sysID)) |
55
|
|
|
{ |
56
|
|
|
return $this->message->reply('**Error:** no data available'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$systemDetails = systemDetails($sysID); |
60
|
|
|
if (null === $systemDetails) |
61
|
|
|
{ |
62
|
|
|
return $this->message->reply('**Error:** ESI is down. Try again later.'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$url = "https://zkillboard.com/api/stats/solarSystemID/{$sysID}/"; |
66
|
|
|
$json = json_decode(file_get_contents($url)); |
67
|
|
|
|
68
|
|
|
$regionID = $json->info->regionID; |
69
|
|
|
$regionName = getRegionName($regionID); |
70
|
|
|
|
71
|
|
|
$thisMonth = (string)date('Ym'); |
72
|
|
|
$lastMonth = (string)date('Ym', strtotime('first day of previous month')); |
73
|
|
|
|
74
|
|
|
$thisMonthKill = $json->months->$thisMonth->shipsDestroyed; |
75
|
|
|
$lastMonthKill = $json->months->$lastMonth->shipsDestroyed; |
76
|
|
|
|
77
|
|
|
$activePVP = $json->activepvp; |
78
|
|
|
$activeKills = $activePVP->kills->count; |
79
|
|
|
$activeChars = $activePVP->characters->count; |
80
|
|
|
|
81
|
|
|
$sysName = $systemDetails['name']; |
82
|
|
|
$secStatus = round($systemDetails['security_status'],2); |
83
|
|
|
|
84
|
|
|
$npc = "https://api.eveonline.com/map/kills.xml.aspx"; |
85
|
|
|
$npc = new SimpleXMLElement(file_get_contents($npc)); |
86
|
|
|
foreach($npc->result->rowset->row as $row){ |
87
|
|
|
if($row->attributes()->solarSystemID == $sysID){ |
88
|
|
|
$npcKills = $row->attributes()->factionKills; |
89
|
|
|
$podKills = $row->attributes()->podKills; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$url = "https://zkillboard.com/system/{$sysID}/"; |
94
|
|
|
|
95
|
|
|
$msg = "```Systeminfo |
96
|
|
|
Name: {$sysName} |
97
|
|
|
Region: {$regionName} |
98
|
|
|
Security: {$secStatus} |
99
|
|
|
|
100
|
|
|
Kills |
101
|
|
|
This Month: {$thisMonthKill} |
102
|
|
|
Last Month: {$lastMonthKill} |
103
|
|
|
|
104
|
|
|
Activity |
105
|
|
|
Characters: {$activeChars} |
106
|
|
|
Kills: {$activeKills} |
107
|
|
|
Pod Kills: {$podKills} |
|
|
|
|
108
|
|
|
NPC Kills: {$npcKills} |
|
|
|
|
109
|
|
|
``` |
110
|
|
|
|
111
|
|
|
More information: $url"; |
112
|
|
|
$this->logger->addInfo("sysInfo: Sending system information to {$user}"); |
113
|
|
|
$this->message->reply($msg); |
114
|
|
|
} |
115
|
|
|
return null; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function information() |
119
|
|
|
{ |
120
|
|
|
return array( |
121
|
|
|
'name' => 'sys', |
122
|
|
|
'trigger' => $this->triggers, |
123
|
|
|
'information' => 'Returns information for the given system' |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
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.