Created
October 19, 2012 06:09
-
-
Save necenzurat/3916472 to your computer and use it in GitHub Desktop.
robot.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// activate full error reporting | |
//error_reporting(E_ALL & E_STRICT); | |
include 'XMPPHP/XMPP.php'; | |
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports | |
#If this doesn't work, are you running 64-bit PHP with < 5.2.6? | |
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'user', 'parola', 'xmpphp', 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO); | |
$conn->autoSubscribe(); | |
$vcard_request = array(); | |
try { | |
$conn->connect(); | |
while(!$conn->isDisconnected()) { | |
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'vcard')); | |
foreach($payloads as $event) { | |
$pl = $event[1]; | |
switch($event[0]) { | |
case 'message': | |
//print "---------------------------------------------------------------------------------\n"; | |
//print "Message from: {$pl['from']}\n"; | |
//if($pl['subject']) print "Subject: {$pl['subject']}\n"; | |
print $pl['body'] . "\n"; | |
//print "---------------------------------------------------------------------------------\n"; | |
$conn->message( | |
$pl['from'], | |
$body="Thanks for sending me \"{$pl['body']}\".", | |
$type=$pl['type']); | |
$cmd = explode(' ', $pl['body']); | |
$c = $cmd[0]; | |
if($cmd[0] == 'status') $conn->presence("yey!"); | |
if ($c == "x") { | |
} | |
/* | |
if($cmd[0] == 'quit') $conn->disconnect(); | |
if($cmd[0] == 'quit') $conn->disconnect(); | |
if($cmd[0] == 'break') $conn->send("xxx"); | |
if($cmd[0] == 'vcard') { | |
if(!($cmd[1])) $cmd[1] = $conn->user . '@' . $conn->server; | |
// take a note which user requested which vcard | |
$vcard_request[$pl['from']] = $cmd[1]; | |
// request the vcard | |
$conn->getVCard($cmd[1]); | |
} | |
*/ | |
break; | |
case 'presence': | |
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n"; | |
break; | |
case 'session_start': | |
print "Session Start\n"; | |
$conn->getRoster(); | |
$conn->presence($status="meh!"); | |
break; | |
case 'vcard': | |
// check to see who requested this vcard | |
$deliver = array_keys($vcard_request, $pl['from']); | |
// work through the array to generate a message | |
print_r($pl); | |
$msg = ''; | |
foreach($pl as $key => $item) { | |
$msg .= "$key: "; | |
if(is_array($item)) { | |
$msg .= "\n"; | |
foreach($item as $subkey => $subitem) { | |
$msg .= " $subkey: $subitem\n"; | |
} | |
} else { | |
$msg .= "$item\n"; | |
} | |
} | |
// deliver the vcard msg to everyone that requested that vcard | |
foreach($deliver as $sendjid) { | |
// remove the note on requests as we send out the message | |
unset($vcard_request[$sendjid]); | |
$conn->message($sendjid, $msg, 'chat'); | |
} | |
break; | |
} | |
} | |
} | |
} catch(XMPPHP_Exception $e) { | |
die($e->getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment