Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 110 lines (84 sloc) 2.906 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
#!/usr/bin/php
<?php

include_once("Net/SmartIRC.php");

$channel = "#LOPSA-live";
$botName = "MPSwindow";
$botRealName = "SmartBot 2000 (ask standalone.sysadmin@gmail.com)";


class mybot {

// AMQP Variables
private $messageQueue = "IRCoutput";
private $connection = "";
private $channel = "";
private $exchange = "";

function __construct() {
$this->AMQPinit();
} // end constructor()

function AMQPinit() {
$this->connection = new AMQPConnection();
$this->connection->connect();

$this->channel = new AMQPChannel($this->connection);
if ( $this->channel->isConnected() ) {
$this->exchange = new AMQPExchange($this->channel);
} else {
print "Error connecting to channel\n";
exit;
}

$this->exchange->setName("IRClog");
$this->exchange->setType("fanout");
$this->exchange->declare();

} // end function AMQPinit()

function handleUpdate(&$irc, &$data) {
$type = $data->type;
$outputMessage = "";

switch($type) {
case SMARTIRC_TYPE_JOIN:
$outputMessage = $data->nick . " joined " . $data->channel;
break;
case SMARTIRC_TYPE_PART:
$outputMessage = $data->nick . " left " . $data->channel;
break;
case SMARTIRC_TYPE_CHANNEL:
$outputMessage = "<" . $data->nick . "> " . $data->message;
break;
case SMARTIRC_TYPE_TOPICCHANGE:
$outputMessage = "The topic on " . $data->channel . " is now " . $data->message;
break;
case SMARTIRC_TYPE_NICKCHANGE:
$outputMessage = $data->nick . " is now known as " . $data->message;
break;
case SMARTIRC_TYPE_KICK:
$outputMessage = $data->nick . " got kicked from " . $data->channel;
break;
case SMARTIRC_TYPE_QUIT:
$outputMessage = $data->nick . " quit";
break;
case SMARTIRC_TYPE_MODECHANGE:
case SMARTIRC_TYPE_CHANNELMODE:
$outputMessage = "Mode change: " . $data->rawmessage;
break;
default:
$outputMessage = "";
}

if ( $outputMessage != "" ) {
$this->channel->startTransaction();
$this->exchange->publish($outputMessage, $this->messageQueue);
$this->channel->commitTransaction();
print $outputMessage . "\n";
}

} // end function handleUpdate()
} // end class mybot()


$bot = &new mybot();
$irc = &new Net_SmartIRC();

//$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);

print "\nConnecting to irc.lopsa.org\n";
$irc->connect('irc.lopsa.org', 6667);

$irc->login("$botName", "$botRealName", 0, 'Net_SmartIRC');

print "Joining $channel\n";
$irc->join(array("$channel"));

//$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '.', $bot, 'channelMessage');
//$irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'channelMemberChange');
//$irc->registerActionhandler(SMARTIRC_TYPE_PART, '.*', $bot, 'channelMemberChange');
$irc->registerActionhandler(SMARTIRC_TYPE_ALL, '.*', $bot, 'handleUpdate');

$irc->listen();



?>
Something went wrong with that request. Please try again.