Passed
Branch master (29155b)
by
unknown
03:29
created

notifications::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 3
dl 0
loc 21
rs 9.3142
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  keyID
32
 * @property  vCode
33
 * @property string allianceOnly
34
 */
35
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...
36
{
37
    /**
38
     * @var
39
     */
40
    var $config;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $config.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
41
    /**
42
     * @var
43
     */
44
    var $discord;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $discord.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
45
    /**
46
     * @var
47
     */
48
    var $logger;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $logger.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
49
    /**
50
     * @var
51
     */
52
    var $nextCheck;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $nextCheck.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
53
    /**
54
     * @var
55
     */
56
    var $keys;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $keys.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
57
    /**
58
     * @var
59
     */
60
    var $keyCount;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $keyCount.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
61
    /**
62
     * @var
63
     */
64
    var $toDiscordChannel;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $toDiscordChannel.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
65
    /**
66
     * @var
67
     */
68
    var $newestNotificationID;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $newestNotificationID.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
69
    /**
70
     * @var
71
     */
72
    var $maxID;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $maxID.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
73
    /**
74
     * @var
75
     */
76
    var $charApi;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $charApi.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
77
    /**
78
     * @var
79
     */
80
    var $corpApi;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $corpApi.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
81
    /**
82
     * @var
83
     */
84
    var $alliApi;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $alliApi.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
85
    public $fuelChannel;
86
    public $fuelSkip;
87
    public $keyID;
88
    public $vCode;
89
    public $characterID;
90
    public $guild;
91
92
    /**
93
     * @param $config
94
     * @param $discord
95
     * @param $logger
96
     */
97
    function init($config, $discord, $logger)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
98
    {
99
        $this->config = $config;
100
        $this->discord = $discord;
101
        $this->logger = $logger;
102
        $this->toDiscordChannel = $config["plugins"]["notifications"]["channelID"];
103
        $this->allianceOnly = strtolower($config["plugins"]["notifications"]["allianceOnly"]);
104
        $this->fuelChannel = $config["plugins"]["fuel"]["channelID"];
105
        $this->fuelSkip = $config["plugins"]["fuel"]["skip"];
106
        $this->newestNotificationID = getPermCache("newestNotificationID");
107
        $this->maxID = 0;
108
        $this->keyID = $config["eve"]["apiKeys"]["user1"]["keyID"];
109
        $this->vCode = $config["eve"]["apiKeys"]["user1"]["vCode"];
110
        $this->characterID = $config["eve"]["apiKeys"]["user1"]["characterID"];
111
        $this->guild = $config["bot"]["guild"];
112
        //Refresh check at bot start
113
        setPermCache("notificationsLastChecked{$this->keyID}",  time() - 5);
114
        if (is_null($this->allianceOnly)) {
115
            $this->allianceOnly = "false";
116
        }
117
    }
118
119
    /**
120
     *
121
     */
122 View Code Duplication
    function tick()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
123
    {
124
        $lastChecked = getPermCache("notificationsLastChecked{$this->keyID}");
125
        $keyID = $this->keyID;
126
        $vCode = $this->vCode;
127
        $characterID = $this->characterID;
128
129
        if ($lastChecked <= time()) {
130
            $this->logger->addInfo("Notifications: Checking API Key {$keyID} for notifications..");
131
            $this->getNotifications($keyID, $vCode, $characterID);
132
        }
133
134
    }
135
136
    /**
137
     * @param $keyID
138
     * @param $vCode
139
     * @param $characterID
140
     * @return null
141
     */
142
    function getNotifications($keyID, $vCode, $characterID)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
    {
144
        $discord = $this->discord;
145
146
        try {
147
            $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
148
            $xml = makeApiRequest($url);
149
            date_default_timezone_set('UTC');
150
            $cached = $xml->cachedUntil[0];
151
            $baseUnix = strtotime($cached);
152
            $cacheClr = $baseUnix - 13500;
153
            if (!isset($this->fuelChannel)) {
154
                $this->fuelChannel = $this->toDiscordChannel;
155
            }
156 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...
157
                $weirdTime = time() + 1830;
158
                $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime);
159
                setPermCache("notificationsLastChecked{$keyID}", $weirdTime);
160
            } else {
161
                $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr);
162
                setPermCache("notificationsLastChecked{$keyID}", $cacheClr);
163
            }
164
            $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
165
                "SimpleXMLElement", LIBXML_NOCDATA)), true);
