Passed
Pull Request — master (#106)
by Bob
03:51
created

notifications::information()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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
use discord\discord;
28
29
/**
30
 * Class notifications
31
 * @property string allianceOnly
32
 */
33
class notifications
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
{
35
    public $config;
36
    public $discord;
37
    public $logger;
38
    private $toDiscordChannel;
39
    private $newestNotificationID;
40
    private $maxID;
41
    private $apiKey;
42
    private $numberOfKeys;
43
    private $fuelChannel;
44
    private $fuelSkip;
45
    private $guild;
46
47
    /**
48
     * @param $config
49
     * @param $discord
50
     * @param $logger
51
     */
52
    public function init($config, $discord, $logger)
53
    {
54
        $this->config = $config;
55
        $this->discord = $discord;
56
        $this->logger = $logger;
57
        $this->toDiscordChannel = $config['plugins']['notifications']['channelID'];
58
        $this->allianceOnly = strtolower($config['plugins']['notifications']['allianceOnly']);
59
        $this->fuelChannel = $config['plugins']['fuel']['channelID'];
60
        $this->fuelSkip = $config['plugins']['fuel']['skip'];
61
        $this->newestNotificationID = getPermCache('newestNotificationID');
62
        $this->maxID = 0;
63
        $this->apiKey = $config['eve']['apiKeys'];
64
        $this->guild = $config['bot']['guild'];
65
66
        //check if allianceOnly is set
67
        if (null === $this->allianceOnly) {
68
            $this->allianceOnly = 'false';
69
        }
70
71
        //Get number of keys
72
        $x = 0;
73 View Code Duplication
        foreach ($this->apiKey as $apiKey) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
            //Check if api is set
75
            if ($apiKey['keyID'] === '' || $apiKey['vCode'] === '' || $apiKey['characterID'] === null) {
76
                continue;
77
            }
78
            $x++;
79
        }
80
        $this->numberOfKeys = $x;
81
    }
82
83
    /**
84
     *
85
     */
86 View Code Duplication
    public function tick()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        // What was the servers last reported state
89
        $lastStatus = getPermCache('serverState');
90
        if ($lastStatus === 'online') {
91
            foreach ($this->apiKey as $apiKey) {
92
                //Check if api is set
93
                if ($apiKey['keyID'] === '' || $apiKey['vCode'] === '' || $apiKey['characterID'] === null) {
94
                    continue;
95
                }
96
                //Get
97
                $lastChecked = getPermCache('notificationsLastChecked');
98
                if ($lastChecked <= time()) {
99
                    $lastCheckedAPI = getPermCache("notificationsLastChecked{$apiKey['keyID']}");
100
                    if ($lastCheckedAPI <= time()) {
101
                        $this->logger->addInfo("Notifications: Checking API Key {$apiKey['keyID']} for notifications..");
102
                        $this->getNotifications($apiKey['keyID'], $apiKey['vCode'], $apiKey['characterID']);
103
                    }
104
                }
105
            }
106
        }
107
    }
108
109
    /**
110
     * @param $keyID
111
     * @param $vCode
112
     * @param $characterID
113
     * @return null
114
     */
115
    private function getNotifications($keyID, $vCode, $characterID)
116
    {
117
        try {
118
            $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
119
            $xml = makeApiRequest($url);
120
            date_default_timezone_set('UTC');
121
            $cached = $xml->cachedUntil[0];
122
            $baseUnix = strtotime($cached);
123
            $cacheClr = $baseUnix - 13500;
124
            if (null === $this->fuelChannel) {
125
                $this->fuelChannel = $this->toDiscordChannel;
126
            }
127
            //Set timer for next key based on number of keys
128
            $nextKey = (1900 / (int)$this->numberOfKeys) + time();
129
            $nextKeyTime = gmdate('Y-m-d H:i:s', $nextKey);
130
            setPermCache('notificationsLastChecked', $nextKey);
131
            //Set cache timer for api key
132 View Code Duplication
            if ($cacheClr <= time()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
                $weirdTime = time() + 1830;
134
                setPermCache("notificationsLastChecked{$keyID}", $weirdTime);
135
            } else {
136
                setPermCache("notificationsLastChecked{$keyID}", $cacheClr);
137
            }
138
            $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
139
                'SimpleXMLElement', LIBXML_NOCDATA)), true);
140
            // If there is no data, just quit..
141
            if (empty($data['result']['rowset']['row'])) {
142
                return null;
143
            }
144
            $data = $data['result']['rowset']['row'];
145
            $fixedData = array();
146
            // Sometimes there is only ONE notification, so.. yeah..
