Convert faves to searchfaves since there's too many
authorCameron Ball <cameron@moodle.com>
Tue, 7 May 2019 08:05:03 +0000 (16:05 +0800)
committerCameron Ball <cameron@moodle.com>
Tue, 7 May 2019 08:05:03 +0000 (16:05 +0800)
src/gnb.php

index fb0c2e5..fcf4a9d 100644 (file)
@@ -22,7 +22,7 @@ function scoresFileContentsToScoresList($who) {
 
 getTelegram()->addCommand(
     new class extends Command {
-        protected $name = 'faves';
+        protected $name = 'searchfaves';
         protected $description = 'List favourites';
 
         public function handle($arguments) {
@@ -32,9 +32,17 @@ getTelegram()->addCommand(
             $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));
+
+            $thing = map(function ($fave) use ($arguments) {
+                $justTitle = join(' ', array_slice(explode(' ', $fave), 0 , -2));
+                similar_text($arguments, $justTitle ?: '', $perc);
+                return ['title' => $fave, 'similarity' => $perc];
+            });
+            $top5 = ∘(unlines, aaray_column('title'), aaray_slice(0)(5), 'array_reverse', 'array_values', ssort(∘(∘f(field('similarity')), ⬄, field('similarity'))));
+
             $this->replyWithMessage(
                 [
-                    'text' => unlines($newFaves)
+                    'text' => unlines($top5($thing))
                 ]
             );
         }