166
            $data = $data["result"]["rowset"]["row"];
167
            // If there is no data, just quit..
168
            if (empty($data)) {
169
                return;
170
            }
171
            $fixedData = array();
172
            // Sometimes there is only ONE notification, so.. yeah..
173
            if (isset($data["@attributes"])) {
174
                $fixedData[] = $data["@attributes"];
175
            }
176
            if (count($data) > 1) {
177
                foreach ($data as $multiNotif) {
178
                    $fixedData[] = $multiNotif["@attributes"];
179
                }
180
            }
181
            foreach ($fixedData as $notification) {
182
                $notificationID = $notification["notificationID"];
183
                $typeID = $notification["typeID"];
184
                $sentDate = $notification["sentDate"];
185
                $channelID = $this->toDiscordChannel;
186
                if ($notificationID > $this->newestNotificationID) {
187
                    $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID,
188
                        $notificationID));
189
                    switch ($typeID) {
190 View Code Duplication
                        case 5: // War Declared
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...
191
                            $defAllianceID = trim(explode(": ", $notificationString[0])[1]);
192
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
193
                            $defAllianceName = apiCharacterName($defAllianceID);
194
                            $aggAllianceName = apiCharacterName($aggAllianceID);
195
                            $msg = "@everyone | War declared by {$aggAllianceName} against {$defAllianceName}. Fighting begins in roughly 24 hours.";
196
                            break;
197
                        case 6: // Corp joins war (Not enough info in api to say who the 3rd party is)
198
                            $defAllianceID = trim(explode(": ", $notificationString[0])[1]);
199
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
200
                            $defAllianceName = apiCharacterName($defAllianceID);
201
                            $aggAllianceName = apiCharacterName($aggAllianceID);
202
                            $msg = "The war between {$aggAllianceName} and {$defAllianceName} has been joined by a third party. This new group may begin fighting in roughly 24 hours.";
203
                            break;
204 View Code Duplication
                        case 7: // War Declared corp
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...
205
                            $defCorpID = trim(explode(": ", $notificationString[0])[1]);
206
                            $aggCorpID = trim(explode(": ", $notificationString[2])[1]);
207
                            $defCorpName = apiCharacterName($defCorpID);
208
                            $aggCorpName = apiCharacterName($aggCorpID);
209
                            $msg = "@everyone | War declared by {$aggCorpName} against {$defCorpName}. Fighting begins in roughly 24 hours.";
210
                            break;
211 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...
212
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
213
                            $aggAllianceName = apiCharacterName($aggAllianceID);
214
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
215
                            break;
216
                        case 10: // Bill issued
217
                            $msg = "skip";
218
                            break;
219
                        case 13: // Bill issued
220
                            $msg = "skip";
221
                            break;
222
                        case 14: // Bounty payment
223
                            $msg = "skip";
224
                            break;
225
                        case 16: // Mail
226
                            $msg = "skip";
227
                            break;
228
                        case 19: // corp tax changed
229
                            $corpID = trim(explode(": ", $notificationString[0])[1]);
230
                            $corpName = apiCharacterName($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 21: // member left corp
239
                            $msg = "skip";
240
                            break;
241 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...
242
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
243
                            $aggAllianceName = apiCharacterName($aggAllianceID);
244
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
245
                            break;
246
                        case 34: // Noob ship
247
                            $msg = "skip";
248
                            break;
249
                        case 35: // Insurance payment
250
                            $msg = "skip";
251
                            break;
252 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...
253
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
254
                            $systemName = apiCharacterName($solarSystemID);
255
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
256
                            $allianceName = apiCharacterName($allianceID);
257
                            $msg = "{$allianceName} has lost control of **{$systemName}**";
258
                            break;
259 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...
260
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
261
                            $systemName = apiCharacterName($solarSystemID);
262
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
263
                            $allianceName = apiCharacterName($allianceID);
264
                            $msg = "{$allianceName} now controls **{$systemName}**";
265
                            break;
266
                        case 52: // clone revoked
267
                            $msg = "skip";
268
                            break;
269
                        case 54: // insurance
270
                            $msg = "skip";
271
                            break;
272
                        case 57: // jump clone destruction
273
                            $msg = "skip";
274
                            break;
275
                        case 71: // Mission Expiration
276
                            $msg = "skip";
277
                            break;
278
                        case 75: // POS / POS Module under attack
279
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
280
                            $aggAllianceName = apiCharacterName($aggAllianceID);
281
                            $aggCorpID = trim(explode(": ", $notificationString[1])[1]);
282
                            $aggCorpName = apiCharacterName($aggCorpID);
283
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
284
                            $aggCharacterName = apiCharacterName($aggID);
285
                            $moonID = trim(explode(": ", $notificationString[5])[1]);
286
                            $moonName = apiCharacterName($moonID);
287
                            $solarSystemID = trim(explode(": ", $notificationString[7])[1]);
288
                            $typeID = trim(explode(": ", $notificationString[8])[1]);
289
                            $typeName = apiTypeName($typeID);
290
                            $systemName = apiCharacterName($solarSystemID);
291
                            $msg = "**{$typeName}** under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}).";
292
                            if ($this->allianceOnly == "true") {
293
                                $msg = "skip";
294
                            }
295
                            break;
296
                        case 76: // Tower resource alert
297
                            $moonID = trim(explode(": ", $notificationString[2])[1]);
298
                            $moonName = apiCharacterName($moonID);
299
                            $solarSystemID = trim(explode(": ", $notificationString[3])[1]);
300
                            $systemName = apiCharacterName($solarSystemID);
301
                            $blocksRemaining = trim(explode(": ", $notificationString[6])[1]);
302
                            $typeID = trim(explode(": ", $notificationString[7])[1]);
303
                            $channelID = $this->fuelChannel;
304
                            $typeName = apiTypeName($typeID);
305
                            $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
306
                            if ($this->fuelSkip == "true" || $this->allianceOnly == "true") {
307
                                $msg = "skip";
308
                            }
309
310
                            break;
311
                        case 88: // IHUB is being attacked
312
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
313
                            $aggAllianceName = apiCharacterName($aggAllianceID);
314
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
315
                            $aggCorpName = apiCharacterName($aggCorpID);
316
                            $aggID = trim(explode(": ", $notificationString[1])[1]);
317
                            $aggCharacterName = apiCharacterName($aggID);
318
                            $armorValue = trim(explode(": ", $notificationString[3])[1]);
319
                            $hullValue = trim(explode(": ", $notificationString[4])[1]);
320
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
321
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
322
                            $systemName = apiCharacterName($solarSystemID);
323
                            $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
324
                            break;
325
                        case 93: // Customs office is being attacked
326
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
327
                            $aggAllianceName = apiCharacterName($aggAllianceID);
328
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
329
                            $aggCorpName = apiCharacterName($aggCorpID);
330
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
331
                            $aggCharacterName = apiCharacterName($aggID);
332
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
333
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
334
                            $systemName = apiCharacterName($solarSystemID);
335
                            $msg = "Customs Office under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}";
336
                            if ($this->allianceOnly == "true") {
337
                                $msg = "skip";
338
                            }
339
                            break;
340
                        case 94: // POCO Reinforced
341
                            $msg = "Customs Office reinforced.";
342
                            break;
343
                        case 95: // IHub Transfer
344
                            $msg = "skip";
345
                            break;
346
                        case 102: // War support offer? I think?
347
                            $msg = "skip";
348
                            break;
349
                        case 103: // War support offer? I think?
350
                            $msg = "skip";
351
                            break;
352
                        case 111: // Bounty
353
                            $msg = "skip";
354
                            break;
355
                        case 128: // Corp App
356
                            $msg = "skip";
357
                            break;
358
                        case 129: // App denied
359
                            $msg = "skip";
360
                            break;
361
                        case 130: // Corp app withdrawn?
362
                            $msg = "skip";
363
                            break;
364
                        case 135: // ESS stolen
365
                            $msg = "skip";
366
                            break;
367
                        case 138: // Clone activation
368
                            $msg = "skip";
369
                            break;
370
                        case 140: // Kill report
371
                            $msg = "skip";
372
                            break;
373
                        case 141: // Kill report
374
                            $msg = "skip";
375
                            break;
376 View Code Duplication
                        case 147: // Entosis has started
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...
377
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
378
                            $systemName = apiCharacterName($solarSystemID);
379
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
380
                            $typeName = apiTypeName($typeID);
381
                            $msg = "Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
382
                            break;
383 View Code Duplication
                        case 148: // Entosis enabled a module ??????
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...
384
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
385
                            $systemName = apiCharacterName($solarSystemID);
386
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
387
                            $typeName = apiTypeName($typeID);
388
                            $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
389
                            break;
390 View Code Duplication
                        case 149: // Entosis disabled a module
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...
391
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
392
                            $systemName = apiCharacterName($solarSystemID);
393
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
394
                            $typeName = apiTypeName($typeID);
395
                            $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
396
                            break;
397 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...
398
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
399
                            $systemName = apiCharacterName($solarSystemID);
400
                            $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
401
                            break;
402 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...
403
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
404
                            $systemName = apiCharacterName($solarSystemID);
405
                            $msg = "Command nodes decloaking for **{$systemName}**";
406
                            break;
407 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...
408
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
409
                            $systemName = apiCharacterName($solarSystemID);
410
                            $msg = "Entosis successful, TCU in **{$systemName}** has been destroyed.";
411
                            break;
412 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...
413
                            $solarSystemID = trim(explode(": ", $notificationString[1])[1]);
414
                            $systemName = apiCharacterName($solarSystemID);
415
                            $msg = "Station in **{$systemName}** has now entered freeport mode.";
416
                            break;
417 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...
418
                            $corpName = trim(explode(": ", $notificationString[1])[1]);
419
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
420
                            $systemName = apiCharacterName($solarSystemID);
421
                            $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**.";
422
                            break;
423
                        case 184: //  Citadel under attack
424
                            $aggID = trim(explode(": ", $notificationString[7])[1]);
425
                            $aggCharacterName = apiCharacterName($aggID);
426
                            $solarSystemID = trim(explode(": ", $notificationString[15])[1]);
427
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
428
                            $aggAllianceName = apiCharacterName($aggAllianceID);
429
                            $aggCorpID = trim(explode("- ", $notificationString[11])[1]);
430
                            $aggCorpName = apiCharacterName($aggCorpID);
431
                            $systemName = apiCharacterName($solarSystemID);
432
                            $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName}).";
