Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Last active December 15, 2015 22:29
Show Gist options
  • Save AstraLuma/5333897 to your computer and use it in GitHub Desktop.
Save AstraLuma/5333897 to your computer and use it in GitHub Desktop.
diff --git a/includes/functions_posting.php b/includes/functions_posting.php
index a94364e..b848faa 100644
--- a/includes/functions_posting.php
+++ b/includes/functions_posting.php
@@ -1179,6 +1179,19 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id
trigger_error('NO_MODE');
}
+ // IRC Notifications
+ include_once($phpbb_root_path . 'ircnotify/notify.php');
+ if (function_exists('irc_notify')) {
+ $url = generate_board_url()."/viewtopic.php?f=$forum_id&t=$topic_id&p=$post_id#p$post_id";
+ if ($topic_notification) {
+ irc_notify("reply", $forum_id, $forum_name, $topic_id, $topic_title, $post_id, $subject, $url);
+ } else if ($forum_notification) {
+ irc_notify("new", $forum_id, $forum_name, $topic_id, $topic_title, $post_id, $subject, $url);
+ }
+ } else {
+ error_log("IRC notifications not configured.");
+ }
+
if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify']))
{
return;
diff --git a/ircnotify/iiconfig.sh b/ircnotify/iiconfig.sh
new file mode 100644
index 0000000..d7f2582
--- /dev/null
+++ b/ircnotify/iiconfig.sh
@@ -0,0 +1,9 @@
+# Make sure these values match notify.php
+IRC_ROOT=/tmp/dnd
+IRC_SERVER=chat.dftba.net
+IRC_CHANNEL=\#dnd-test
+
+IRC_NICK=DnD
+IRC_NICKSERV_PASS="foobar"
+II_OPS=" -f \"DnD Notify Bot\""
+
diff --git a/ircnotify/killii b/ircnotify/killii
new file mode 100755
index 0000000..4c38a0d
--- /dev/null
+++ b/ircnotify/killii
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+. `dirname $0`/iiconfig.sh
+
+kill `cat $IRC_ROOT/pid`
+rm -r $IRC_ROOT
diff --git a/ircnotify/notify.php b/ircnotify/notify.php
new file mode 100644
index 0000000..23fba33
--- /dev/null
+++ b/ircnotify/notify.php
@@ -0,0 +1,31 @@
+<?php
+# Make sure these values match iiconfig.sh
+define('IRC_ROOT', '/tmp/dnd');
+define('IRC_SERVER', 'chat.dftba.net');
+define('IRC_CHANNEL', '#dnd-test');
+
+global $IRC_IGNORE_FORUMS, $IRC_IGNORE_TOPICS;
+$IRC_IGNORE_FORUMS = array(); # Array of numeric forum IDs to omit from notifications
+$IRC_IGNORE_TOPICS = array(); # Array of numeric topic IDs to omit from notifications
+
+
+function irc_notify($type, $forum_id, $forum_name, $topic_id, $topic_name, $post_id, $subject, $url) {
+ global $IRC_IGNORE_FORUMS, $IRC_IGNORE_TOPICS;
+ if (in_array($forum_id, $IRC_IGNORE_FORUMS)) {
+ return;
+ }
+ if (in_array($topic_id, $IRC_IGNORE_TOPICS)) {
+ return;
+ }
+ switch($type) {
+ case 'reply':
+ $msg = "Reply to $topic_name in $forum_name $url";
+ break;
+ case 'new':
+ $msg = "New topic in $forum_name: $topic_name $url";
+ break;
+ }
+ file_put_contents(IRC_ROOT.'/'.IRC_SERVER.'/'.IRC_CHANNEL.'/in', $msg."\n");
+}
+
+?>
diff --git a/ircnotify/startii b/ircnotify/startii
new file mode 100755
index 0000000..5e291c5
--- /dev/null
+++ b/ircnotify/startii
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+. `dirname $0`/iiconfig.sh
+
+ii -i $IRC_ROOT -s $IRC_SERVER -n $IRC_NICK $II_OPS &
+pid=$!
+
+sleep 5
+
+echo $pid > $IRC_ROOT/pid
+echo /mode $IRC_NICK +B >> $IRC_ROOT/$IRC_SERVER/in
+echo /j NickServ IDENTIFY $NICKSERV_PASS >> $IRC_ROOT/$IRC_SERVER/in
+echo /join $IRC_CHANNEL >> $IRC_ROOT/$IRC_SERVER/in
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment