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(systemID($cleanString)); |
52
|
|
|
|
53
|
|
|
//Check if we get a system back, otherwise check for partials |
54
|
|
|
if(empty($sysID)) |
55
|
|
|
{ |
56
|
|
|
$search = "http://tools.pandemic-legion.pl/api/search/{$cleanString}"; |
57
|
|
|
$search = json_decode(file_get_contents($search)); |
58
|
|
|
$tot = 0; |
59
|
|
|
$res = array(); |
60
|
|
|
foreach ($search as $s){ |
61
|
|
|
if ($s->type == "system"){ |
62
|
|
|
$tot++; |
63
|
|
|
$res[] = $s->name; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
if ($tot == 0){ |
67
|
|
|
return $this->message->reply('**Error:** no data available'); |
68
|
|
|
} |
69
|
|
|
if ($tot == 1){ |
70
|
|
|
$sysID = urlencode(systemID($res[0])); |
71
|
|
|
if(empty($sysID)){ |
72
|
|
|
return $this->message->reply('**Error:** no data available'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
if ($tot > 1){ |
76
|
|
|
$res = implode(", ",$res); |
77
|
|
|
return $this->message->reply("**Error:** Did you mean one of these? {$res}"); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$systemDetails = systemDetails($sysID); |
82
|
|
|
if (null === $systemDetails) |
83
|
|
|
{ |
84
|
|
|
return $this->message->reply('**Error:** ESI is down. Try again later.'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$url = "https://zkillboard.com/api/stats/solarSystemID/{$sysID}/"; |
88
|
|
|
$json = json_decode(file_get_contents($url)); |
89
|
|
|
|
90
|
|
|
$regionID = $json->info->regionID; |
91
|
|
|
$regionDetails = regionDetails($regionID); |
92
|
|
|
$regionName = $regionDetails['name']; |
93
|
|
|
|
94
|
|
|
$thisMonth = (string)date('Ym'); |
95
|
|
|
$lastMonth = (string)date('Ym', strtotime('first day of previous month')); |
96
|
|
|
|
97
|
|
|
$thisMonthKill = $json->months->$thisMonth->shipsDestroyed; |
98
|
|
|
$lastMonthKill = $json->months->$lastMonth->shipsDestroyed; |
99
|
|
|
|
100
|
|
|
$activePVP = $json->activepvp; |
101
|
|
|
$activeKills = $activePVP->kills->count; |
102
|
|
|
$activeChars = $activePVP->characters->count; |
103
|
|
|
|
104
|
|
|
$sysName = $systemDetails['name']; |
105
|
|
|
$secStatus = round($systemDetails['security_status'],2); |
106
|
|
|
|
107
|
|
|
$npc = "https://api.eveonline.com/map/kills.xml.aspx"; |
108
|
|
|
$npc = new SimpleXMLElement(file_get_contents($npc)); |
109
|
|
|
foreach($npc->result->rowset->row as $row){ |
110
|
|
|
if($row->attributes()->solarSystemID == $sysID){ |
111
|
|
|
$npcKills = $row->attributes()->factionKills; |
112
|
|
|
$podKills = $row->attributes()->podKills; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$url = "https://zkillboard.com/system/{$sysID}/"; |
117
|
|
|
|
118
|
|
|
$msg = "```Systeminfo |
119
|
|
|
Name: {$sysName} |
120
|
|
|
Region: {$regionName} |
121
|
|
|
Security: {$secStatus} |
122
|
|
|
|
123
|
|
|
Kills |
124
|
|
|
This Month: {$thisMonthKill} |
125
|
|
|
Last Month: {$lastMonthKill} |
126
|
|
|
|
127
|
|
|
Activity |
128
|
|
|
Characters: {$activeChars} |
129
|
|
|
Kills: {$activeKills} |
130
|
|
|
Pod Kills: {$podKills} |
|
|
|
|
131
|
|
|
NPC Kills: {$npcKills} |
|
|
|
|
132
|
|
|
``` |
133
|
|
|
|
134
|
|
|
More information: $url"; |
135
|
|
|
$this->logger->addInfo("sysInfo: Sending system information to {$user}"); |
136
|
|
|
$this->message->reply($msg); |
137
|
|
|
} |
138
|
|
|
return null; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function information() |
142
|
|
|
{ |
143
|
|
|
return array( |
144
|
|
|
'name' => 'sys', |
145
|
|
|
'trigger' => $this->triggers, |
146
|
|
|
'information' => 'Returns information for the given system' |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
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.