433
                            break;
434 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...
435
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
436
                            $systemName = apiCharacterName($solarSystemID);
437
                            $msg = "Citadel now online in **{$systemName}**.";
438
                            break;
439 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...
440
                            $corpID = trim(explode("- ", $notificationString[3])[1]);
441
                            $corpName = apiCharacterName($corpID);
442
                            $solarSystemID = trim(explode(": ", $notificationString[5])[1]);
443
                            $systemName = apiCharacterName($solarSystemID);
444
                            $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed.";
445
                            break;
446
                        case 199: // citadel delivery
447
                            $msg = "skip";
448
                            break;
449
                        default: // Unknown typeID
450
                            $string = implode(" ", $notificationString);
451
                            $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}";
452
                            break;
453
                    }
454
455
                    if ($msg == "skip") {
456
                        return null;
457
                    }
458
                    $this->logger->addInfo("Notifications: Notification sent to channel {$this->toDiscordChannel}, Message - {$msg}");
459
                    $guild = $discord->guilds->get('id', $this->guild);
460
                    $channel = $guild->channels->get('id', $channelID);
461
                    $channel->sendMessage($msg, false);
462
                    // Find the maxID so we don't output this message again in the future
463
                    $this->maxID = max($notificationID, $this->maxID);
464
                    $this->newestNotificationID = $this->maxID;
465
                    setPermCache("newestNotificationID", $this->maxID);
466
                }
467
            }
468
469
            $this->logger->addInfo("Notifications: Next Notification Check At: {$cacheTimer} EVE Time");
470
        } catch (Exception $e) {
471
            $this->logger->addInfo("Notifications: Notification Error: " . $e->getMessage());
472
        }
473
        return null;
474
    }
475
476
    /**
477
     * @param $keyID
478
     * @param $vCode
479
     * @param $characterID
480
     * @param $notificationID
481
     * @return string
482
     */
483
    function getNotificationText($keyID, $vCode, $characterID, $notificationID)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
484
    {
485
        $url = "https://api.eveonline.com/char/NotificationTexts.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&IDs={$notificationID}";
486
        $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
487
            "SimpleXMLElement", LIBXML_NOCDATA)), true);
488
        $data = $data["result"]["rowset"]["row"];
489
        return $data;
490
    }
491
492
    /**
493
     *
494
     */
495
    function onMessage()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
496
    {
497
    }
498
499
500
    /**
501
     * @return array
502
     */
503
    function information()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
504
    {
505
        return array(
506
            "name" => "",
507
            "trigger" => array(""),
508
            "information" => "");
509
    }
510
}
511