Make scores command a little nicer
authorCameron Ball <cameron@moodle.com>
Tue, 7 May 2019 05:21:57 +0000 (13:21 +0800)
committerCameron Ball <cameron@moodle.com>
Tue, 7 May 2019 05:26:13 +0000 (13:26 +0800)
src/gnb.php

index 4d38a48..fea966b 100644 (file)
@@ -26,6 +26,15 @@ getTelegram()->addCommand(
         protected $description = 'Get all scores with specified high score name';
 
         public function handle($arguments) {
+            if (!$arguments) {
+                $this->replyWithMessage(
+                    [
+                        'text' => "Scores command requires a high score name."
+                    ]
+                );
+                return;
+            }
+
             $diffEmojiMap = [
                 'Beginner' => '🗑',
                 'Easy' => '📗',
@@ -60,6 +69,15 @@ getTelegram()->addCommand(
                 ]);
             }
 
+            if (!$pranks) {
+                $this->replyWithMessage(
+                    [
+                        'text' => "$arguments doesn't have any scores."
+                    ]
+                );
+                return;
+            }
+
             $this->replyWithMessage(
                 [
                     'text' => "High scores for $arguments ...\n\n" . unlines($pranks)