From 505426160f3ae9806be078f32c588c096029af78 Mon Sep 17 00:00:00 2001 From: Jake Birchall Date: Tue, 23 Aug 2016 01:20:27 +0100 Subject: [PATCH] Safer sendoutput --- app/Plugin.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/Plugin.php b/app/Plugin.php index 8454ced..08d4d75 100644 --- a/app/Plugin.php +++ b/app/Plugin.php @@ -13,6 +13,8 @@ * * @package App */ +use TeamSpeak3\Ts3Exception; + /** * Class Plugin * @@ -205,18 +207,22 @@ static function sortByLengthDESC($array) function sendOutput($text, ...$params) { $text = vsprintf($text, $params); - - $client = $this->teamSpeak3Bot->node->clientGetByName($this->info['invokername']); - - if (\App\TeamSpeak3Bot::$config['newLineNewMessage'] === false) { - $client->message($text); - $this->teamSpeak3Bot->printOutput($text); - } else { - $messages = explode(PHP_EOL, $text); - foreach ($messages as $message) { - $client->message($message); - $this->teamSpeak3Bot->printOutput($message); + try { + + $client = $this->teamSpeak3Bot->node->clientGetByName($this->info['invokername']); + + if (\App\TeamSpeak3Bot::$config['newLineNewMessage'] === false) { + $client->message($text); + $this->teamSpeak3Bot->printOutput($text); + } else { + $messages = explode(PHP_EOL, $text); + foreach ($messages as $message) { + $client->message($message); + $this->teamSpeak3Bot->printOutput($message); + } } + } catch (Ts3Exception $e) { + $this->teamSpeak3Bot->printOutput($e->getMessage()); } return; }