I ported it to IP.Board 2.3.6 (may work on older versions, just edit the message line in the code below)
ipbnewthread.tcl
Code: Select all
# IPB New Thread TCL
# Original by ShavdApe (http://forum.egghelp.org/viewtopic.php?p=31532#31532)
# Modified by Apoc for some simple names, and formatting differences. (In case you run vBulletin as well :P)
# Date: 2/25/2009
# Version: 1.0
#
# Description: Just a simple socket listener to execute an IRC command
# from the PHP script run by an IP.Board installation.
# If you change this port here, you'll need to change it in class_irc_send.php too!
listen 13481 script ipbnewthreadaccept
proc ipbnewthreadaccept {idx} {
control $idx ipbincoming
}
proc ipbincoming {idx args} {
putlog "$args"
set line [join $args]
if {[join $args] != "" } {
set chan [lindex $line 0]
set line [lrange $line 1 end]
set line [join $line]
set line [split $line ";"]
foreach line $line {
putserv "PRIVMSG $chan :$line"
}
putlog "$line"
}
killdcc $idx
}
putlog "IPB New Thread Notifications Loaded..."
Code: Select all
<?php
/*
irc_send class by Apoc (2/25/2009) v1.0
What: A simple class to send out a verified message to an eggdrop IRC bot.
How: Options are set via ACP, and sent via a single socket open/write.
When: Whenever you want to call it! :)
Usage: $irc->send(<forum id>, <message to send>);
Yep, it's that simple.
Credits: ShavdApe (http://forum.egghelp.org/viewtopic.php?p=31532#31532)
Apoc - Created this as a class for IP.Board, and made it easier in general to use.
*/
class irc_send
{
// Add any allowed forumids here. These will be checked each time you
// have a new thread created. (This is useful if you don't want certain
// forums to show a message in IRC. Eg; staff forums)
// Leave this empty to allow all forums.
var $allowed_forums = array();
// Set this to the channel you want to output to in IRC.
var $irc_channel = '#yourchannel';
// Put the IP of your bot here.
// If your bot is running locally, you can usually just
// set this to localhost.
var $irc_server_ip = "your.bots.ip.here";
// Do not change this unless you have changed it in the TCL file as well!!!
var $irc_server_port = "13481";
// If you want this class to enable some debug messages. (Logged to this current folder path/irc_debug.txt)
// set this to true. Otherwise leave it off.
// It is highly suggested you leave this off once you have everything working!
var $_enable_debug = false;
//----------------------------------
// Main IRC Sending method.
// Args:
// @forumId: The forumId of the message being sent.
// @ircMessage: The actual message to send. This must be pre-formatted. (Excluding <br /> tags, and ; characters.)
// Returns: Nothing
//----------------------------------
function send($forumId, $ircMessage)
{
$this->write_debug("\$ircMessage: ".$ircMessage);
// Make sure we have some valid text passed to us.
if (!$ircMessage)
{
return;
}
$this->write_debug("IRC Channel: ".$this->irc_channel);
$this->write_debug("IRC Server IP: ".$this->irc_server_ip);
$this->write_debug("IRC Server Port: ".$this->irc_server_port);
// Sanity checks!
if (!$this->irc_channel || !$this->irc_server_ip || !$this->irc_server_port)
{
return;
}
$this->write_debug("Checking valid forums...");
// Make sure the forum is valid to be passed to IRC.
// This makes sure that if our allowed_forums array has any forums in it,
// that the $forumId var is in that array.
if (!$this->valid_forum($forumId))
{
return;
}
// Do some IRC splitting and replacing.
$ircMessage = ereg_replace(";", ":", $ircMessage);
$ircMessage = ereg_replace("<br />", ";", $ircMessage);
$this->write_debug("\$ircMessage after replaces: ".$ircMessage);
$line = "{$this->irc_channel} {$ircMessage}";
$this->write_debug("\$line: ".$line);
// open socket and put the line
$socket = @fsockopen ($this->irc_server_ip, $this->irc_server_port, $null, $null, 30);
if ($socket)
{
$this->write_debug("Got a valid socket. Sending and waiting...");
@fwrite($socket,"{$line}\n");
for($i=0;$i<400000;$i++){$g=$i;}
$this->write_debug("Done sending. Closing socket");
fclose($socket);
}
else
{
$this->write_debug("FAILED TO OPEN SOCKET!!!");
}
}
private function valid_forum($id)
{
$this->write_debug("Forum array count: ". count($this->allowed_forums));
// If we have 0 forums in the array,
// all forums should be passed. And are therefore, valid.
if (count($this->allowed_forums) == 0)
{
return true;
}
$this->write_debug("Id in forum: ($id) - ". in_array($this->allowed_forums));
// Just return whether the id is in the allowed forums array.
return in_array($id, $this->allowed_forums);
}
private function write_debug($m)
{
if (!$this->_enable_debug)
{
return;
}
$f = ROOT_PATH.'sources/classes/post/irc_debug.txt';
$h = fopen($f, 'a');
fwrite($h, $m."\n");
fclose($h);
}
}
?>
Code: Select all
Find:
//-----------------------------------------
// Redirect them back to the topic
//-----------------------------------------
Add above:
//-----------------------------------------
// Send out our IRC message
//-----------------------------------------
require_once(ROOT_PATH.'sources/classes/post/class_irc_send.php');
$irc = new irc_send();
$line = "New thread posted by {$this->topic['starter_name']} in {$this->forum['name']}<br />";
$line .= $this->topic['title'] . ' (' . $this->ipsclass->base_url . "showtopic=" . $this->topic['tid'] . ')';
$irc->send($this->forum['id'], $line);
Finally, edit the code in class_irc_send.php to the proper values for your bot. (See the comments for proper values)
Note: If you change the message in the class_new_post.php that gets sent to IRC, make sure you use either '<br />' or '\n' to separate lines. (Reason for XHTML compliant <br /> is that I was going to add ACP configuration at some point. But was just too lazy to do it. )
Enjoy, and please leave comments/feedback![/url]