Multivit4min icon

Untitled

Multivit4min | PRO | 03/03/16 07:32:06 PM UTC | 0 ⭐ | 405 👁️ | Never ⏰ | []
PHP |

1.5 KB

|

None

|

0 👍

/

0 👎

<?php
 
class Bot {
    
    public $token;
    
    public function __construct($botHost = '127.0.0.1', $botPort = 8087, $botId = NULL) {
        if ($botId == NULL) return false;
        $this->Host = $botHost;
        $this->Port = $botPort;
        $this->botId = $botId;
    }
    
    public function Login($username, $password) {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->Host.':'.$this->Port.'/api/v1/bot/login',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_POSTFIELDS => json_encode(array('username' => $username, 'password' => $password, 'botId' => $this->botId)),
            CURLOPT_HTTPHEADER => array('Content-Type: application/json')
        ));
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($code != 200) return $code;
        $this->token = json_decode($data, TRUE)['token'];
        return true;
    }
    
    public function setAvatar($image) {
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'http://'.$this->Host.':'.$this->Port.'/api/v1/bot/i/'.$this->botId.'/avatar',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_POSTFIELDS => $image,
            CURLOPT_HTTPHEADER => array('Content-Type: image/png')
        ));
        $data = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $code;
    }
}

Comments