@@ -440,6 +440,9 @@ |
||
440 | 440 | * @return mixed |
441 | 441 | */ |
442 | 442 | ////System name to ID |
443 | +/** |
|
444 | + * @return string |
|
445 | + */ |
|
443 | 446 | function systemID($systemName) |
444 | 447 | { |
445 | 448 | $logger = new Logger('eveESI'); |
@@ -1,7 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -use Discord\Discord; |
|
4 | - |
|
5 | 3 | class sysInfo |
6 | 4 | { |
7 | 5 | public $config; |
@@ -4,94 +4,94 @@ discard block |
||
4 | 4 | |
5 | 5 | class sysInfo |
6 | 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'); |
|
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 | 95 | $lastMonth = (string)date('Ym', strtotime('first day of previous month')); |
96 | 96 | |
97 | 97 | $thisMonthKill = $json->months->$thisMonth->shipsDestroyed; |
@@ -101,21 +101,21 @@ discard block |
||
101 | 101 | $activeKills = $activePVP->kills->count; |
102 | 102 | $activeChars = $activePVP->characters->count; |
103 | 103 | |
104 | - $sysName = $systemDetails['name']; |
|
105 | - $secStatus = round($systemDetails['security_status'],2); |
|
104 | + $sysName = $systemDetails['name']; |
|
105 | + $secStatus = round($systemDetails['security_status'],2); |
|
106 | 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 | - } |
|
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 | 115 | |
116 | - $url = "https://zkillboard.com/system/{$sysID}/"; |
|
116 | + $url = "https://zkillboard.com/system/{$sysID}/"; |
|
117 | 117 | |
118 | - $msg = "```Systeminfo |
|
118 | + $msg = "```Systeminfo |
|
119 | 119 | Name: {$sysName} |
120 | 120 | Region: {$regionName} |
121 | 121 | Security: {$secStatus} |
@@ -132,18 +132,18 @@ discard block |
||
132 | 132 | ``` |
133 | 133 | |
134 | 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 | - } |
|
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 | 149 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | $channelID = (int) $msgData['message']['channelID']; |
31 | 31 | |
32 | - if(in_array($channelID, $this->excludeChannel, true)) |
|
32 | + if (in_array($channelID, $this->excludeChannel, true)) |
|
33 | 33 | { |
34 | 34 | return null; |
35 | 35 | } |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | $user = $msgData['message']['from']; |
41 | 41 | |
42 | 42 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
43 | - if(isset($data['trigger'])) |
|
43 | + if (isset($data['trigger'])) |
|
44 | 44 | { |
45 | 45 | $messageString = strstr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
46 | - if(is_numeric($messageString)) |
|
46 | + if (is_numeric($messageString)) |
|
47 | 47 | { |
48 | 48 | $messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', array(':id' => $messageString)); |
49 | 49 | } |
@@ -51,29 +51,29 @@ discard block |
||
51 | 51 | $sysID = urlencode(systemID($cleanString)); |
52 | 52 | |
53 | 53 | //Check if we get a system back, otherwise check for partials |
54 | - if(empty($sysID)) |
|
54 | + if (empty($sysID)) |
|
55 | 55 | { |
56 | 56 | $search = "http://tools.pandemic-legion.pl/api/search/{$cleanString}"; |
57 | 57 | $search = json_decode(file_get_contents($search)); |
58 | 58 | $tot = 0; |
59 | 59 | $res = array(); |
60 | - foreach ($search as $s){ |
|
61 | - if ($s->type == "system"){ |
|
60 | + foreach ($search as $s) { |
|
61 | + if ($s->type == "system") { |
|
62 | 62 | $tot++; |
63 | 63 | $res[] = $s->name; |
64 | 64 | } |
65 | 65 | } |
66 | - if ($tot == 0){ |
|
66 | + if ($tot == 0) { |
|
67 | 67 | return $this->message->reply('**Error:** no data available'); |
68 | 68 | } |
69 | - if ($tot == 1){ |
|
69 | + if ($tot == 1) { |
|
70 | 70 | $sysID = urlencode(systemID($res[0])); |
71 | - if(empty($sysID)){ |
|
71 | + if (empty($sysID)) { |
|
72 | 72 | return $this->message->reply('**Error:** no data available'); |
73 | 73 | } |
74 | 74 | } |
75 | - if ($tot > 1){ |
|
76 | - $res = implode(", ",$res); |
|
75 | + if ($tot > 1) { |
|
76 | + $res = implode(", ", $res); |
|
77 | 77 | return $this->message->reply("**Error:** Did you mean one of these? {$res}"); |
78 | 78 | } |
79 | 79 | } |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | $regionDetails = regionDetails($regionID); |
92 | 92 | $regionName = $regionDetails['name']; |
93 | 93 | |
94 | - $thisMonth = (string)date('Ym'); |
|
95 | - $lastMonth = (string)date('Ym', strtotime('first day of previous month')); |
|
94 | + $thisMonth = (string) date('Ym'); |
|
95 | + $lastMonth = (string) date('Ym', strtotime('first day of previous month')); |
|
96 | 96 | |
97 | 97 | $thisMonthKill = $json->months->$thisMonth->shipsDestroyed; |
98 | 98 | $lastMonthKill = $json->months->$lastMonth->shipsDestroyed; |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | $activeChars = $activePVP->characters->count; |
103 | 103 | |
104 | 104 | $sysName = $systemDetails['name']; |
105 | - $secStatus = round($systemDetails['security_status'],2); |
|
105 | + $secStatus = round($systemDetails['security_status'], 2); |
|
106 | 106 | |
107 | 107 | $npc = "https://api.eveonline.com/map/kills.xml.aspx"; |
108 | 108 | $npc = new SimpleXMLElement(file_get_contents($npc)); |
109 | - foreach($npc->result->rowset->row as $row){ |
|
110 | - if($row->attributes()->solarSystemID == $sysID){ |
|
109 | + foreach ($npc->result->rowset->row as $row) { |
|
110 | + if ($row->attributes()->solarSystemID == $sysID) { |
|
111 | 111 | $npcKills = $row->attributes()->factionKills; |
112 | 112 | $podKills = $row->attributes()->podKills; |
113 | 113 | } |