]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/ChatlibDatabase.php
13c881a902a5589a8b31849c422dbf4259dbbf4a
[alttp.git] / app / Console / Commands / ChatlibDatabase.php
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Models\ChatLib;
6 use App\Models\ChatLog;
7 use Illuminate\Console\Command;
8
9 class ChatlibDatabase extends Command {
10
11         /**
12          * The name and signature of the console command.
13          *
14          * @var string
15          */
16         protected $signature = 'chatlib:database';
17
18         /**
19          * The console command description.
20          *
21          * @var string
22          */
23         protected $description = 'Updates the ChatLib database';
24
25         /**
26          * Execute the console command.
27          *
28          * @return int
29          */
30         public function handle() {
31                 $db = new ChatLib();
32
33                 ChatLog::where('banned', '=', false)
34                         ->whereNotNull('evaluated_at')
35                         ->chunk(500, function ($msgs) use ($db) {
36                                 foreach ($msgs as $msg) {
37                                         $db->addMessage($msg);
38                                 }
39                         });
40
41                 $db->compile();
42
43                 for ($i = 0; $i < 50; ++$i) {
44                         $this->line($db->generate());
45                 }
46
47                 return 0;
48         }
49
50 }
51
52 ?>