97e2793a6d938b81104c712472887a3a8636ab71
[GrooveNetBot.git] / src / gnb.php
1 <?php declare(strict_types=1);
2
3 require('common.php');
4
5 use Telegram\Bot\Actions;
6 use Telegram\Bot\Commands\Command;
7
8 if(getTelegram()->getWebHookUpdates()->get('message') && !canChatWith(getTelegram()->getWebhookUpdates())) {
9 getTelegram()->sendMessage([
10 'chat_id' => getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id'),
11 'text' => "Sorry, Dad says I can't talk to you."
12 ]);
13 exit(0);
14 }
15
16 const scoresFileContentsToScoresList = 'scoresFileContentsToScoresList';
17 function scoresFileContentsToScoresList($who) {
18 return function($lines) use ($who) {
19 return filter(notEmpty)(foldMap((map(filterk(('NODATA'))), unflatten, insert($who)(3), delemit(':')))(lines($lines)));
20 };
21 }
22
23 getTelegram()->addCommand(
24 new class extends Command {
25 protected $name = 'scores';
26 protected $description = 'Get all scores with specified high score name';
27
28 public function handle($arguments) {
29 $diffEmojiMap = [
30 'Beginner' => '🗑',
31 'Easy' => '📗',
32 'Medium' => '📙',
33 'Hard' => '📕',
34 'Challenge' => '📘',
35 'Edit' => '📓'
36 ];
37
38 $songHashMap = unserialize(file_get_contents(__DIR__ . '/hashmap.txt'));
39
40 $scoreFiles = foldMap(((lhead)(null), 'file_get_contents'))(glob(PATH_TO_GROOVENET . '/*.scores.txt'));
41 $scoreTesseract = map(map(map(maxKey)))(
42(foldMap(id), zzipWith(pa)(map(ltail)($scoreFiles)), map((scoresFileContentsToScoresList, lhead)))($scoreFiles)
43 );
44
45 $asdf = prefixKey('', $scoreTesseract);
46 $pranks = [];
47 foreach ($asdf as $k => $v) {
48 $k = explode('.', $k);
49 if ($k[3] !== $arguments) {
50 continue;
51 }
52
53 $pranks[] = glue('')([
54 "——————————————\n",
55 $diffEmojiMap[$k[1]],
56 $k[2] == 'dance-double' ? $diffEmojiMap[$k[1]] : '',
57 ' ' . $songHashMap[$k[0]],
58 "\n ",
59 truncate($v*100, 2) . "%"
60 ]);
61 }
62
63 $this->replyWithMessage(
64 [
65 'text' => "High scores for $arguments ...\n\n" . unlines($pranks)
66 ]
67 );
68 }
69 }
70 );
71
72 getTelegram()->addCommand(
73 new class extends Command {
74 protected $name = 'hashgen';
75 protected $description = 'Generate the songs hash';
76
77 public function handle($arguments) {
78 $this->replyWithMessage(
79 [
80 'text' => "Building songs hash... This will take a while."
81 ]
82 );
83
84 exec('/root/hashghen.sh');
85 }
86 }
87 );
88
89
90 getTelegram()->commandsHandler(true); //must come afterwards because lolzer