Completed
Push — master ( be6f3f...852d82 )
by Michael
02:34
created
src/Plugins/onMessage/cleverbot.php 1 patch
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -57,16 +57,16 @@
 block discarded – undo
57 57
 
58 58
     /**
59 59
      * cleverBotMessage constructor.
60
-     * @param $message
61
-     * @param $discord
62
-     * @param $log
63
-     * @param $config
64
-     * @param $db
65
-     * @param $curl
66
-     * @param $settings
67
-     * @param $permissions
60
+     * @param Message $message
61
+     * @param Discord $discord
62
+     * @param Logger $log
63
+     * @param Config $config
64
+     * @param Db $db
65
+     * @param cURL $curl
66
+     * @param Settings $settings
67
+     * @param Permissions $permissions
68 68
      * @param $serverConfig
69
-     * @param $users
69
+     * @param Users $users
70 70
      */
71 71
     public function __construct($message, $discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users)
72 72
     {
Please login to merge, or discard this patch.
src/Sovereign.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
     public function run()
155 155
     {
156 156
         // Reap the threads!
157
-        $this->websocket->loop->addPeriodicTimer(600, function () {
157
+        $this->websocket->loop->addPeriodicTimer(600, function() {
158 158
             // Only restart the audioStream pool if it's actually empty..
159 159
             if (empty($this->voice)) {
160 160
                 $this->voice->shutdown();
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         });
174 174
 
175 175
         // Handle the onReady event, and setup some timers and so forth
176
-        $this->websocket->on('ready', function (Discord $discord) {
176
+        $this->websocket->on('ready', function(Discord $discord) {
177 177
             $this->log->addInfo('Websocket connected..');
178 178
 
179 179
             // Update our presence status
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
             // Setup the timers for the timer plugins
196 196
             foreach ($this->onTimer as $command => $data) {
197
-                $this->websocket->loop->addPeriodicTimer($data['timer'], function () use ($data, $discord) {
197
+                $this->websocket->loop->addPeriodicTimer($data['timer'], function() use ($data, $discord) {
198 198
                     try {
199 199
                         $plugin = new $data['class']($discord, $this->log, $this->globalConfig, $this->db, $this->curl, $this->settings, $this->permissions, $this->container->get('serverConfig'), $this->users, $this->extras);
200 200
                         $this->timers->submit($plugin);
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             }
206 206
 
207 207
             // Issue periodically recounting and other things (Needed because of pthreads not putting the entire context into children - leading to some weirdness in some plugins)
208
-            $this->websocket->loop->addPeriodicTimer(600, function () {
208
+            $this->websocket->loop->addPeriodicTimer(600, function() {
209 209
                 $this->extras['memberCount'] = 0;
210 210
                 $this->extras['guildCount'] = 0;
211 211
                 /** @var Guild $guild */
@@ -226,26 +226,26 @@  discard block
 block discarded – undo
226 226
             // If not, stop the session and leave the channel (To save some bandwidth)
227 227
         });
228 228
 
229
-        $this->websocket->on('error', function ($error, $websocket) {
229
+        $this->websocket->on('error', function($error, $websocket) {
230 230
             $this->log->addError('An error occurred on the websocket', [$error->getMessage()]);
231 231
             die(1);
232 232
         });
233 233
 
234
-        $this->websocket->on('close', function ($opCode, $reason) {
234
+        $this->websocket->on('close', function($opCode, $reason) {
235 235
             $this->log->addWarning('Websocket got closed', ['code' => $opCode, 'reason' => $reason]);
236 236
             die(1);
237 237
         });
238 238
 
239
-        $this->websocket->on('reconnecting', function () {
239
+        $this->websocket->on('reconnecting', function() {
240 240
             $this->log->addInfo('Websocket is reconnecting..');
241 241
         });
242 242
 
243
-        $this->websocket->on('reconnected', function () {
243
+        $this->websocket->on('reconnected', function() {
244 244
             $this->log->addInfo('Websocket was reconnected..');
245 245
         });
246 246
 
247 247
         // Handle incoming message logging
248
-        $this->websocket->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
248
+        $this->websocket->on(Event::MESSAGE_CREATE, function(Message $message, Discord $discord) {
249 249
             $this->log->addInfo("Message from {$message->author->username}", [$message->content]);
250 250
 
251 251
             // Don't update data for ourselves..
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         });
258 258
 
259 259
         // Handle plugin running
260
-        $this->websocket->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
260
+        $this->websocket->on(Event::MESSAGE_CREATE, function(Message $message, Discord $discord) {
261 261
             $guildID = $message->getChannelAttribute()->guild_id;
262 262
 
263 263
             // Get server config
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         });
317 317
 
318 318
         // Handle joining a voice channel, and playing.. stuff....
319
-        $this->websocket->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
319
+        $this->websocket->on(Event::MESSAGE_CREATE, function(Message $message, Discord $discord) {
320 320
             // Get the guildID
321 321
             $guildID = $message->getChannelAttribute()->guild_id;
322 322
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
         });
355 355
 
356 356
         // Handle if it's a message for the bot (CleverBot invocation)
357
-        $this->websocket->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
357
+        $this->websocket->on(Event::MESSAGE_CREATE, function(Message $message, Discord $discord) {
358 358
             // If we got highlighted we should probably answer back
359 359
             if (stristr($message->content, $discord->getClient()->id)) {
360 360
                 try {
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         });
367 367
 
368 368
         // Handle presence updates
369
-        $this->websocket->on(Event::PRESENCE_UPDATE, function (PresenceUpdate $presenceUpdate) {
369
+        $this->websocket->on(Event::PRESENCE_UPDATE, function(PresenceUpdate $presenceUpdate) {
370 370
             if ($presenceUpdate->user->id && $presenceUpdate->user->username) {
371 371
                 try {
372 372
                     $this->log->addInfo("Updating presence info for {$presenceUpdate->user->username}");
@@ -379,12 +379,12 @@  discard block
 block discarded – undo
379 379
         });
380 380
 
381 381
         // Create a new cleverbot \nick\ for this new guild
382
-        $this->websocket->on(Event::GUILD_CREATE, function (Guild $guild) {
382
+        $this->websocket->on(Event::GUILD_CREATE, function(Guild $guild) {
383 383
             $cleverBotExists = $this->db->queryField("SELECT serverID FROM cleverbot WHERE serverID = :serverID", "serverID", array(":serverID" => $guild->id));
384 384
             $guildExists = $this->db->queryField("SELECT guildID FROM guilds WHERE guildID = :serverID", "guildID", array(":serverID" => $guild->id));
385 385
 
386 386
             // Only create a new server nick if the cleverbot instance doesn't exist.. (Hopefully cleverbot.io is done deleting them at random)
387
-            if(!isset($cleverBotExists)) {
387
+            if (!isset($cleverBotExists)) {
388 388
                 $this->log->addInfo("Setting up Cleverbot for {$guild->name}");
389 389
                 $serverID = $guild->id;
390 390
                 $result = $this->curl->post('https://cleverbot.io/1.0/create', ['user' => $this->globalConfig->get('user', 'cleverbot'), 'key' => $this->globalConfig->get('key', 'cleverbot')]);
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
                 }
400 400
             }
401 401
 
402
-            if(!isset($guildExists)) {
402
+            if (!isset($guildExists)) {
403 403
                 $this->db->execute("INSERT IGNORE INTO guilds (guildID) VALUES (:guildID)", array(":guildID" => $guild->id));
404 404
 
405 405
                 // Send a hello message to the channel (Only if it's new!)
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -277,20 +277,24 @@  discard block
 block discarded – undo
277 277
                 $content = explode(' ', $message->content);
278 278
                 foreach ($this->onMessage as $command => $data) {
279 279
                     $parts = [];
280
-                    foreach ($content as $index => $c)
281
-                        foreach (explode("\n", $c) as $p)
280
+                    foreach ($content as $index => $c) {
281
+                                            foreach (explode("\n", $c) as $p)
282 282
                             $parts[] = $p;
283
+                    }
283 284
 
284 285
                     if ($parts[0] === $config->prefix . $command) {
285 286
                         // If they are listed under the admins array in the bot config, they're the super admins
286
-                        if (in_array($message->author->id, $this->globalConfig->get('admins', 'permissions')))
287
-                            $userPerms = 3;
287
+                        if (in_array($message->author->id, $this->globalConfig->get('admins', 'permissions'))) {
288
+                                                    $userPerms = 3;
289
+                        }
288 290
                         // If they are guild owner, they're automatically getting permission level 2
289
-                        elseif (null !== $message->getChannelAttribute()->getGuildAttribute()->owner_id && ($message->author->id === $message->getChannelAttribute()->getGuildAttribute()->owner_id))
290
-                            $userPerms = 2;
291
+                        elseif (null !== $message->getChannelAttribute()->getGuildAttribute()->owner_id && ($message->author->id === $message->getChannelAttribute()->getGuildAttribute()->owner_id)) {
292
+                                                    $userPerms = 2;
293
+                        }
291 294
                         // Everyone else are just users
292
-                        else
293
-                            $userPerms = 1;
295
+                        else {
296
+                                                    $userPerms = 1;
297
+                        }
294 298
 
295 299
                         if ($userPerms >= $data['permissions']) {
296 300
                             try {
@@ -331,8 +335,9 @@  discard block
 block discarded – undo
331 335
                 foreach ($this->onVoice as $command => $data) {
332 336
                     $parts = [];
333 337
                     foreach ($content as $index => $c) {
334
-                        foreach (explode("\n", $c) as $p)
335
-                            $parts[] = $p;
338
+                        foreach (explode("\n", $c) as $p) {
339
+                                                    $parts[] = $p;
340
+                        }
336 341
                     }
337 342
 
338 343
                     if ($parts[0] === $config->prefix . $command) {
Please login to merge, or discard this patch.
src/Command/StartCommand.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
         error_reporting(E_ALL);
35 35
         define('DISCORDPHP_STARTTIME', microtime(true));
36 36
         define('BASEDIR', __DIR__);
37
-        define('SOVEREIGN_CONFIG_FILE',  realpath('./' . ltrim($input->getOption('configFile'), '/')));
37
+        define('SOVEREIGN_CONFIG_FILE', realpath('./' . ltrim($input->getOption('configFile'), '/')));
38 38
 
39 39
         // Init the container object
40 40
         $container = getContainer();
Please login to merge, or discard this patch.
src/Lib/Config.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,18 +31,18 @@  discard block
 block discarded – undo
31 31
     /**
32 32
      * @param $configFile
33 33
      */
34
-    public function loadFile ($configFile) {
34
+    public function loadFile($configFile) {
35 35
 
36 36
         if (!file_exists(realpath($configFile))) {
37
-            $this->logger->addError('Config file '.realpath($configFile).' not found.');
37
+            $this->logger->addError('Config file ' . realpath($configFile) . ' not found.');
38 38
             return;
39 39
         }
40 40
 
41 41
         try {
42 42
             $this->config = array_change_key_case(include($configFile), \CASE_LOWER);
43
-            $this->logger->addDebug('Config file loaded: '.realpath($configFile));
43
+            $this->logger->addDebug('Config file loaded: ' . realpath($configFile));
44 44
         } catch (\Exception $e) {
45
-            $this->logger->addError('Failed loading config file ('.realpath($configFile).'): '.$e->getMessage());
45
+            $this->logger->addError('Failed loading config file (' . realpath($configFile) . '): ' . $e->getMessage());
46 46
         }
47 47
     }
48 48
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             return $this->config[$type][$key];
60 60
         }
61 61
 
62
-        $this->logger->addWarning('Config setting not found: ['.$type.']['.$key.']');
62
+        $this->logger->addWarning('Config setting not found: [' . $type . '][' . $key . ']');
63 63
 
64 64
         return $default;
65 65
     }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             return $this->config[$type];
76 76
         }
77 77
 
78
-        $this->logger->addWarning('Config group not found: ['.$type.']');
78
+        $this->logger->addWarning('Config group not found: [' . $type . ']');
79 79
 
80 80
         return array();
81 81
     }
Please login to merge, or discard this patch.
src/Plugins/onMessage/help.php 1 patch
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -96,10 +96,11 @@
 block discarded – undo
96 96
         if (isset($cmd)) {
97 97
             foreach ($plugins as $command => $data) {
98 98
                 if ($command == $cmd) {
99
-                    if ($data["usage"])
100
-                        $this->message->reply("**{$this->channelConfig->prefix}{$command}** _{$data["usage"]}_\r\n {$data["description"]}");
101
-                    else
102
-                        $this->message->reply("**{$this->channelConfig->prefix}{$command}** \r\n {$data["description"]}");
99
+                    if ($data["usage"]) {
100
+                                            $this->message->reply("**{$this->channelConfig->prefix}{$command}** _{$data["usage"]}_\r\n {$data["description"]}");
101
+                    } else {
102
+                                            $this->message->reply("**{$this->channelConfig->prefix}{$command}** \r\n {$data["description"]}");
103
+                    }
103 104
                 }
104 105
             }
105 106
         } else {
Please login to merge, or discard this patch.
src/Plugins/onMessage/porn.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,10 +122,10 @@
 block discarded – undo
122 122
                 "innie" => "https://api.imgur.com/3/gallery/r/innie/time/all/",
123 123
             );
124 124
 
125
-            foreach($categories as $catName => $catURL) {
125
+            foreach ($categories as $catName => $catURL) {
126 126
                 $categoryNames[] = ucfirst($catName);
127
-                if(strtolower($type) == strtolower($catName)) {
128
-                    if(is_array($catURL))
127
+                if (strtolower($type) == strtolower($catName)) {
128
+                    if (is_array($catURL))
129 129
                         $url = $catURL[array_rand($catURL)];
130 130
                     else
131 131
                         $url = $catURL;
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -125,10 +125,11 @@
 block discarded – undo
125 125
             foreach($categories as $catName => $catURL) {
126 126
                 $categoryNames[] = ucfirst($catName);
127 127
                 if(strtolower($type) == strtolower($catName)) {
128
-                    if(is_array($catURL))
129
-                        $url = $catURL[array_rand($catURL)];
130
-                    else
131
-                        $url = $catURL;
128
+                    if(is_array($catURL)) {
129
+                                            $url = $catURL[array_rand($catURL)];
130
+                    } else {
131
+                                            $url = $catURL;
132
+                    }
132 133
                 }
133 134
             }
134 135
 
Please login to merge, or discard this patch.
src/Plugins/onVoice/radio.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -85,18 +85,18 @@  discard block
 block discarded – undo
85 85
         $url = "";
86 86
 
87 87
         // Populate the radioNames, and also get the URL if the person actually defined one
88
-        foreach($radios as $radioName => $radioURL) {
88
+        foreach ($radios as $radioName => $radioURL) {
89 89
             $radioNames[] = ucfirst($radioName);
90 90
             if (strtolower($radioName) == strtolower($radioStation)) {
91 91
                 $url = $radioURL;
92 92
             }
93 93
         }
94 94
 
95
-        if(!$url)
95
+        if (!$url)
96 96
             $message->reply("You can listen to the following radios: " . implode(", ", $radioNames));
97 97
 
98 98
         if (!empty($url)) {
99
-            $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use ($message, $discord, &$webSocket, $log, &$audioStreams, $channel, $curl, $url) {
99
+            $webSocket->joinVoiceChannel($channel)->then(function(VoiceClient $vc) use ($message, $discord, &$webSocket, $log, &$audioStreams, $channel, $curl, $url) {
100 100
                 $guildID = $message->getChannelAttribute()->guild_id;
101 101
 
102 102
                 // Add this audio stream to the array of audio streams
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                 $audioStreams["eveRadio"][$guildID] = new Process(implode(" ", $params));
122 122
                 $audioStreams["eveRadio"][$guildID]->start($webSocket->loop);
123 123
 
124
-                $vc->playRawStream($audioStreams["eveRadio"][$guildID]->stdout)->done(function () use (&$audioStreams, $vc, $guildID) {
124
+                $vc->playRawStream($audioStreams["eveRadio"][$guildID]->stdout)->done(function() use (&$audioStreams, $vc, $guildID) {
125 125
                     $audioStreams["eveRadio"][$guildID]->close();
126 126
                     unset($audioStreams[$guildID]);
127 127
                     $vc->close();
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -92,8 +92,9 @@
 block discarded – undo
92 92
             }
93 93
         }
94 94
 
95
-        if(!$url)
96
-            $message->reply("You can listen to the following radios: " . implode(", ", $radioNames));
95
+        if(!$url) {
96
+                    $message->reply("You can listen to the following radios: " . implode(", ", $radioNames));
97
+        }
97 98
 
98 99
         if (!empty($url)) {
99 100
             $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use ($message, $discord, &$webSocket, $log, &$audioStreams, $channel, $curl, $url) {
Please login to merge, or discard this patch.
src/Plugins/onVoice/radio90s.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 {
19 19
     public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
20 20
     {
21
-        $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use ($message, $discord, $webSocket, $log, &$audioStreams, $channel, $curl) {
21
+        $webSocket->joinVoiceChannel($channel)->then(function(VoiceClient $vc) use ($message, $discord, $webSocket, $log, &$audioStreams, $channel, $curl) {
22 22
             $guildID = $message->getChannelAttribute()->guild_id;
23 23
 
24 24
             // Add this audio stream to the array of audio streams
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
             $vc->setBitrate(128000);
29 29
             $vc->setFrameSize(40);
30 30
 
31
-            $tickQueue = function () use (&$tickQueue, &$vc, &$message, &$channel, &$curl, &$log, &$audioStreams, $guildID) {
31
+            $tickQueue = function() use (&$tickQueue, &$vc, &$message, &$channel, &$curl, &$log, &$audioStreams, $guildID) {
32 32
                 // Get the song we'll be playing this round
33 33
                 $data = $this->getSong($curl, $log);
34 34
                 $song = $data["songData"];
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 // Do we really want it to spam the origin channel with what song we're playing all the time?
38 38
                 //$message->getChannelAttribute()->sendMessage("Now playing **{$song->title}** by **{$song->artist}** in {$channel->name}");
39 39
                 $log->addInfo("Now playing **{$song->title}** by **{$song->artist}** in {$channel->name}");
40
-                $vc->playFile($songFile)->done(function () use (&$tickQueue, $vc, &$log, &$audioStreams, $guildID) {
40
+                $vc->playFile($songFile)->done(function() use (&$tickQueue, $vc, &$log, &$audioStreams, $guildID) {
41 41
                     if (isset($audioStreams[$guildID])) {
42 42
                         $log->addInfo("Going to next song..");
43 43
                         $vc->stop();
Please login to merge, or discard this patch.
src/Plugins/onVoice/reapers.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
14 14
 {
15 15
     public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
16 16
     {
17
-        $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use ($message, $discord, $webSocket, $log, &$audioStreams, $channel) {
17
+        $webSocket->joinVoiceChannel($channel)->then(function(VoiceClient $vc) use ($message, $discord, $webSocket, $log, &$audioStreams, $channel) {
18 18
             $guildID = $message->getChannelAttribute()->guild_id;
19 19
             // Add this audio stream to the array of audio streams
20 20
             $audioStreams[$guildID] = $vc;
21
-            $vc->setFrameSize(40)->then(function () use ($vc, &$audioStreams, $guildID) {
21
+            $vc->setFrameSize(40)->then(function() use ($vc, &$audioStreams, $guildID) {
22 22
                 $vc->setBitrate(128000);
23 23
                 $number = mt_rand(1, 23);
24 24
                 $file = __DIR__ . "/../../../sounds/reapers/{$number}.mp3";
25
-                $vc->playFile($file, 2)->done(function () use ($vc, &$audioStreams, $guildID) {
25
+                $vc->playFile($file, 2)->done(function() use ($vc, &$audioStreams, $guildID) {
26 26
                     unset($audioStreams[$guildID]);
27 27
                     $vc->close();
28 28
                 });
Please login to merge, or discard this patch.