Thanks! That helps a lot.
I'm having a bit of trouble with my script 🙁
<?php
/*
demonbot - a demonstation for codedemons.net
*/
$CONFIG = array();
$CONFIG['server'] = 'irc.gamesnet.net'; // server (i.e. irc.gamesnet.net)
$CONFIG['nick'] = 'name'; // nick (i.e. demonbot
$CONFIG['port'] = 6667; // port (standard: 6667)
$CONFIG['channel'] = '#channel'; // channel (i.e. #php)
$CONFIG['name'] = 'name'; // bot name (i.e. demonbot)
$CONFIG['admin_pass'] = 'password'; // admin pass (to change settings remotely)
/* Let it run forever (no timeouts) */
set_time_limit(0);
/* The connection */
$con = array();
/* start the bot... */
init();
function init()
{
global $con, $CONFIG;
/* We need this to see if we need to JOIN (the channel) during
the first iteration of the main loop */
$firstTime = true;
/* Connect to the irc server */
$con['socket'] = fsockopen($CONFIG['server'], $CONFIG['port']);
/* Check that we have connected */
if (!$con['socket']) {
print ("Could not connect to: ". $CONFIG['server'] ." on port ". $CONFIG['port']);
} else {
/* Send the username and nick */
cmd_send("USER ". $CONFIG['nick'] ." codedemons.net codedemons.net :". $CONFIG['name']);
cmd_send("NICK ". $CONFIG['nick'] ." codedemons.net");
/* Here is the loop. Read the incoming data (from the socket connection) */
while (!feof($con['socket']))
{
/* Think of $con['buffer']['all'] as a line of chat messages.
We are getting a 'line' and getting rid of whitespace around it. */
$con['buffer']['all'] = trim(fgets($con['socket'], 4096));
/* Pring the line/buffer to the console
I used <- to identify incoming data, -> for outgoing. This is so that
you can identify messages that appear in the console. */
print date("[d/m @ H:i]")."<- ".$con['buffer']['all'] ."\n";
/* If the server is PINGing, then PONG. This is to tell the server that
we are still here, and have not lost the connection */
if(substr($con['buffer']['all'], 0, 6) == 'PING :') {
/* PONG : is followed by the line that the server
sent us when PINGing */
cmd_send('PONG :'.substr($con['buffer']['all'], 6));
/* If this is the first time we have reached this point,
then JOIN the channel */
if ($firstTime == true){
cmd_send("JOIN ". $CONFIG['channel']);
/* The next time we get here, it will NOT be the firstTime */
$firstTime = false;
}
/* Make sure that we have a NEW line of chats to analyse. If we don't,
there is no need to parse the data again */
} elseif ($old_buffer != $con['buffer']['all']) {
/* Determine the patterns to be passed
to parse_buffer(). buffer is in the form:
:username!~identd@hostname JOIN :#php
:username!~identd@hostname PRIVMSG #PHP :action text
:username!~identd@hostname command channel :text */
function meessage ($catche, $sende) {
if (preg_match("/$catche/i", $con['buffer']['all'])) {
cmd_send("PRIVMSG ".$CONFIG['channel']." $sende");
}
}
meessage('!help', 'poo on you');
}
$old_buffer = $con['buffer']['all'];
}
}
}
/* Accepts the command as an argument, sends the command
to the server, and then displays the command in the console
for debugging */
function cmd_send($command)
{
global $con, $time, $CONFIG;
/* Send the command. Think of it as writing to a file. */
fputs($con['socket'], $command."\n\r");
/* Display the command locally, for the sole purpose
of checking output. (line is not actually not needed) */
print (date("[d/m @ H:i]") ."-> ". $command. "\n\r");
}
?>
Thats the code in whole, this piece is giving me an error:
function meessage ($catche, $sende) {
if (preg_match("/$catche/i", $con['buffer']['all'])) {
cmd_send("PRIVMSG ".$CONFIG['channel']." $sende");
}
}
I'm quite new to functions 🙁 - so I don't understand the error message:
Debug Error: C:\apache\demonbot.php line 77 - Cannot redeclare meessage() (previously declared in C:\apache\demonbot.php:77)