News:

Wondering if this will always be free?  See why free is better.

Main Menu

need help building irc whois mod

Started by electroshokker, August 31, 2006, 11:54:46 AM

Previous topic - Next topic

electroshokker

Ever since I got that pjirc mod working properly at my forum, I've felt there was something lacking:

a box which would state who is online on our irc channel!

I've been trying to cook something up myself, and while I didn't get it to work for me, perhaps one of you guys might have a useful suggestion; (I'm a relative newbie with php, btw.)

I'm trying to use an irc bot to connect to the irc server and channel. This fails by a connection timeout(110). If I get this to work, I can then use the whois function to gather a list of names, put them in a nice file my forum can read out.

currently, this is where I am:

download 2 packages,

hxxp:pear.php.net/package/PEAR [nonactive]

and

hxxp:pear.php.net/package/Net_SmartIRC [nonactive]

get the pear.php and system.php file from the pear package, and the SmartIRC folder and SmartIRC.php from the other one.

Put these in a single folder, which I'll call /whois_mod for now.

Then create a new php file in the same folder, called SMF_whois.php

and here my code begins: (I got most of this from some site, I forgot which)

<?php

require_once('SmartIRC.php');

class 
myBot {

    
// Constructor
    
function myBot() {
    }

    function 
help(&$irc, &$data) {
        
$irc->message(SMARTIRC_TYPE_CHANNEL$data->channel'This is a whois test. U said "' $data->message '"?');
    }
}

// Command line vars
$args $_SERVER['argv'];
$host = ((isset($args[1]) && !empty($args[1])) ? $args[1] : 'irc.servername.com');
$channel = ((isset($args[2]) && !empty($args[2])) ? $args[2] : '#mychannel');

// Init
$bot = &new myBot();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setLogfile('./mybot.log'); //Creates log file in same folder on your server
$irc->setLogdestination(SMARTIRC_FILE);
$irc->setAutoReconnect(true); // Auto reconnect?
$irc->setUseSockets(true); //set to false if you don't have the sockets extension installed

// Handlers
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL'!help.*'$bot'help');

$irc->connect($host6667); 
$irc->login('MyBot''MyBot 1.0'0'mybot'); // Log in
$irc->join(array($channel)); // join channel
$irc->listen();
$irc->disconnect();

?>


Change the "irc.servername.com" to your irc server of choice, as well as the "#mychannel" to your preferred channel

This doesn't do much yet, just joins the channel and then quits. Later on I'd add the whois command.

Upload the entire folder to a php server and run the SMF_whois.php

Afterwards, download the log file to see the result. (or just be waiting in an irc client to see something happen)

I get a SmartIRC.php(851) DEBUG_NOTICE: couldn't connect to "irc.servername.com" reason: "Connection timed out (110)"

If this is truly only a timeout problem, this might work for someone else, in which case let me know.

In any case, I'd love to hear suggestions on how to fix this.

Advertisement: