]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/TwitchTopEmotes.php
add myustery circus link
[alttp.git] / app / Console / Commands / TwitchTopEmotes.php
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Models\ChatLog;
6 use Illuminate\Console\Command;
7
8 class TwitchTopEmotes extends Command {
9
10         /**
11          * The name and signature of the console command.
12          *
13          * @var string
14          */
15         protected $signature = 'twitch:top-emotes {amount=10}';
16
17         /**
18          * The console command description.
19          *
20          * @var string
21          */
22         protected $description = 'Compiles a list of top N emotes in the chatbot catalog';
23
24         /**
25          * Execute the console command.
26          *
27          * @return int
28          */
29         public function handle() {
30                 $counts = [];
31
32                 ChatLog::where('type', '=', 'chat')
33                         ->where('banned', '=', false)
34                         ->whereNotNull('evaluated_at')
35                         ->chunk(5000, function ($msgs) use (&$counts) {
36                                 foreach ($msgs as $msg) {
37                                         $tokenized = $msg->tokenize();
38                                         foreach ($tokenized->getOriginalEmotes() as $emote) {
39                                                 if (!isset($counts[$emote])) {
40                                                         $counts[$emote] = 1;
41                                                 } else {
42                                                         ++$counts[$emote];
43                                                 }
44                                         }
45                                 }
46                         });
47
48                 arsort($counts);
49
50                 $amount = intval($this->argument('amount'));
51                 $counts = array_slice($counts, 0, $amount);
52
53                 foreach ($counts as $emote => $count) {
54                         $this->line(mb_str_pad($emote, 20).$count);
55                 }
56
57                 return 0;
58         }
59
60 }
61
62 ?>