147
            if (isset($data['@attributes'])) {
148
                $fixedData[] = $data['@attributes'];
149
            }
150
            if (count($data) > 1) {
151
                foreach ($data as $multiNotif) {
152
                    $fixedData[] = $multiNotif['@attributes'];
153
                }
154
            }
155
            foreach ($fixedData as $notification) {
156
                $notificationID = $notification['notificationID'];
157
                $typeID = $notification['typeID'];
158
                $sentDate = $notification['sentDate'];
159
                $channelID = $this->toDiscordChannel;
160
                if ($notificationID > $this->newestNotificationID) {
161
                    $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID, $notificationID));
162
                    switch ($typeID) {
163
                        case 1: // Old
164
                            $msg = 'skip';
165
                            break;
166
                        case 2: // biomassed
167
                            $msg = 'skip';
168
                            break;
169
                        case 3: // medal awarded
170
                            $msg = 'skip';
171
                            break;
172
                        case 4: // alliance bill
173
                            $msg = 'skip';
174
                            break;
175
                        case 5: // War Declared
176
                            $defAllianceID = trim(explode(': ', $notificationString[0])[1]);
177
                            $aggAllianceID = trim(explode(': ', $notificationString[2])[1]);
178
                            $defAllianceName = allianceName($defAllianceID);
179
                            $aggAllianceName = allianceName($aggAllianceID);
180
                            $msg = "@everyone | War declared by {$aggAllianceName} against {$defAllianceName}. Fighting begins in roughly 24 hours.";
181
                            break;
182
                        case 6: // Corp joins war (Not enough info in api to say who the 3rd party is)
183
                            $defAllianceID = trim(explode(': ', $notificationString[0])[1]);
184
                            $aggAllianceID = trim(explode(': ', $notificationString[2])[1]);
185
                            $defAllianceName = allianceName($defAllianceID);
186
                            $aggAllianceName = allianceName($aggAllianceID);
187
                            $msg = "The war between {$aggAllianceName} and {$defAllianceName} has been joined by a third party. This new group may begin fighting in roughly 24 hours.";
188
                            break;
189
                        case 7: // War Declared corp
190
                            $defCorpID = trim(explode(': ', $notificationString[0])[1]);
191
                            $aggCorpID = trim(explode(': ', $notificationString[2])[1]);
192
                            $defCorpName = corpName($defCorpID);
193
                            $aggCorpName = corpName($aggCorpID);
194
                            $msg = "@everyone | War declared by {$aggCorpName} against {$defCorpName}. Fighting begins in roughly 24 hours.";
195
                            break;
196 View Code Duplication
                        case 8: // Alliance war invalidated by CONCORD
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
197
                            $aggAllianceID = trim(explode(': ', $notificationString[2])[1]);
198
                            $aggAllianceName = allianceName($aggAllianceID);
199
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
200
                            break;
201
                        case 9: // Pilot bill
202
                            $msg = 'skip';
203
                            break;
204
                        case 10: // Bill issued
205
                            $msg = 'skip';
206
                            break;
207
                        case 11: // Bill stuff
208
                            $msg = 'skip';
209
                            break;
210
                        case 12: // Bill Stuff
211
                            $msg = 'skip';
212
                            break;
213
                        case 13: // Bill issued
214
                            $msg = 'skip';
215
                            break;
216
                        case 14: // Bounty payment
217
                            $msg = 'skip';
218
                            break;
219
                        case 16: // Mail
220
                            $msg = 'skip';
221
                            break;
222
                        case 17: // Corp app
223
                            $msg = 'skip';
224
                            break;
225
                        case 18: // Corp app
226
                            $msg = 'skip';
227
                            break;
228
                        case 19: // corp tax changed
229
                            $corpID = trim(explode(': ', $notificationString[0])[1]);
230
                            $corpName = corpName($corpID);
231
                            $oldTax = trim(explode(': ', $notificationString[2])[1]);
232
                            $newTax = trim(explode(': ', $notificationString[1])[1]);
233
                            $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%";
234
                            if ($this->allianceOnly === 'true') {
235
                                $msg = 'skip';
236
                            }
237
                            break;
238
                        case 20: // Corp news?
239
                            $msg = 'skip';
240
                            break;
241
                        case 21: // member left corp
242
                            $msg = 'skip';
243
                            break;
244 View Code Duplication
                        case 31: // Alliance war invalidated by CONCORD
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
245
                            $aggAllianceID = trim(explode(': ', $notificationString[2])[1]);
246
                            $aggAllianceName = allianceName($aggAllianceID);
247
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
248
                            break;
249
                        case 34: // Noob ship
250
                            $msg = 'skip';
251
                            break;
252
                        case 35: // Insurance payment
253
                            $msg = 'skip';
254
                            break;
255 View Code Duplication
                        case 41: // System lost
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
256
                            $solarSystemID = trim(explode(': ', $notificationString[2])[1]);
257
                            $systemName = systemName($solarSystemID);
258
                            $allianceID = trim(explode(': ', $notificationString[0])[1]);
259
                            $allianceName = allianceName($allianceID);
260
                            $msg = "{$allianceName} has lost control of **{$systemName}**";
261
                            break;
262 View Code Duplication
                        case 43: // System captured
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263
                            $solarSystemID = trim(explode(': ', $notificationString[2])[1]);
264
                            $systemName = systemName($solarSystemID);
265
                            $allianceID = trim(explode(': ', $notificationString[0])[1]);
266
                            $allianceName = allianceName($allianceID);
267
                            $msg = "{$allianceName} now controls **{$systemName}**";
268
                            break;
269
                        case 45: // Tower anchoring
270
                            $msg = 'skip';
271
                            break;
272
                        case 50: // Office Expired
273
                            $msg = 'skip';
274
                            break;
275
                        case 52: // clone revoked
276
                            $msg = 'skip';
277
                            break;
278
                        case 54: // insurance
279
                            $msg = 'skip';
280
                            break;
281
                        case 55: // insurance
282
                            $msg = 'skip';
283
                            break;
284
                        case 57: // jump clone destruction
285
                            $msg = 'skip';
286
                            break;
287
                        case 71: // Mission Expiration
288
                            $msg = 'skip';
289
                            break;
290
                        case 73: // special mission
291
                            $msg = 'skip';
292
                            break;
293
                        case 75: // POS / POS Module under attack
294
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
295
                            $aggAllianceName = allianceName($aggAllianceID);
296
                            $aggCorpID = trim(explode(': ', $notificationString[1])[1]);
297
                            $aggCorpName = corpName($aggCorpID);
298
                            $aggID = trim(explode(': ', $notificationString[2])[1]);
299
                            $aggCharacterName = characterName($aggID);
300
                            $moonID = trim(explode(': ', $notificationString[5])[1]);
301
                            $moonName = apiMoonName($moonID);
302
                            $solarSystemID = trim(explode(': ', $notificationString[7])[1]);
303
                            $typeID = trim(explode(': ', $notificationString[8])[1]);
304
                            $typeName = apiTypeName($typeID);
305
                            $systemName = systemName($solarSystemID);
306
                            $msg = "**{$typeName}** under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}).";
307
                            if ($this->allianceOnly === 'true') {
308
                                $msg = 'skip';
309
                            }
310
                            break;
311
                        case 76: // Tower resource alert
312
                            $moonID = trim(explode(': ', $notificationString[2])[1]);
313
                            $moonName = apiMoonName($moonID);
314
                            $solarSystemID = trim(explode(': ', $notificationString[3])[1]);
315
                            $systemName = systemName($solarSystemID);
316
                            $blocksRemaining = trim(explode(': ', $notificationString[6])[1]);
317
                            $typeID = trim(explode(': ', $notificationString[7])[1]);
318
                            $channelID = $this->fuelChannel;
319
                            $typeName = apiTypeName($typeID);
320
                            $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
321
                            if ($this->fuelSkip === 'true' || $this->allianceOnly === 'true') {
322
                                $msg = 'skip';
323
                            }
324
325
                            break;
326
                        case 88: // IHUB is being attacked
327
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
328
                            $aggAllianceName = allianceName($aggAllianceID);
329
                            $aggCorpID = trim(explode(': ', $notificationString[0])[1]);
330
                            $aggCorpName = corpName($aggCorpID);
331
                            $aggID = trim(explode(': ', $notificationString[1])[1]);
332
                            $aggCharacterName = characterName($aggID);
333
                            $armorValue = trim(explode(': ', $notificationString[3])[1]);
334
                            $hullValue = trim(explode(': ', $notificationString[4])[1]);
335
                            $shieldValue = trim(explode(': ', $notificationString[5])[1]);
336
                            $solarSystemID = trim(explode(': ', $notificationString[6])[1]);
337
                            $systemName = systemName($solarSystemID);
338
                            $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
339
                            break;
340
                        case 89: // Sov level?
341
                            $msg = 'skip';
342
                            break;
343
                        case 93: // Customs office is being attacked
344
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
345
                            $aggAllianceName = allianceName($aggAllianceID);
346
                            $aggCorpID = trim(explode(': ', $notificationString[0])[1]);
347
                            $aggCorpName = corpName($aggCorpID);
348
                            $aggID = trim(explode(': ', $notificationString[2])[1]);
349
                            $aggCharacterName = characterName($aggID);
350
                            $shieldValue = trim(explode(': ', $notificationString[5])[1]);
351
                            $solarSystemID = trim(explode(': ', $notificationString[6])[1]);
352
                            $systemName = systemName($solarSystemID);
353
                            $msg = "Customs Office under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}";
354
                            if ($this->allianceOnly === 'true') {
355
                                $msg = 'skip';
356
                            }
357
                            break;
358
                        case 94: // POCO Reinforced
359
                            $msg = 'Customs Office reinforced.';
360
                            break;
361
                        case 95: // IHub Transfer
362
                            $msg = 'skip';
363
                            break;
364
                        case 100: // Aggressor corp joins war
365
                            $aggCorpID = trim(explode(': ', $notificationString[0])[1]);
366
                            $defCorpID = trim(explode(': ', $notificationString[1])[1]);
367
                            $aggCorpName = corpName($aggCorpID);
368
                            $defCorpName = corpName($defCorpID);
369
                            $msg = "{$aggCorpName} has joined the war against {$defCorpName}.";
370
                            break;
371
                        case 102: // War support offer? I think?
372
                            $msg = 'skip';
373
                            break;
374
                        case 103: // War support offer? I think?
375
                            $msg = 'skip';
376
                            break;
377
                        case 111: // Bounty
378
                            $msg = 'skip';
379
                            break;
380
                        case 113: // Bounty
381
                            $msg = 'skip';
382
                            break;
383
                        case 116: // Kill right
384
                            $msg = 'skip';
385
                            break;
386
                        case 128: // Corp App
387
                            $msg = 'skip';
388
                            break;
389
                        case 129: // App denied
390
                            $msg = 'skip';
391
                            break;
392
                        case 130: // Corp app withdrawn?
393
                            $msg = 'skip';
394
                            break;
395
                        case 135: // ESS stolen
396
                            $msg = 'skip';
397
                            break;
398
                        case 138: // Clone activation
399
                            $msg = 'skip';
400
                            break;
401
                        case 140: // Kill report
402
                            $msg = 'skip';
403
                            break;
404
                        case 141: // Kill report
405
                            $msg = 'skip';
406
                            break;
407
                        case 147: // Entosis has started
408
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
409
                            $systemName = systemName($solarSystemID);
410
                            $typeID = trim(explode(': ', $notificationString[1])[1]);
411
                            $typeName = apiTypeName($typeID);
412
                            $msg = "Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
413
                            break;
414
                        case 148: // Entosis enabled a module ??????
415
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
416
                            $systemName = systemName($solarSystemID);
417
                            $typeID = trim(explode(': ', $notificationString[1])[1]);
418
                            $typeName = apiTypeName($typeID);
419
                            $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
420
                            break;
421
                        case 149: // Entosis disabled a module
422
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
423
                            $systemName = systemName($solarSystemID);
424
                            $typeID = trim(explode(': ', $notificationString[1])[1]);
425
                            $typeName = apiTypeName($typeID);
426
                            $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
427
                            break;
428
                        case 152: // Sov bill
429
                            $msg = 'skip';
430
                            break;
431 View Code Duplication
                        case 160: // Entosis successful
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
432
                            $solarSystemID = trim(explode(': ', $notificationString[2])[1]);
433
                            $systemName = systemName($solarSystemID);
434
                            $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
435
                            break;
436 View Code Duplication
                        case 161: //  Command Nodes Decloaking
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
437
                            $solarSystemID = trim(explode(': ', $notificationString[2])[1]);
438
                            $systemName = systemName($solarSystemID);
439
                            $msg = "Command nodes decloaking for **{$systemName}**";
440
                            break;
441 View Code Duplication
                        case 162: //  TCU Destroyed
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
442
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
443
                            $systemName = systemName($solarSystemID);
444
                            $msg = "Entosis successful, TCU in **{$systemName}** has been destroyed.";
445
                            break;
446 View Code Duplication
                        case 163: //  Outpost freeport
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
447
                            $solarSystemID = trim(explode(': ', $notificationString[1])[1]);
448
                            $systemName = systemName($solarSystemID);
449
                            $msg = "Station in **{$systemName}** has now entered freeport mode.";
450
                            break;
451 View Code Duplication
                        case 165: //  System became Capital
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
452
                            $solarSystemID = trim(explode(': ', $notificationString[1])[1]);
453
                            $systemName = systemName($solarSystemID);
454
                            $allianceID = trim(explode(': ', $notificationString[0])[1]);
455
                            $allianceName = allianceName($allianceID);
456
                            $msg = "**{$systemName}** is now the capital for {$allianceName}.";
457
                            break;
458 View Code Duplication
                        case 167: //  Initiate Self-destruct on TCU
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
459
                            $solarSystemID = trim(explode(': ', $notificationString[3])[1]);
460
                            $systemName = systemName($solarSystemID);
461
                            $msg = "TCU in **{$systemName}** has initiated a self destruct sequence.";
462
                            break;
463 View Code Duplication
                        case 169: //  TCU Self-Destructed
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
464
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
465
                            $systemName = systemName($solarSystemID);
466
                            $msg = "TCU in **{$systemName}** has self destructed.";
467
                            break;
468 View Code Duplication
                        case 182: //  Citadel being anchored
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
469
                            $corpName = trim(explode(': ', $notificationString[1])[1]);
470
                            $solarSystemID = trim(explode(': ', $notificationString[2])[1]);
471
                            $systemName = systemName($solarSystemID);
472
                            $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**.";
473
                            break;
474
                        case 184: //  Citadel under attack
475
                            $aggID = trim(explode(': ', $notificationString[7])[1]);
476
                            $aggCharacterName = characterName($aggID);
477
                            $solarSystemID = trim(explode(': ', $notificationString[15])[1]);
478
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
479
                            $aggAllianceName = allianceName($aggAllianceID);
480
                            $aggCorpID = trim(explode('- ', $notificationString[11])[1]);
481
                            $aggCorpName = corpName($aggCorpID);
482
                            $systemName = systemName($solarSystemID);
483
                            $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName}).";
