]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/EvaluateChatCommand.php
add myustery circus link
[alttp.git] / app / Console / Commands / EvaluateChatCommand.php
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Models\ChatLog;
6 use Illuminate\Console\Command;
7
8 class EvaluateChatCommand extends Command {
9
10         /**
11          * The name and signature of the console command.
12          *
13          * @var string
14          */
15         protected $signature = 'chat:evaluate {amount=1}';
16
17         /**
18          * The console command description.
19          *
20          * @var string
21          */
22         protected $description = 'Evaluate chat log entries';
23
24         /**
25          * Execute the console command.
26          *
27          * @return int
28          */
29         public function handle() {
30                 $amount = $this->argument('amount');
31
32                 $logs = ChatLog::whereNull('evaluated_at')->orderBy('created_at')->limit($amount)->get();
33
34                 foreach ($logs as $line) {
35                         try {
36                                 $line->evaluate();
37                                 $line->evaluated_at = now();
38                                 $line->save();
39                         } catch (\Exception $e) {
40                                 $this->error('unable to evaluate line '.$line->id.': '.$e->getMessage());
41                                 $line->type = 'error';
42                                 $line->text_content = $e->getMessage();
43                                 $line->evaluated_at = now();
44                                 $line->save();
45                         }
46                 }
47
48                 return Command::SUCCESS;
49         }
50
51 }