]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/ChatlibDatabase.php
cb7978f6e92bb84074c183354dc85f04766d1d36
[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('type', '=', 'chat')
34                         ->where('banned', '=', false)
35                         ->whereNotNull('evaluated_at')
36                         ->chunk(500, function ($msgs) use ($db) {
37                                 foreach ($msgs as $msg) {
38                                         $db->addMessage($msg);
39                                 }
40                         });
41
42                 $db->compile();
43
44                 for ($i = 0; $i < 50; ++$i) {
45                         $this->line($db->generate());
46                 }
47
48                 return 0;
49         }
50
51 }
52
53 ?>