rendered paste body<?php
include("SmartIRC/SmartIRC.php");
include("ffdb.php");
include('config.php');
//error_reporting(0);
$irc = &new Net_SmartIRC();
//
// Identify admins...
//
function admin_identify($host,$user,$channel)
{
global $admins;
if (in_array(strtolower($host), $admins))
{
return true;
} else {
global $irc;
//$irc->message(SMARTIRC_TYPE_CHANNEL, $channel, $user.': Ah...No!');
sendmsg("SMARTIRC_TYPE_CHANNEL",$channel,$user.': Ah...No!');
return false;
}
}
//
// Send message to channel/user...
//
function sendmsg($type,$to,$msg)
{
global $irc;
$irc->message($type, $to, $msg);
echo date("H:i:s")." - [->$to] $msg\n";
}
class bot
{
function parse(&$irc, &$data)
{
$recip = $data->channel;
$msgToMe = false;
$msgPrefix = 'nothing';
$msg = $data->message;
global $triggers;
foreach ($triggers as $prefix)
{
if ( substr($msg, 0, strlen($prefix)) == $prefix )
{
$msgToMe = true;
$msgwithoutident = substr($msg, strlen($prefix));
}
}
if ($msgToMe == true)
{
$msg_parts = explode(' ', $msgwithoutident, 2);
/*echo date("H:i:s")." - ".$data->nick." @ ".$recip." =>";
foreach ($msg_parts as $stuff)
{
echo " ".$stuff."";
}
echo "\n";*/
echo date("H:i:s")." - [".$data->nick."->] $msgwithoutident \n";
sendmsg("SMARTIRC_TYPE_CHANNEL",$recip,'Hiya.');
include("functions.php");
} else {
//Store the message with a time and date
$dataf = new FFDB("data.txt");
$array = $dataf->get_table($recip);
$array[] = array("user" => $data->nick, "time" => strtotime("now"), "msg" => $data->message);
$dataf->write_table($recip,$array);
}
}
function action(&$irc, &$data)
{
$recip = $data->channel;
$msg = "*".substr($data->message, 7, -1);
$dataf = new FFDB("data.txt");
$array = $dataf->get_table($recip);
$array[] = array("user" => $data->nick, "time" => strtotime("now"), "msg" => $msg);
$dataf->write_table($recip,$array);
}
function part(&$irc, &$data)
{
$recip = $data->channel;
$msg = $data->nick." left $recip.";
$dataf = new FFDB("data.txt");
$array = $dataf->get_table($recip);
$array[] = array("user" => $data->nick, "time" => strtotime("now"), "msg" => $msg);
$dataf->write_table($recip,$array);
}
function join(&$irc, &$data)
{
$recip = $data->channel;
$msg = $data->nick." joined $recip.";
$dataf = new FFDB("data.txt");
$array = $dataf->get_table($recip);
$array[] = array("user" => $data->nick, "time" => strtotime("now"), "msg" => $msg);
$dataf->write_table($recip,$array);
}
}
$bot = new bot();
$irc = &new Net_SmartIRC();
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL|SMARTIRC_TYPE_QUERY, '.*', $bot, 'parse');
$irc->registerActionhandler(SMARTIRC_TYPE_ACTION, '.*', $bot, 'action');
$irc->registerActionhandler(SMARTIRC_TYPE_PART, '.*', $bot, 'part');
$irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'join');
$irc->setUseSockets(TRUE);
$irc->setChannelSyncing(TRUE);
$irc->setSenddelay(500);
echo date("H:i:s")." - Connecting to irc.freenode.net:6667...\n";
$irc->connect('irc.freenode.net', 6667);
$irc->login($bot_name, $bot_real_name, 0, 'Net_SmartIRC', $bot_password);
foreach ($channels as $chan)
{
echo date("H:i:s")." - Joining channel $chan...\n";
//Set mili to 0
$dataf = new FFDB("data.txt");
$array = $dataf->get_table($chan);
$array['mili'] = time()+microtime(true);
$dataf->write_table($chan,$array);
}
$irc->join($channels);
echo date("H:i:s")." - Listening...\n";
$irc->listen();
echo date("H:i:s")." - Disconnecting...\n";
$irc->disconnect();
?>