Skip to content

Instantly share code, notes, and snippets.

@ciembor
Created June 7, 2011 06:07
Show Gist options
  • Save ciembor/1011761 to your computer and use it in GitHub Desktop.
Save ciembor/1011761 to your computer and use it in GitHub Desktop.
Broadcast Messaging System based on BotApi (Gadu-Gadu protocol)
<?php
require_once 'GGBotApi/PushConnection.php';
/********************************/
/******* LISTA ROZMÓWCÓW ********/
/********************************/
$interlocutors = array(
8112393 => array('Asia', 149, 179, 0),
2876746 => array('Kasia', 179, 30, 0),
3293012 => array('Zosia', 46, 116, 225),
593815 => array('Basia', 179,119, 0)
); // numer gg => (imię, r, g, b)
// gdzie r, g i b to składowe koloru w jakim wyświetlane jest imię
/********************************/
/******* DANE POŁĄCZENIA ********/
/********************************/
$bot = array(
'number' => 01234567,
'login' => 'login@poczta.xy',
'password' => '8jdk37fza8'
);
/********************************/
/********** BROADCAST ***********/
/********************************/
if (is_numeric($_GET['from'])) // jeżeli numer jest faktycznie numerem (przezorny zawsze bezpieczny)
{
if (array_key_exists($_GET['from'], $interlocutors)) // jeżeli nadawca jest na liście
{
$message = new MessageBuilder('utf-8');
$message->reply(); // jeśli tego nie będzie, bot wyśle do nadawcy pustą wiadomość (nielogiczne, ale... )
$message->addText($interlocutors[$_GET['from']][0] . ':\r\n', // imię
MessageBuilder::FORMAT_BOLD_TEXT, // pogrubienie
$interlocutors[$_GET['from']][1], // red
$interlocutors[$_GET['from']][2], // green
$interlocutors[$_GET['from']][3] // blue
); // dodaj do rozgłaszanej wiadomości nagłówek z imieniem nadawcy
$message->addText(iconv('windows-1250', 'utf-8', $HTTP_RAW_POST_DATA)); // dodaj treść wiadomości wysłaną przez nadawcę
unset($interlocutors[$_GET['from']]); // usuwamy nadawcę z tablicy rozmówców, bo nie chcemy wysyłać do niego tego co sam napisał
$message->setRecipients(array_keys($interlocutors)); // ustawiamy listę odbiorców wiadomości
$BotAPIConnection = new PushConnection($bot['number'], $bot['login'], $bot['password']); // tworzymy nowe połączenie BotAPI
$BotAPIConnection->push($message); // wysyłamy wcześniej utworzoną wiadomość
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment