]> git.localhorst.tv Git - alttp.git/blobdiff - app/Console/Commands/ChatlibDatabase.php
chat adlib prototype
[alttp.git] / app / Console / Commands / ChatlibDatabase.php
diff --git a/app/Console/Commands/ChatlibDatabase.php b/app/Console/Commands/ChatlibDatabase.php
new file mode 100644 (file)
index 0000000..13c881a
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\ChatLib;
+use App\Models\ChatLog;
+use Illuminate\Console\Command;
+
+class ChatlibDatabase extends Command {
+
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'chatlib:database';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Updates the ChatLib database';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle() {
+               $db = new ChatLib();
+
+               ChatLog::where('banned', '=', false)
+                       ->whereNotNull('evaluated_at')
+                       ->chunk(500, function ($msgs) use ($db) {
+                               foreach ($msgs as $msg) {
+                                       $db->addMessage($msg);
+                               }
+                       });
+
+               $db->compile();
+
+               for ($i = 0; $i < 50; ++$i) {
+                       $this->line($db->generate());
+               }
+
+               return 0;
+       }
+
+}
+
+?>