<?php

namespace App\Console\Commands;

use App\Http\Controllers\BotController;
use Illuminate\Console\Command;
use App\Models\users;

class FillUsers extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fill:users';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $users_txt = file_get_contents('/var/www/html/flibusta/storage/users.txt');
        $users_txt = explode(PHP_EOL,$users_txt);

        foreach ($users_txt as $chat_id) {
            $chat_id = trim($chat_id);
            $check_user = users::where('chat_id',$chat_id)->first();
            if(!$check_user){
                $user = new users();
                $user->chat_id = $chat_id;
                $user->username = "";
                $user->first_name = "";
                $user->ref = "";
                $user->search = "";
                $user->action = "0";
                $user->keyboard_actions = "0";
                $user->updated = 0;
                $user->registered = time();
                $user->save();
            }
        }
    }
}
