--- /dev/null
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class ChatLog extends Model {
+
+ use HasFactory;
+
+ protected $casts = [
+ 'params' => 'array',
+ 'tags' => 'array',
+ ];
+
+ protected $fillable = [
+ 'command',
+ 'nick',
+ 'params',
+ 'tags',
+ ];
+
+}
namespace App\TwitchBot;
+use App\Models\ChatLog;
+
class IRCMessage {
public $command = null;
return $str;
}
+ public function log() {
+ ChatLog::create([
+ 'command' => $this->command,
+ 'nick' => $this->nick,
+ 'params' => $this->params,
+ 'tags' => $this->tags,
+ ]);
+ }
+
public static function join($channels) {
$msg = new IRCMessage();
$msg->command = 'JOIN';
public function handleIRCMessage(IRCMessage $msg) {
$this->last_contact = time();
- if ($msg->isPrivMsg()) {
- $this->handlePrivMsg($msg);
- return;
- }
if ($msg->isPing()) {
$this->sendIRCMessage($msg->makePong());
return;
if ($msg->isPong()) {
return;
}
+ $msg->log();
+ if ($msg->isPrivMsg()) {
+ $this->handlePrivMsg($msg);
+ return;
+ }
if ($msg->isNotice() && $msg->getText() == 'Login authentication failed') {
$this->logger->notice('login failed, refreshing access token');
$this->token->refresh();
public function handlePrivMsg(IRCMessage $msg) {
$target = $msg->getPrivMsgTarget();
- if ($target[0] != '#') return;
+ if ($target[0] != '#') return; // direct message
$text = $msg->getText();
if ($text[0] != '!') return;
$channel = Channel::firstWhere('twitch_chat', '=', $target);
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('chat_logs', function (Blueprint $table) {
+ $table->id();
+ $table->timestamps();
+ $table->string('command');
+ $table->string('nick')->nullable();
+ $table->text('params');
+ $table->text('tags');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('chat_logs');
+ }
+};