-
December 17th, 2005, 05:26 AM
#1
QuaridBot
As some of your know I'm well on my way developing an IRC bot for the ANewEraIRC Network, anyways, here's what I have so far. (It uses the Net_SmartIRC PEAR class)
The actual main program
PHP Code:
<?php
ini_set("max_execution_time","0");
/**
* Quarid, a basic (at the moment) bot for op functions, and some "neat" features
* such as stats logging, and "last seen". Configuration in config.php
* Build using SmartIRC PEAR class
*
* Author: Daniel J. Enman
* Creation Date: December 14th 2005
*/
/**
* Include what we need to.
*/
require_once("SmartIRC.php");
require_once("QuaridConfig.php");
class Quarid extends QuaridConfig {
/**
* The Net_SmartIRC object
*/
var $irc;
/**
* The debug level
*/
var $debug;
/**
* Constructors... yippie!
*/
public function __construct() {
/**
* We're going to need the Net_SmartIRC class for some
* fancy pantsin'.
*/
$this->irc = new Net_SmartIRC();
$botff = "botf";
$this->{$botff} = new botf();
}
/**
* Let's start with some debugging
*/
public function _setDebug() {
$debug = $this->bot['debuglev'];
switch($debug){
case 0:
$this->irc->setDebug(SMARTIRC_DEBUG_NONE);
break;
case 1:
$this->irc->setDebug(SMARTIRC_DEBUG_NOTICE);
break;
case 2:
$this->irc->setDebug(SMARTIRC_DEBUG_SOCKET);
break;
case 3:
$this->irc->setDebug(SMARTIRC_DEBUG_TIMEHANDLER);
break;
case 4:
$this->irc->setDebug(SMARTIRC_DEBUG_USERSYNCING);
break;
case 5:
$this->irc->setDebug(SMARTIRC_DEBUG_MODULES);
break;
case 6:
$this->irc->setDebug(SMARTIRC_DEBUG_MESSAGETYPES);
break;
case 7:
$this->irc->setDebug(SMARTIRC_DEBUG_MESSAGEPARSER);
break;
case 8:
$this->irc->setDebug(SMARTIRC_DEBUG_MESSAGEHANDLER);
break;
case 9:
$this->irc->setDebug(SMARTIRC_DEBUG_IRCMESSAGES);
break;
case 10:
$this->irc->setDebug(SMARTIRC_DEBUG_CONNECTION);
break;
case 11:
$this->irc->setDebug(SMARTIRC_DEBUG_CHANNELSYNCING);
break;
case 12:
$this->irc->setDebug(SMARTIRC_DEBUG_ACTIONHANDLER);
break;
case 13:
$this->irc->setDebug(SMARTIRC_DEBUG_ALL);
break;
default:
die("Error, please set a value on debug between 0 and 13. See manual for more infromation.");
break;
}
return $debug;
}
public function _startLog() {
$logto = $this->bot['logto'];
switch($logto){
case 0:
$this->irc->setLogdestination(SMARTIRC_FILE);
$file = "./log/".$this->bot['logfile'];
if(!file_exists($file)){
touch($file);
chmod($file, 0777);
}
$logf = fopen($file, 'a');
if(!$logf){
echo "Could not open file ".$file.", or create log file. Does log/ exist, and is it writeable?\n";
exit;
}
$this->irc->log(SMARTIRC_DEBUG_NOTICE, "QuaridBot loaded.", "Quarid", "0");
$this->irc->setLogFile($file);
break;
case 1:
$this->irc->setLogDestination(SMARTIRC_STDOUT);
break;
case 2:
$this->irc->setLogDestination(SMARTIRC_BROWSEROUT);
break;
case 3:
$this->irc->setLogDestination(SMARTIRC_SYSLOG);
break;
case 4:
$this->irc->setLogDestination(SMARTIRC_NONE);
default:
die("Error, please set a value between 0 and 4. See the manual for more information");
}
return $logto;
}
/**
* CTCP version
*/
protected function _setVersion() {
$this->irc->setCTCPVersion("QuaridBot 0.01");
}
public function actions() {
$this->irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $this->botf, 'onjoin_greeting');
}
public function main() {
/**
* Set up some settings set in QuaridConfig.php
*/
$this->_setDebug();
$this->irc->setUseSockets($this->bot['sockets']);
$this->irc->setBenchmark($this->bot['bmark']);
$this->irc->setChannelSyncing($this->bot['chansync']);
$this->_startLog(); // Let's start logging now!
$this->irc->showBenchmark();
/**
* Do the botf stuff!
*/
$this->irc->connect('irc.unerror.com', 6667);
$this->irc->login($this->bot['nickname'], $this->bot['realname'], 0, $this->bot['username'], null);
$this->irc->join($this->channels);
$this->actions();
print_r($this->botf);
$this->irc->listen();
$this->irc->disconnect();
}
}
$Quarid = new Quarid();
$Quarid->main();
?>
The configuration:
PHP Code:
<?php
/**
* The configuration class for Quarid
*/
class QuaridConfig {
var $db = array("host" => "localhost",
"user" => "root",
"pass" => "AReallyStrongPassWord",
"dbse" => "QuaridIRC",
"tblp" => "quarid_");
var $bot = array("nickname" => "Quarid",
"username" => "quarid",
"realname" => "Quarid Bot",
"servername" => "ANewEraIRC",
"serveraddy" => "unerror.anewerairc.net",
"serverport" => 6667,
"SSL" => false,
"debuglev" => 13,
"sockets" => true,
"bmark" => true,
"chansync" => true,
"logfile" => "Quarid.log",
"logto" => 0);
var $channels = array ("#network");
}
/**
* Let's do some modules
*/
$modnames = array("botf");
for($i=0;$i<count($modnames);$i++){
include("modules/".$modnames[$i].".php");
}
?>
And an example of a module:
PHP Code:
<?php
/**
* Some basic bot functions
*/
class botf {
function onjoin_greeting(&$irc, &$data)
{
// if _we_ join, don't greet ourself, just jump out via return
if ($data->nick == $irc->_nick)
return;
// now check if this is the right channel
if ($data->channel == '#network')
// it is, lets greet the joint user
$irc->message(SMARTIRC_TYPE_CHANNEL, '#network', 'Hey, '.$data->nick);
print_r($data);
}
}
?>
Although as you can probably tell (given you know PHP, and have read the source) dynamic module loading isn't working, but I think I'm on my way for getting the bot up and running sometime soon, and hopefully addind some neat features into ANewEraIRC, it's services, and it's website.
Comments and suggestions are welcome
-enmand
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|