IRCBotas

Iš Žinynas.
Jump to navigation Jump to search

This is MediaWiki integration scripts intergrating IRC between MediaWiki/php and eggdrop with tcl script. Copyright (c) 2013 \dev\null. Licensed under GPLv2. Script reports all article/talk or other changes to specified IRC Channel.

It's usually a hack by replacing UDP (User Datagram Protocol) to Transmission Control Protocol TCP, because all the tcl libs for support to UDP are outdated and not supported. By default MediaWiki still uses UDP as official version, so we changed it and written a simple tcl script for eggdrop to handle the incoming connections from MediaWiki and put them on the IRC Channel. Everything works! ;-)

We are planning to do much more work on integrating MediaWiki with IRC


--\dev\null 08:19, 11 spalio 2013 (EEST)

Output to IRC[keisti]

MediaWiki already outputs text with colors like this

 [[File has modification time in the future]]  http://wiki.eofnet.lt/w/index.php?diff=3161&oldid=3160&rcid=3579 * \dev\null * (+5) 

If your IRC Client does not support colors then you will see something like this:

14[[07File has modification time in the future14]]4 10 02http://wiki.eofnet.lt/w/index.php?diff=3162&oldid=3161&rcid=3580 5* 03\dev\null 5* (-6) 10

Mediawiki[keisti]

You will need to open includes/RecentChange.php and do search for a function

 
        public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
                global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
                # Assume default for standard RC case
                $address = $address ? $address : $wgRC2UDPAddress;
                $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
                $port = $port ? $port : $wgRC2UDPPort;
                # Notify external application via UDP
                if ( $address ) {
                        $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
                        if ( $conn ) {
                                $line = $prefix . $line;
                                wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
                                socket_sendto( $conn, $line, strlen( $line ), 0, $address, $port );
                                socket_close( $conn );
                                return true;
                        } else {
                                wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
                        }
                }
                return false;
        }

And replace it with this function:

 
        public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
                global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
                # Assume default for standard RC case
                $address = $address ? $address : $wgRC2UDPAddress;
                $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
                $port = $port ? $port : $wgRC2UDPPort;
                # Notify external application via UDP
                if ( $address ) {
                        $conn = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
                        socket_connect($conn, $address, $port);
                        if ($conn) {
                                $line = $prefix . $line;   
                                socket_write($conn, $line);
                                wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
                                socket_close( $conn );
                                return true;
                        } else { 
                                wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
                        }
                }
                return false;
        }

Now open LocalSettings.php add these line, just change port with whatever you want:

# IRC
$wgRC2UDPAddress = '127.0.0.1'; # the host where the IRC client is running
$wgRC2UDPPort = 4013; # or whatever
$wgRC2UDPPrefix = ;


TCL for eggdrop (version >=1.8)[keisti]

To install put it eggdrop/scripts directory and load from eggdrop.conf, just change parameters if you need. It's very simple script. Sorry no any security mechanisms implemented yet, but if you use it on your own local machine/server host everything will be okay, also you can use iptables/packet filter to block applications/connections to it.

 # This script dedicated for displaying recent changes from http://wiki.eofnet.lt using tcp socket
 # Can work with any MediaWiki or other service, just use it at your own rist!
 # (c) 2013 \dev\null, EofNET LAB07.
 # v1.0 - Initial Release 
 ##################### CONFIGURATION #######################
 # port to bind
 set port 4013
 # ip to bind
 set host 127.0.0.1  
 # in what channel it will be used ?
 set channel #ubuntu
 ###########################################################

 set TcpSocket [socket -server main -myaddr $host $port]
 
 proc main { sock host port } {
   fconfigure $sock -buffering line
   fileevent $sock readable [action $sock $host $port]
 }
 
 proc action { sock host port } {
   global channel
   if {![eof $sock]} {
   set data [gets $sock]
   if {$data != ""} {
   putquick "PRIVMSG $channel :$data"
   }
   }  {
   close $sock
   }
 }
 putlog "tcport.tcl loaded"