/** * Zwraca wiadomość zgodną z BotAPI Gadu-Gadu, którą można przekazać bezpośrednio do BotMastera * @param NULL|bool $img Czy dołączać obrazki? * @return string */ function getGG($image = NULL) { if ($image === FALSE) { $image = ''; } elseif ($image === TRUE) { $last = array_pop($this->images); if (count($this->images) > 0) { $push = new BotAPIGG(); foreach ($this->images as $data) { $push->putImage($image[3]); } } $image = $last[2] . file_get_contents($last[3]); } else { if (count($this->images) > 0) { $push = new BotAPIGG(); foreach ($this->images as $image) { if (!$push->existsImage($image[2])) { $push->putImage($image[3]); } } } $image = ''; } $format = $this->getFormat(); return pack('VVVV', strlen($this->html) + 1, strlen($this->old) + 1, strlen($image), strlen($format)) . $this->html . "" . $this->old . "" . $image . $format; }
function getImageData() { if ($this->data === NULL) { $push = new BotAPIGG(); $this->data = $push->getImage($this->hash); } return $this->data; }
function miasto($msg, $params) { $msg->session->setClass('pogoda'); if (strlen($params) > 0) { $arg = trim($params); } else { $arg = trim($msg->args); } $out = new BotMsg(); if (empty($arg)) { if (isset($msg->session->miasto)) { return new BotMsg('Aktualnie ustawione miejsce to: ' . htmlspecialchars($this->session->miasto) . ', ' . htmlspecialchars($this->session->countryName)); } try { $api = new BotAPIGG(); $dane = $api->getPublicData($msg->user); if (!isset($arg['city']) || empty($arg['city'])) { throw new Exception('Brak miasta w danych w katalogu publicznym.'); } $arg = trim($arg['city']); } catch (Exception $e) { return new BotMsg('Nie podano wymaganego argumentu <i>miasto</i>.'); } $out->a('<p>Na podstawie danych z katalogu publicznego wybieram miasto: ' . htmlspecialchars($arg) . '</p>' . "\n\n"); } else { } $api = new api_geonames(); $dane = $api->search($arg); if ($dane === FALSE) { return new BotMsg('Wystąpił błąd przy wyszukiwaniu miasta. Spróbuj ponownie później.'); } elseif ($dane === NULL) { return new BotMsg('Nie udało się zlokalizować podanego miejsca. Spróbuj wpisać inną nazwę.'); } $msg->session->miasto = $dane['name']; $msg->session->kraj = $dane['countryName']; $msg->session->cc = $dane['countryCode']; $msg->session->geo = array('lat' => $dane['lat'], 'lon' => $dane['lng']); $out->a('<p>Ustawiono miejsce: ' . htmlspecialchars($this->session->miasto) . ', ' . htmlspecialchars($this->session->countryName) . '</p>'); return $out; }
<?php require_once './class/std.php'; try { $api = new BotAPIGG(); $api->setStatus(BotAPIGG::STATUS_DOSTEPNY_DESC, 'Wpisz help, by uzyskać pomoc | http://jacekk.info/botgg'); } catch (Exception $e) { echo $e; }
function getToken($force = FALSE) { if ($force || self::$token === NULL) { $auth = $this->APIs['Gadu-Gadu']; $tok = $this->httpQuery('https://botapi.gadu-gadu.pl/botmaster/getToken/' . $auth['numer'], array(CURLOPT_USERPWD => $auth['login'] . ':' . $auth['haslo'], CURLOPT_HTTPAUTH => CURLAUTH_BASIC), FALSE); if ($tok->errorMsg) { throw new BotAPIGGReplyException('Pobieranie tokena nie powiodło się.', $tok); } self::$token = array('token' => (string) $tok->token, 'host' => (string) $tok->server, 'port' => (int) $tok->port); } return self::$token; }
<?php require_once './class/std.php'; try { $msg = new BotMsg('<p>To jest tekst!</p>'); $msg->a('<p>A to tekst <b>pogrubiony</b> oraz <i>pochylony</i>.</p>'); $api = new BotAPIGG(); var_dump($api->sendMessage(array('Gadu-Gadu://NUMER_GG@gadu-gadu.pl'), $msg)); } catch (Exception $e) { echo $e; }