Add fulldigest command
authorCameron Ball <cameron@cameron1729.xyz>
Sun, 20 Oct 2019 13:28:05 +0000 (21:28 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Sun, 20 Oct 2019 13:28:05 +0000 (21:28 +0800)
src/gnb.php

index 0463cdb..cd813b4 100644 (file)
@@ -229,6 +229,109 @@ getTelegram()->addCommand(
 
 getTelegram()->addCommand(
     new class extends Command {
+        protected $name = 'fulldigest';
+        protected $description = 'Get the prank digest for today';
+
+        public function handle($arguments) {
+            $diffEmojiMap = [
+                'Beginner' => 'šŸ—‘',
+                'Easy' => 'šŸ“—',
+                'Medium' => 'šŸ“™',
+                'Hard' => 'šŸ“•',
+                'Challenge' => 'šŸ“˜',
+                'Edit' => 'šŸ““'
+            ];
+
+            $songHashMap = unserialize(file_get_contents(__DIR__ . '/hashmap.txt'));
+            $scoreFiles = foldMap(āˆ˜(ā˜(lhead)(null), 'file_get_contents'))(glob(PATH_TO_GROOVENET . '/*.scores.txt'));
+            $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));
+
+            $oldFaveMap = unserialize(file_get_contents(__DIR__ . '/faves.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));
+            $oldScoreTesseract = unserialize(file_get_contents(__DIR__ . '/tesseract.txt'));
+            $scoreTesseract = map(map(map(maxKey)))(
+                āˆ˜(foldMap(id), zzipWith(pa)(map(ltail)($scoreFiles)), map(āˆ˜(scoresFileContentsToScoresList, lhead)))($scoreFiles)
+            );
+
+            $diff = array_diff_assoc_recursive($scoreTesseract, $oldScoreTesseract);
+            $asdf = prefixKey('', $diff);
+            $pranks = [];
+
+            foreach ($asdf as $k => $v) {
+                $k = explode('.', $k);
+
+                if (!isset($oldScoreTesseract[$k[0]][$k[1]][$k[2]])) {
+                    continue;
+                }
+
+                $previous = $oldScoreTesseract[$k[0]][$k[1]][$k[2]];
+                $scorer = array_keys($previous)[0];
+                $score = $previous[$scorer];
+
+                $pranks[] = glue('')([
+                    "ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”\n",
+                    $diffEmojiMap[$k[1]],
+                    $k[2] == 'dance-double' ? $diffEmojiMap[$k[1]] : '',
+                    ' ' . explode('/', $songHashMap[$k[0]])[1],
+                    "\n",
+                    $k[3] . ": " . truncate($v*100, 2) . "%",
+                    " (was $scorer: " . truncate($score*100, 2) . "%)"
+                ]);
+            }
+
+            if ($pranks) {
+                $numE = count($pranks);
+                $pranks[$numE- 1] .= "\nā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”ā€”";
+            }
+
+            $faveDiff = array_diff_assoc($faveMap, $oldFaveMap);
+            $newFaves = zzipWith(āˆ˜(concat, flip(concat)(" in "), field(1), delemit('/'), āˆ˜(flip(field))($songHashMap)))(array_keys($faveDiff))(array_values($faveDiff));
+            $chatid = getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id');
+
+            $c = lines(trim(file_get_contents(glob(PATH_TO_GROOVENET . '/songs.*.txt')[0])));
+            $newSongHashMap = [];
+
+            foreach ($c as $v) {
+                $slash = explode('/', $v);
+                $newSongHashMap[explode(' ', $v)[0]] = $slash[4] . '/' . $slash[5];
+            }
+
+            $newFiles = array_diff($newSongHashMap, $songHashMap);
+
+            if ($pranks || $newFaves || $newFiles) {
+                getTelegram()->sendMessage(
+                    [
+                        'chat_id' => $chatid,
+                        'parse_mode' => 'Markdown',
+                        'text' => unlines(
+                            array_merge(
+                                ['Welcome to the GrooveNet digest', ""],
+                                $pranks ? ["Latest pranks:", '```'] : [],
+                                $pranks,
+                                $pranks ? ['```'] : [],
+                                $newFaves ? ['Latest faves:', '```'] : [],
+                                $newFaves,
+                                $newFaves ? ['```'] : [],
+                                $newFiles ? ['Latest files:', '```'] : [],
+                                $newFiles,
+                                $newFiles ? ['```'] : []
+                            )
+                        )
+                    ]
+                );
+            }
+
+            if (!$pranks && !$newFaves && !$newFiles) {
+                $this->replyWithMessage(['text' => 'Nothing to report. I guess nothing cool happened yesterday.']);
+            }
+        }
+    }
+);
+
+getTelegram()->addCommand(
+    new class extends Command {
         protected $name = 'search';
         protected $description = 'Search songs list';