@@ -57,16 +57,16 @@ |
||
| 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 | { |
@@ -154,7 +154,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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!) |
@@ -277,20 +277,24 @@ discard block |
||
| 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 |
||
| 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) { |
@@ -34,7 +34,7 @@ |
||
| 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(); |
@@ -31,18 +31,18 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -96,10 +96,11 @@ |
||
| 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 { |
@@ -122,10 +122,10 @@ |
||
| 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; |
@@ -125,10 +125,11 @@ |
||
| 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 | |
@@ -14,15 +14,15 @@ |
||
| 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 | }); |
@@ -3,11 +3,11 @@ |
||
| 3 | 3 | use League\Container\Container; |
| 4 | 4 | use League\Container\ReflectionContainer; |
| 5 | 5 | |
| 6 | -if (! function_exists('getContainer')) { |
|
| 6 | +if (!function_exists('getContainer')) { |
|
| 7 | 7 | // Initialize and save the container instance |
| 8 | 8 | function getContainer() { |
| 9 | 9 | static $container; |
| 10 | - if(!isset($container)) { |
|
| 10 | + if (!isset($container)) { |
|
| 11 | 11 | $container = new Container; |
| 12 | 12 | |
| 13 | 13 | //. Attempt to autowire class constructor dependencies |
@@ -14,15 +14,15 @@ |
||
| 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 | }); |