Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement