Add scoresummary command
authorCameron Ball <cameron@moodle.com>
Thu, 16 May 2019 02:58:46 +0000 (10:58 +0800)
committerCameron Ball <cameron@moodle.com>
Thu, 16 May 2019 03:22:36 +0000 (11:22 +0800)
src/common.php
src/gnb.php

index 9abcc2b..e8446a1 100644 (file)
@@ -24,6 +24,11 @@ function scoresFileContentsToScoresList($who) {
     };
 }
 
+const not = 'not';
+function not($v) {
+    return !$v;
+}
+
 const notEmpty = 'notEmpty';
 function notEmpty($value) : bool {
     return !empty($value);
@@ -217,7 +222,7 @@ function map($callable) {
 
 function contains(string $what) {
     return function(string $h) use ($what) {
-        return strpos($h, $what) === false;
+        return strpos($h, $what) !== false;
     };
 }
 
index 23badfe..cb76238 100644 (file)
@@ -98,6 +98,32 @@ function getChunkyScores($who) {
 
 getTelegram()->addCommand(
     new class extends Command {
+        protected $name = 'scoresummary';
+        protected $description = 'Get a count of how many scores each participant has';
+
+        public function handle($arguments) {
+            $counts = foldMap(∘(☐(lhead)(∘('count', filter(∘(not, contains('NODATA'))), lines)), 'trim', 'file_get_contents'))(glob(PATH_TO_GROOVENET . '/*.scores.txt'));
+
+            $out = array_reduce(
+                array_keys($counts)
+                ,function($c, $v) use ($counts) {
+                    return "$c\n$v: " . $counts[$v] . " pranks";
+                }, '');
+
+            $chatid = getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id');
+            getTelegram()->sendMessage(
+                [
+                    'chat_id' => $chatid,
+                    'parse_mode' => 'Markdown',
+                    'text' => "```" . $out . "\n```\n"
+                ]
+            );
+        }
+    }
+);
+
+getTelegram()->addCommand(
+    new class extends Command {
         protected $name = 'digest';
         protected $description = 'Get the prank digest for today';