484
                            break;
485 View Code Duplication
                        case 185: //  Citadel online
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
486
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
487
                            $systemName = systemName($solarSystemID);
488
                            $msg = "Citadel now online in **{$systemName}**.";
489
                            break;
490 View Code Duplication
                        case 188: //  Citadel destroyed
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
491
                            $corpID = trim(explode('- ', $notificationString[3])[1]);
492
                            $corpName = corpName($corpID);
493
                            $solarSystemID = trim(explode(': ', $notificationString[5])[1]);
494
                            $systemName = systemName($solarSystemID);
495
                            $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed.";
496
                            break;
497
                        case 198: // citadel out of fuel
498
                            $solarSystemID = trim(explode(': ', $notificationString[1])[1]);
499
                            $systemName = systemName($solarSystemID);
500
                            $msg = "Citadel in **{$systemName}** has run out of fuel.";
501
                            if ($this->fuelSkip === 'true' || $this->allianceOnly === 'true') {
502
                                $msg = 'skip';
503
                            }
504
                            break;
505
                        case 199: // citadel delivery
506
                            $msg = 'skip';
507
                            break;
508
                        case 1031: // plex delivery
509
                            $msg = 'skip';
510
                            break;
511
                        default: // Unknown typeID
512
                            $string = implode(' ', $notificationString);
