Advertisement
Multivit4min

Untitled

Mar 3rd, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2.  
  3. class Bot {
  4.    
  5.     public $token;
  6.    
  7.     public function __construct($botHost = '127.0.0.1', $botPort = 8087, $botId = NULL) {
  8.         if ($botId == NULL) return false;
  9.         $this->Host = $botHost;
  10.         $this->Port = $botPort;
  11.         $this->botId = $botId;
  12.     }
  13.    
  14.     public function Login($username, $password) {
  15.         $ch = curl_init();
  16.         curl_setopt_array($ch, array(
  17.             CURLOPT_URL => 'http://'.$this->Host.':'.$this->Port.'/api/v1/bot/login',
  18.             CURLOPT_RETURNTRANSFER => 1,
  19.             CURLOPT_POSTFIELDS => json_encode(array('username' => $username, 'password' => $password, 'botId' => $this->botId)),
  20.             CURLOPT_HTTPHEADER => array('Content-Type: application/json')
  21.         ));
  22.         $data = curl_exec($ch);
  23.         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  24.         curl_close($ch);
  25.         if ($code != 200) return $code;
  26.         $this->token = json_decode($data, TRUE)['token'];
  27.         return true;
  28.     }
  29.    
  30.     public function setAvatar($image) {
  31.         $ch = curl_init();
  32.         curl_setopt_array($ch, array(
  33.             CURLOPT_URL => 'http://'.$this->Host.':'.$this->Port.'/api/v1/bot/i/'.$this->botId.'/avatar',
  34.             CURLOPT_RETURNTRANSFER => 1,
  35.             CURLOPT_POSTFIELDS => $image,
  36.             CURLOPT_HTTPHEADER => array('Content-Type: image/png')
  37.         ));
  38.         $data = curl_exec($ch);
  39.         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  40.         curl_close($ch);
  41.         return $code;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement