| View previous topic :: View next topic |
| Author |
Message |
Apoc Voice
Joined: 25 Feb 2009 Posts: 1
|
Posted: Wed Feb 25, 2009 10:33 pm Post subject: IP.Board New Thread Notification (v1.0) |
|
|
First of all, credits to ShavdApe (this post) for the main TCL code, and the idea.
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: | # 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..." |
class_irc_send.php (put this in sources/classes/post/ of your IPB installation)
| Code: | <?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);
}
}
?> |
Edits for class_post_new.php (In sources/classes/post)
| Code: |
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); |
Save and upload.
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] |
|
| Back to top |
|
 |
arejay Voice
Joined: 22 Apr 2008 Posts: 7
|
Posted: Sun Aug 30, 2009 2:02 am Post subject: |
|
|
I cannot get this working, i turned on debug (set it to true)
and get this:
| Code: |
$ircMessage: New thread posted by arejay in Off-Topic<br />test (http://theiphonebay.com/forums/index.php?showtopic=426)
IRC Channel: #chat
IRC Server IP: cube.dawnshosting.com
IRC Server Port: 13481
Checking valid forums...
Forum array count: 0
$ircMessage after replaces: New thread posted by arejay in Off-Topic;test (http://theiphonebay.com/forums/index.php?showtopic=426)
$line: #chat New thread posted by arejay in Off-Topic;test (http://theiphonebay.com/forums/index.php?showtopic=426)
Got a valid socket. Sending and waiting...
Done sending. Closing socket
|
and in bot during telnet
| Code: |
02:00] net: connect! sock 8
[02:00] DNS resolved 69.42.210.218 to dc-node.bytebistro.com
[02:00] Telnet connection: dc-node.bytebistro.com/43135
[02:00] net: eof!(read) socket 13
[02:00] Lost connection while identing [dc-node.bytebistro.com/43135]
|
|
|
| Back to top |
|
 |
unavailable Voice
Joined: 12 Sep 2009 Posts: 2
|
Posted: Sat Sep 12, 2009 3:15 am Post subject: |
|
|
| What about a version to phpBB? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|