--- /dev/null
+#! /usr/bin/env python
+#
+# usage: mxircecho.py nickname server
+import sys
+sys.path.append('/home/kate/pylib/lib/python2.2/site-packages')
+
+from ircbot import SingleServerIRCBot
+import threading
+
+class EchoReader(threading.Thread):
+ def __init__(self, bot):
+ threading.Thread.__init__(self)
+ self.abot = bot
+
+ def run(self):
+ while True:
+ try:
+ s = raw_input()
+ sp = s.split("\t")
+ if len(sp) == 2:
+ channel = sp[0]
+ text = sp[1]
+
+ if channel not in bot.chans:
+ bot.chans.append(channel)
+ bot.connection.join(channel)
+
+
+ # this throws an exception if not connected.
+ bot.connection.privmsg(channel, text)
+ except EOFError:
+ # Once the input is finished, the bot should exit
+ break
+ except:
+ pass
+
+class EchoBot(SingleServerIRCBot):
+ def __init__(self, chans, nickname, server):
+ print "*** Connecting to IRC server %s..." % server
+ SingleServerIRCBot.__init__(self, [(server, 6667)], nickname, "IRC echo bot")
+ self.chans = chans
+
+ def on_nicknameinuse(self, c, e):
+ c.nick(c.get_nickname() + "_")
+
+ def on_welcome(self, c, e):
+ print "*** Connected"
+ for chan in self.chans:
+ c.join(chan)
+
+bot = EchoBot([], sys.argv[1], sys.argv[2]);
+sthr = EchoReader(bot)
+sthr.start()
+bot.start()
+++ /dev/null
-<?php
-
-$ircNick = "wikipedia_rc";
-$rooms = array("en" => 1, "fr" => 1, "de" => 1);
-$ircServer = "irc.freenode.net";
-$ircSockName = "tcp://$ircServer";
-$ircPort = 6667;
-$minDelay = 0.5;
-$ircReadTimeout = 200000; # us
-$ircWriteTimeout = 30; # s
-$fmB = chr(2);
-$fmU = chr(31);
-$queueId = 337055475;
-$maxMessageSize = 16384;
-
-#-----------------------------------------------------------------------------
-
-# Get queue
-
-$ircPassword = mt_rand(0xffffffff);
-$hostname = getenv('SERVER_NAME');
-
-$queue = msg_get_queue($queueId);
-
-if ( !$queue ) {
- print "Could not open RC message queue\n";
- exit;
-}
-emptyQueue( $queue );
-
-# Initialise the IRC connection
-$sockIRC = fsockopen( $ircSockName, $ircPort );
-if ( !$sockIRC ) {
- print "Could not open IRC connection\n";
- exit;
-}
-stream_set_timeout($sockIRC, 0, $ircWriteTimeout);
-
-fwrite( $sockIRC,
- "PASS $ircPassword\r\n" .
- "NICK $ircNick\r\n" .
- "USER recentchanges $hostname $ircServer Wikipedia RC->IRC bot\r\n"
-);
-
-foreach ( $rooms as $room => $v ) {
- joinRoom( $sockIRC, $room );
-}
-
-$readObjs = array( $sockIRC, $queue );
-
-# Main input loop
-$die = false;
-while ( !$die ) {
- # RC input
- $msgType = 0;
- $entry = false;
- if (!msg_receive($queue, 0, $msgType, $maxMessageSize, $entry, true, MSG_IPC_NOWAIT)) {
- $entry = false;
- }
- if (is_array( $entry )) {
- $out = getIrcOutput( $sockIRC, $entry );
- fwrite( $sockIRC, $out );
- }
-
- # IRC input
- stream_set_timeout($sockIRC, 0, $ircReadTimeout);
- $line = rtrim(fgets( $sockIRC ));
- stream_set_timeout($sockIRC, 0, $ircWriteTimeout);
- if ( $line ) {
- $die = processIrcInput( $sockIRC, $line );
- }
-}
-exit();
-
-#--------------------------------------------------------------
-function delayMin()
-{
- static $lastTime = 0;
- global $minDelay;
- if ( !$lastTime ) {
- $lastTime = getMicroTime();
- }
- $curTime = getMicroTime();
- $timeDifference = $curTime - $lastTime;
- if ( $timeDifference < $minDelay ) {
- usleep( ($minDelay - $timeDifference) *1000000 );
- }
- $lastTime = $curTime;
-}
-
-function getMicroTime()
-{
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
-}
-
-function getIrcOutput( $socket, $in )
-{
- global $rooms;
-
- delayMin();
- $bad = array("\n", "\r");
- $empty = array("", "");
- $comment = $in['comment'];
- $title = $in['prefixedDBkey'];
- $user = $in['userText'];
- $lastid = IntVal($in['lastOldid']);
- $flag = ($in['minor'] ? "M" : "") . ($in['new'] ? "N" : "");
- $lang = $in['lang'];
- if ( $lang == "w" ) {
- $lang = "en";
- }
-
- if ( !array_key_exists( $rooms, $lang ) ) {
- return "";
- }
- $room = "#{$lang}rc.wikipedia";
-
- if ( $in['new'] ) {
- $url = "http://$lang.wikipedia.org/wiki/" . urlencode($title);
- } else {
- $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode($title) .
- "&diff=0&oldid=$lastid";
- }
- $spaceTitle = str_replace("_", " ", $title);
-
- $beep = "";
- if ( $patterns ) {
- foreach ( $patterns as $pattern ) {
- if ( preg_match( $pattern, $comment ) ) {
- $beep = chr(7);
- break;
- }
- }
- }
- if ( $comment !== "" ) {
- $comment = "($comment)";
- }
-
- $fullString = str_replace($bad, $empty,
- "$beep$fmB$spaceTitle$fmB $flag $url $user $comment");
- $fullString = "PRIVMSG $room :$fullString\r\n";
- return $fullString;
-}
-
-function joinRoom( $sock, $room )
-{
- global $rooms;
- $rooms[$room] = 1;
- fwrite( $sock, "JOIN #{$room}rc.wikipedia\r\n" );
-}
-
-function partRoom( $sock, $room )
-{
- global $rooms;
- unset( $rooms[$room] );
- fwrite( $sock, "PART #{$room}rc.wikipedia\r\n" );
-}
-
-function processIrcInput( $sock, $line )
-{
- global $rooms;
-
- $die = false;
- $args = explode( " ", $line );
-
- if ( $args[0] == "PING" ) {
- fwrite( $sock, "PONG {$args[1]}\r\n" );
- } elseif ( $args[0]{0} == ":" ) {
- $name = array_shift( $args );
- $name = substr($name, 1);
- $cmd = array_shift( $args );
- if ( $cmd == "PRIVMSG" ) {
- $msgRoom = array_shift( $args );
- if ( $args[0] == "die" ) {
- $die = true;
- } elseif ( $args[0] == "join" ) {
- joinRoom( $args[1] );
- } elseif ( $args[0] == "part" ) {
- partRoom( $args[1] );
- }
- }
- }
-}
-
-function emptyQueue( $id )
-{
- while ( msg_receive($queue, 0, $msgType, $maxMessageSize, $entry, true, MSG_IPC_NOWAIT));
-}
-
-?>
-
ini_set( "display_errors", 1 );
$wgCommandLineMode = true;
-
+$optionsWithArgs = array( 'm' );
require_once("../maintenance/commandLine.inc" );
+if ( !empty( $options['m'] ) ) {
+ $channel = $options['m'];
+} else {
+ $channel = false;
+}
+
+if ($lang == "commons") $site = "wikimedia";
+
if ($wgWikiFarm) {
- $serverName="$lang.wikipedia.org";
+ $serverName="$lang.$site.org";
$newPageURLFirstPart="http://$serverName/wiki/";
$URLFirstPart="http://$serverName/w/wiki.phtml?title=";
} else {
$wgCommandLineMode = true;
set_time_limit(0);
-sleep(30);
-$dbr =& wfGetDB( DB_SLAVE );
-$recentchanges = $dbr->tableName( 'recentchanges' );
+if ( empty($options['b']) ) {
+ $bots = "AND NOT(rc_bot)";
+} else {
+ $bots = "";
+}
+
+if (isset($args[0]) && isset($args[1])) {
+ $lowest = $args[0];
+ $highest = $args[1];
+ #$what = $args[0][0];
+ #$highest = $args[0][1];
+}
+#sleep(30);
$res = $dbr->query( "SELECT rc_timestamp FROM $recentchanges ORDER BY rc_timestamp DESC LIMIT 1" );
$row = $dbr->fetchObject( $res );
$empty = array("", "");
$comment = str_replace($bad, $empty, $comment);
$title = str_replace($bad, $empty, $title);
+ $a = $title[0];
+ if ($a < 'A' || $a > 'Z')
+ $a = 'Z';
+ #if ((isset($highest)) && (($what == "<" && $a > "$highest") || ($what == ">" && $a <= "$highest")))
+ if ((isset($highest) && ($a > $highest)) || (isset($lowest) && $a <= $lowest))
+ continue;
$user = str_replace($bad, $empty, $row->rc_user_text);
$lastid = IntVal($row->rc_last_oldid);
$flag = ($row->rc_minor ? "M" : "") . ($row->rc_new ? "N" : "");
+ $stupid_urlencode = array("%2F", "%3A");
+ $haha_take_that = array("/", ":");
if ( $row->rc_new ) {
$url = $newPageURLFirstPart . urlencode($title);
} else {
$url = $URLFirstPart . urlencode($title) .
"&diff=0&oldid=$lastid";
}
+ $url = str_replace($stupid_urlencode, $haha_take_that, $url);
$title = str_replace("_", " ", $title);
# see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
# no colour (\003) switches back to the term default
- $fullString = "\00303$title\0037 $flag\00310 $url \0037*\003 $user \0037*\003 $comment\n";
+ $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
+ $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
+ "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 \00310$comment\003\n";
+ if ( $channel ) {
+ $fullString = "$channel\t$fullString";
+ }
print( $fullString );
$oldTimestamp = $row->rc_timestamp;