Passed
Pull Request — master (#198)
by
unknown
02:40
created

authCheck::checkAuthState()   C

Complexity

Conditions 14
Paths 32

Size

Total Lines 79
Code Lines 43

Duplication

Lines 8
Ratio 10.13 %

Importance

Changes 0
Metric Value
cc 14
eloc 43
nc 32
nop 0
dl 8
loc 79
rs 5.1058
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
/**
28
 * Class fileAuthCheck
29
 * @property int nextCheck
30
 */
31
class authCheck
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...
32
{
33
34
    /**
35
     * @var
36
     */
37
    private $active;
38
    private $config;
39
    private $discord;
40
    private $logger;
41
    private $db;
42
    private $dbUser;
43
    private $dbPass;
44
    private $dbName;
45
    private $guildID;
46
    private $exempt;
47
    private $corpTickers;
48
    private $nameEnforce;
49
    private $standingsBased;
50
    private $apiKey;
51
    private $authGroups;
52
    private $alertChannel;
53
    private $nameCheck;
54
55
    /**
56
     * @param $config
57
     * @param $discord
58
     * @param $logger
59
     */
60
    public function init($config, $discord, $logger)
61
    {
62
        $this->active = true;
63
        $this->config = $config;
64
        $this->discord = $discord;
65
        $this->logger = $logger;
66
        $this->db = $config['database']['host'];
67
        $this->dbUser = $config['database']['user'];
68
        $this->dbPass = $config['database']['pass'];
69
        $this->dbName = $config['database']['database'];
70
        $this->guildID = $config['bot']['guild'];
71
        $this->exempt = $config['plugins']['auth']['exempt'];
72
        $this->corpTickers = $config['plugins']['auth']['corpTickers'];
73
        $this->nameEnforce = $config['plugins']['auth']['nameEnforce'];
74
        $this->standingsBased = $config['plugins']['auth']['standings']['enabled'];
75
        $this->apiKey = $config['eve']['apiKeys'];
76
        $this->authGroups = $config['plugins']['auth']['authGroups'];
77
        $this->alertChannel = $config['plugins']['auth']['alertChannel'];
78
        $this->nextCheck = 0;
79
80
        //Set name check to happen if corpTicker or nameEnforce is set
81
        if ($this->nameEnforce === 'true' || $this->corpTickers === 'true') {
82
            $this->nameCheck = 'true';
83
        }
84
85
        //check if cache has been set
86
        $permsChecked = getPermCache('permsLastChecked');
87
        $namesChecked = getPermCache('nextRename');
88
        if ($namesChecked === NULL) {
89
            setPermCache('nextRename', time());
90
        }
91
92
        //if not set set for now (30 minutes from now for role removal)
93
        if ($permsChecked === NULL) {
94
            setPermCache('permsLastChecked', time() - 1);
95
        }
96
97
        // If config is outdated
98
        if (null === $this->authGroups) {
99
            $msg = '**Auth Failure:** Please update the bots config to the latest version.';
100
            queueMessage($msg, $this->alertChannel, $this->guildID);
101
            $this->logger->addInfo($msg);
102
            $this->active = false;
103
        }
104
105
    }
106
107
    public function tick()
108
    {
109
        // What was the servers last reported state
110
        $lastStatus = getPermCache('serverState');
111
        if ($this->active && $lastStatus === 'online') {
112
            $permsChecked = getPermCache('permsLastChecked');
113
            $namesChecked = getPermCache('nextRename');
114
            $standingsChecked = getPermCache('nextStandingsCheck');
115
116
            if ($permsChecked <= time()) {
117
                $this->logger->addInfo('AuthCheck: Checking for users who have left corp/alliance....');
118
                $this->checkPermissions();
119
                $this->logger->addInfo('AuthCheck: Corp/alliance check complete.');
120
            }
121
122
            if ($this->nameCheck === 'true' && $namesChecked <= time()) {
123
                $this->logger->addInfo('AuthCheck: Resetting player names....');
124
                $this->nameReset();
125
                $this->logger->addInfo('AuthCheck: Names reset.');
126
            }
127
128
            if ($this->standingsBased === 'true' && $standingsChecked <= time()) {
129
                $this->logger->addInfo('AuthCheck: Updating Standings');
130
                $this->standingsUpdate();
131
                $this->logger->addInfo('AuthCheck: Standings Updated');
132
            }
133
        }
134
    }
135
136
    // remove user roles
137
    private function removeRoles($member)
138
    {
139
        $discordNick = $member->nick ?: $member->username;
140
        $dbh = new PDO("mysql:host={$this->db};dbname={$this->dbName}", $this->dbUser, $this->dbPass);
141
        $rows = array_column($dbh->query('SELECT discordID, characterID, eveName, role FROM authUsers')->fetchAll(), null, 'discordID');
142
        $roleRemoved = false;
143
        if (null === $member->roles)
144
            continue;
145
        if (!isset($rows[$member->id])) {
146
            foreach ($member->roles as $role) {
147
                if (!in_array($role->name, $this->exempt, true)) {
148
                    $roleRemoved = true;
149
                    $member->removeRole($role);
150
                    $this->discord->guilds->get('id', $this->guildID)->members->save($member);
151
                }
152
            }
153
        }
154
        if ($roleRemoved) {
155
            $this->logger->addInfo("AuthCheck: Roles removed from $discordNick");
156
            $msg = "Discord roles removed from $discordNick";
157
            queueMessage($msg, $this->alertChannel, $this->guildID);
158
        }
159
    }
160
    /**
161
     * @return null
162
     */
163
164
    //Check user corp/alliance affiliation
165
    //Remove members who have roles but never authed
166
    private function checkPermissions()
167
    {
168
        $rows = array();
0 ignored issues
show
Unused Code introduced by
$rows is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
169
        $dbh = new PDO("mysql:host={$this->db};dbname={$this->dbName}", $this->dbUser, $this->dbPass);
170
        $rows = array_column($dbh->query('SELECT discordID, characterID, eveName, role FROM authUsers')->fetchAll(), null, 'discordID');
171
172
        //Set empty arrays
173
        $corpArray = array_column($this->authGroups, 'corpID');
174
        $allianceArray = array_column($this->authGroups, 'allianceID');
175
176
        foreach ($this->discord->guilds->get('id', $this->guildID)->members as $member) {
177
            $discordID = $member->getIdAttribute();
178
            $discordNick = $member->nick ?: $member->getUsernameAttribute();
179
            if ($member->getRolesAttribute()->isEmpty()) {
180
                continue;
181
            }
182
            if ($this->discord->id == $discordID) {
183
                continue;
184
            }
185
            $this->logger->addDebug("AuthCheck: Username: $discordNick");
186
            if (!isset($rows[$discordID])) {
187
                $this->logger->addInfo("AuthCheck: User [$discordNick] not found in database.");
188
                $this->removeRoles($member);
189
                continue;
190
            }
191
            $charID = $rows[$discordID]['characterID'];
192
193
            // corporation membership check
194
            for ($i=0; $i<3; $i++) {
195
                $character = characterDetails($charID);
196
                //if (isset($character['corporation_id']) && in_array($character['corporation_id'], $corpArray))
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
197
                if (!is_null($character))
198
                    break;
199
                //Postpone check if ESI is down to prevent timeouts
200
                if (isset($character['error']) && $character['error'] === 'The datasource tranquility is temporarily unavailable') {
201
                    $this->logger->addInfo('AuthCheck: The datasource tranquility is temporarily unavailable, check canceled.');
202
                    $nextCheck = time() + 10800;
203
                    setPermCache('permsLastChecked', $nextCheck);
204
                    return;
205
                }
206
            }
207 View Code Duplication
            if (is_null($character) || isset($character['error'])) {
0 ignored issues
show
Bug introduced by
The variable $character does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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...
208
                $this->logger->addInfo('AuthCheck: characterDetails lookup failed.');
209
                continue;
210
            } elseif (isset($character['corporation_id']) && in_array($character['corporation_id'], $corpArray)) {
211
                continue; // user is in a valid corporation, stop checking
212
            }
213
214
            // alliance membership check
215
            for ($i=0; $i<3; $i++) {
216
                $corporationDetails = corpDetails($corporationID);
0 ignored issues
show
Bug introduced by
The variable $corporationID does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
217
                if (!is_null($corporationDetails))
218
                    break;
219
            }
220 View Code Duplication
            if (is_null($corporationDetails) || isset($corporationDetails['error'])) {
0 ignored issues
show
Bug introduced by
The variable $corporationDetails does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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...
221
                $this->logger->addInfo('AuthCheck: corpDetails lookup failed.');
222
                continue;
223
            } else if (isset($corporationDetails['alliance_id']) && in_array($corporationDetails['alliance_id'], $allianceArray)) {
224
                continue; // user is in a valid alliance, stop checking
225
            }
226
227
            //check if user authed based on standings
228
            $role = $rows[$discordID]['role'];
229
            $standings = null;
230
            if ($role === 'blue' || 'neut' || 'red') {
231
                $allianceContacts = getContacts($allianceID);
0 ignored issues
show
Bug introduced by
The variable $allianceID does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
Are you sure the assignment to $allianceContacts is correct as getContacts($allianceID) (which targets getContacts()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
232
                $corpContacts = getContacts($corporationID);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $corpContacts is correct as getContacts($corporationID) (which targets getContacts()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
233
                if ($role === 'blue' && ((int) $allianceContacts['standing'] === 5 || 10 || (int) $corpContacts['standing'] === 5 || 10)) {
234
                    $standings = 1;
235
                }
236
                if ($role === 'red' && ((int) $allianceContacts['standing'] === -5 || -10 || (int) $corpContacts['standing'] === -5 || -10)) {
237
                    $standings = 1;
238
                }
239
                if ($role === 'neut' && ((int) $allianceContacts['standing'] === 0 || (int) $corpContacts['standing'] === 0 || (@(int) $allianceContacts['standings'] === null || '' && @(int) $corpContacts['standings'] === null || ''))) {
240
                    $standings = 1;
241
                }
242
            }
243
            if ($standings)
0 ignored issues
show
Bug Best Practice introduced by
The expression $standings of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
244
                continue; //keep the user based on standings
245
246
            // User failed all checks, deactivate user in database
247
            $sql = "UPDATE authUsers SET active='no' WHERE discordID='$discordID'";
248
            $this->logger->addInfo("AuthCheck: {$eveName} account has been deactivated as they are no longer in a correct corp/alliance.");
0 ignored issues
show
Bug introduced by
The variable $eveName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
249
            $dbh->query($sql);
250
            $this->removeRoles($member);
251
        }
252
        setPermCache('permsLastChecked', time() + 1800);
253
    }
254
255
    private function nameReset()
256
    {
257
        //Get guild object
258
        $guild = $this->discord->guilds->get('id', $this->guildID);
259
260
        //Get name queue status
261
        $x = (int) getPermCache('nameQueueState');
262
263
        //Establish connection to mysql
264
        $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName);
265
        $sql = "SELECT id FROM authUsers WHERE active='yes'";
266
        $count = $conn->query($sql);
267
        $rowAmount = round($count->num_rows / 2);
268
        if ($x === 1) {
269
            $sql = "SELECT characterID, discordID, eveName  FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount} OFFSET {$rowAmount}";
270
            setPermCache('nameQueueState', 0);
271
        } else {
272
            $sql = "SELECT characterID, discordID, eveName  FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount}";
273
            setPermCache('nameQueueState', 1);
274
        }
275
        $result = $conn->query($sql);
276
277
        if (@$result->num_rows >= 1) {
278
            while ($rows = $result->fetch_assoc()) {
279
                $charID = $rows['characterID'];
280
                $discordID = $rows['discordID'];
281
                $member = $guild->members->get('id', $discordID);
282
                $eveName = $rows['eveName'];
283
                //Check if member has roles
284
                if (null === @$member->roles) {
285
                    continue;
286
                }
287
288
                //Get current nickname
289
                $guild = $this->discord->guilds->get('id', $this->guildID);
290
                $member = $guild->members->get('id', $discordID);
291
                $nickName = $member->nick;
292
                $userName = $member->user->username;
293
                //If nick isn't set than make it username
294
                if ($nickName === '' || null === $nickName) {
295
                    $nickName = $userName;
296
                }
297
298
                //Check for bad tickers
299
                if (strpos($nickName, '[U]') !== false) {
300
                    $nickName = str_replace('[U]', '', $nickName);
301
                    queueRename($discordID, $nickName, $this->guildID);
302
                    continue;
303
                }
304
305
                //corp ticker
306
                if ($this->corpTickers === 'true') {
307
                    $timeout = 0;
308
                    $character = characterDetails($charID);
309
                    while (null === $character) { //try 10 times to pull characterDetails
310
                        if ($timeout > 9) {
311
                            continue;
312
                        }
313
                        else{
314
                            $character = characterDetails($charID);
315
                            $timeout++;
316
                        }
317
                    }
318
                    if (!array_key_exists('corporation_id', $character)) {
319
                        continue;
320
                    }
321
                    $corpInfo = getCorpInfo($character['corporation_id']);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $corpInfo is correct as getCorpInfo($character['corporation_id']) (which targets getCorpInfo()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
322
                    //Clean bad entries
323
                    if (@$corpInfo['corpTicker'] === 'U') {
324
                        deleteCorpInfo(@$corpInfo['corpID']);
325
                    }
326
                    $nick = null;
327 View Code Duplication
                    if (null !== @$corpInfo['corpTicker']) {
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...
328
                        $corpTicker = (string) $corpInfo['corpTicker'];
329
                        if ($this->nameEnforce === 'true') {
330
                            $nick = "[{$corpTicker}] {$eveName}";
331
                        } elseif ((string) $nickName === "[{$corpTicker}]") {
332
                            $nick = "[{$corpTicker}] {$userName}";
333
                        } elseif (strpos($nickName, $corpTicker) === false) {
334
                            $nick = "[{$corpTicker}] {$nickName}";
335
                        } elseif (strpos($nickName, $corpTicker) !== false) {
336
                            continue;
337
                        }
338
                        if ($nick !== $nickName) {
339
                            queueRename($discordID, $nick, $this->guildID);
340
                        }
341
                        continue;
342
                    }
343
                    $corporationDetails = corpDetails($character['corporation_id']);
344
                    if (null === $corporationDetails) {
345
                        continue;
346
                    }
347
                    $corpTicker = $corporationDetails['ticker'];
348
                    //Check for bad tickers (ESI ERROR?)
349
                    if (@$corpTicker === 'U') {
350
                        continue;
351
                    }
352
                    $corpName = (string) $corporationDetails['corporation_name'];
353 View Code Duplication
                    if (null !== $corpTicker) {
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...
354
                        if ($this->nameEnforce === 'true') {
355
                            $nick = "[{$corpTicker}] {$eveName}";
356
                        } elseif ((string) $nickName === "[{$corpTicker}]") {
357
                            $nick = "[{$corpTicker}] {$userName}";
358
                        } elseif (strpos($nickName, $corpTicker) === false) {
359
                            $nick = "[{$corpTicker}] {$nickName}";
360
                        } elseif (strpos($nickName, $corpTicker) !== false) {
361
                            continue;
362
                        }
363
                        if ($nick !== $nickName) {
364
                            queueRename($discordID, $nick, $this->guildID);
365
                            addCorpInfo($character['corporation_id'], $corpTicker, $corpName);
366
                        }
367
                        continue;
368
                    }
369
                    continue;
370
                }
371
                $nick = "{$eveName}";
372
                if ($nick !== $nickName) {
373
                    queueRename($discordID, $nick, $this->guildID);
374
                }
375
                continue;
376
            }
377
            $nextCheck = time() + 1800;
378
            setPermCache('nextRename', $nextCheck);
379
            return null;
380
        }
381
        $nextCheck = time() + 1800;
382
        setPermCache('nextRename', $nextCheck);
383
        return null;
384
385
    }
386
387
    private function standingsUpdate()
388
    {
389
        foreach ($this->apiKey as $apiKey) {
390
            if ((string) $apiKey['keyID'] === (string) $this->config['plugins']['auth']['standings']['apiKey']) {
391
                $url = "https://api.eveonline.com/char/ContactList.xml.aspx?keyID={$apiKey['keyID']}&vCode={$apiKey['vCode']}&characterID={$apiKey['characterID']}";
392
                $xml = makeApiRequest($url);
393
                if (empty($xml)) {
394
                    return null;
395
                }
396
                foreach ($xml->result->rowset as $contactType) {
397
                    if ((string) $contactType->attributes()->name === 'corporateContactList' || 'allianceContactList') {
398
                        foreach ($contactType->row as $contact) {
399
                            if (null !== $contact['contactID'] && $contact['contactName'] && $contact['standing']) {
400
                                addContactInfo($contact['contactID'], $contact['contactName'], $contact['standing']);
401
                            }
402
                        }
403
                    }
404
                }
405
            }
406
        }
407
        $nextCheck = time() + 86400;
408
        setPermCache('nextStandingsCheck', $nextCheck);
409
    }
410
}
411