<?php

namespace App\Console\Commands;

use App\Jobs\ReadDiscordMessageJob;
use App\Models\PromptTask;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class ReadDiscordMessageCommand extends Command
{
    protected $signature = 'read:discord-message';

    protected $description = 'Command description';

    protected string $key = 'discord_message';

    public function handle()
    {
        while (true) {
            $data = Redis::connection()->blpop($this->key, 1);
            if (filled($data)) {
                $data = json_decode($data[1], true);
                if (filled($data)) {
                    $this->info("开始处理消息 {$data['message_content']}");
                    dispatch(new ReadDiscordMessageJob($data));
                }
            }
            $this->info('运行完成');
        }
    }
}
