]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/ChatlibDatabase.php
try to improve message genration
[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                 $de = new ChatLib();
32                 $en = new ChatLib();
33
34                 ChatLog::where('type', '=', 'chat')
35                         ->where('banned', '=', false)
36                         ->whereNotNull('evaluated_at')
37                         ->chunk(5000, function ($msgs) use ($de, $en) {
38                                 foreach ($msgs as $msg) {
39                                         if ($msg->detected_language === 'de') {
40                                                 $de->addMessage($msg);
41                                         } else if ($msg->detected_language === 'en') {
42                                                 $en->addMessage($msg);
43                                         } else if (is_null($msg->detected_language)) {
44                                                 $de->addMessage($msg);
45                                                 $en->addMessage($msg);
46                                         }
47                                 }
48                         });
49
50                 $de->compile();
51                 $en->compile();
52
53                 $this->line('');
54                 for ($i = 0; $i < 50; ++$i) {
55                         $this->line($de->generate());
56                 }
57                 $this->line('');
58                 for ($i = 0; $i < 50; ++$i) {
59                         $this->line($en->generate());
60                 }
61
62                 return 0;
63         }
64
65 }
66
67 ?>