Add command to list faves
authorCameron Ball <cameron@moodle.com>
Tue, 7 May 2019 07:25:41 +0000 (15:25 +0800)
committerCameron Ball <cameron@moodle.com>
Tue, 7 May 2019 07:35:04 +0000 (15:35 +0800)
src/gnb.php

index 4b6f238..fb0c2e5 100644 (file)
@@ -22,6 +22,27 @@ function scoresFileContentsToScoresList($who) {
 
 getTelegram()->addCommand(
     new class extends Command {
+        protected $name = 'faves';
+        protected $description = 'List favourites';
+
+        public function handle($arguments) {
+            $faveFiles = foldMap(☐(null)(∘(lines, 'trim', 'file_get_contents')))(glob(PATH_TO_GROOVENET . '/*.favourites.txt'));
+            $names = map(☐(produceValue(0))(null))(array_keys($faveFiles));
+            $hashes = map(map(☐(produceValue(0))(null)))(array_values($faveFiles));
+            $songHashMap = unserialize(file_get_contents(__DIR__ . '/hashmap.txt'));
+            $faveMap = ∘(map(∘(flip(concat)("'s Faves"), 'ucwords', field(0), delemit('.'), 'basename')), foldMap(☐(field(1))(field(0))), foldMap(id))(zzipWith(∘(map, aaray_merge))($names)($hashes));
+            $newFaves = zzipWith(∘(concat, flip(concat)(" in "), flip(field)($songHashMap)))(array_keys($faveMap))(array_values($faveMap));
+            $this->replyWithMessage(
+                [
+                    'text' => unlines($newFaves)
+                ]
+            );
+        }
+    }
+);
+
+getTelegram()->addCommand(
+    new class extends Command {
         protected $name = 'scores';
         protected $description = 'Get all scores with specified high score name';