]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/ChatlibDatabase.php
b701ad144b3d0aed3abc26cb481813e4347b0b4e
[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                 $count = 0;
32
33                 $de = new ChatLib();
34                 $en = new ChatLib();
35
36                 ChatLog::where('type', '=', 'chat')
37                         ->where('banned', '=', false)
38                         ->whereNotNull('evaluated_at')
39                         ->where('created_at', '<', now()->sub(7, 'day'))
40                         ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7'])
41                         ->whereRaw('LENGTH(`text_content`) > 12')
42                         ->chunk(5000, function ($msgs) use (&$count, $de, $en) {
43                                 foreach ($msgs as $msg) {
44                                         if ($msg->detected_language === 'de') {
45                                                 $de->addMessage($msg);
46                                         } else if ($msg->detected_language === 'en') {
47                                                 $en->addMessage($msg);
48                                         } else if (is_null($msg->detected_language)) {
49                                                 $de->addMessage($msg);
50                                                 $en->addMessage($msg);
51                                         }
52                                         ++$count;
53                                 }
54                                 $this->line($count);
55                         });
56
57                 $de->compile();
58                 $de->saveAs('de');
59
60                 $en->compile();
61                 $en->saveAs('en');
62
63                 return 0;
64         }
65
66 }
67
68 ?>