513
                            $msg = "typeID {$typeID} is an unmapped notification, please create a Github issue with this entire message and please include what the in-game notification is. {$string}";
514
                            break;
515
                    }
516
517
                    if ($msg === 'skip') {
518
                        return null;
519
                    }
520
                    $this->logger->addInfo('Notifications: Notification queued');
521
                    priorityQueueMessage($msg, $channelID, $this->guild);
522
                    // Find the maxID so we don't output this message again in the future
523
                    $this->maxID = max($notificationID, $this->maxID);
524
                    $this->newestNotificationID = $this->maxID;
525
                    setPermCache('newestNotificationID', $this->maxID);
526
                }
527
            }
528
            $this->logger->addInfo("Notifications: Next Notification Check At: {$nextKeyTime} EVE Time");
529
        } catch (Exception $e) {
530
            $this->logger->addInfo('Notifications: Notification Error: ' . $e->getMessage());
531
        }
532
        return null;
533
    }
534
535
    /**
536
     * @param $keyID
537
     * @param $vCode
538
     * @param $characterID
539
     * @param $notificationID
540
     * @return string
541
     */
542
    private function getNotificationText($keyID, $vCode, $characterID, $notificationID)
543
    {
544
        $url = "https://api.eveonline.com/char/NotificationTexts.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&IDs={$notificationID}";
545
        $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
546
            'SimpleXMLElement', LIBXML_NOCDATA)), true);
547
        $data = $data['result']['rowset']['row'];
548
        return $data;
549
    }
550
}
551