]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/ReevaluateChatCommand.php
more spam
[alttp.git] / app / Console / Commands / ReevaluateChatCommand.php
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Models\ChatLog;
6 use Illuminate\Console\Command;
7
8 class ReevaluateChatCommand extends Command {
9
10         /**
11          * The name and signature of the console command.
12          *
13          * @var string
14          */
15         protected $signature = 'chat:reevaluate';
16
17         /**
18          * The console command description.
19          *
20          * @var string
21          */
22         protected $description = 'Reevaluate chat log entries';
23
24         /**
25          * Execute the console command.
26          *
27          * @return int
28          */
29         public function handle() {
30                 $good = 0;
31                 $bad = 0;
32                 ChatLog::whereIn('type', ['chat', 'error'])
33                         ->where('banned', false)
34                         ->orderBy('created_at')
35                         ->chunk(10000, function ($logs) use (&$good, &$bad) {
36                                 foreach ($logs as $line) {
37                                         try {
38                                                 $line->evaluate();
39                                                 $line->evaluated_at = now();
40                                                 $line->save();
41                                                 ++$good;
42                                         } catch (\Exception $e) {
43                                                 ++$bad;
44                                                 $this->error('unable to evaluate line '.$line->id.': '.$e->getMessage());
45                                                 $line->type = 'error';
46                                                 $line->text_content = $e->getMessage();
47                                                 $line->evaluated_at = now();
48                                                 $line->save();
49                                         }
50                                 }
51                                 echo $good;
52                                 if ($bad) {
53                                         echo ' +', $bad, ' errors';
54                                 }
55                                 echo PHP_EOL;
56                         });
57
58                 return Command::SUCCESS;
59         }
60
61 }