<?php


namespace Chat\Task;


use pocketmine\Server;

class DiscordAsync extends \pocketmine\scheduler\AsyncTask
{

    protected $webhook;
    protected $data;

    public function __construct(string $webhook, array $data)
    {
        $this->webhook = $webhook;
        $this->data = serialize($data);
    }

    public function onRun()
    {
        $data = unserialize($this->data);

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->webhook);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_exec($curl);

    }

    public function onCompletion(Server $server)
    {
        parent::onCompletion($server);
    }
}