Wednesday, June 25, 2008

Recent Hacks: and

The Mono a11y team has weekly iteration meetings in IRC, and we post the logs to the Mono wiki. Our version of MediaWiki doesn't automatically prettify IRC logs, so for awhile I was using Jamie Zawinski's to create HTML tables. Today I hacked it up to produce MediaWiki tables instead. I call it Fixes welcome (or better suggestions).

Also, I now live on IRC. Some people prefer to get me through IM, so I always have Pidgin running, but my online presence is mostly reflected in my IRC nick. I'm forgetful, so I kept noticing that I was "available" in Pidgin even though my IRC nick was "sandy|lunch", or that when I changed my nick from "sandy|brb" to "sandy" my Pidgin status would stay the same. I decided to automate that shit. Based on a bunch of useful code from Arstechnica's Ryan Paul, I present to you my first xchat plugin,

#!/usr/bin/env python

# Sets Pidgin status from XChat nick, assuming you use a style like:
# mynick => Available (status "Workin")
# mynick|busy => Away (status "busy")
# Hobbled together by Sandy Armstrong from code
# written by Ryan Paul (segphault) of Ars Technica:

import xchat, dbus

# Describe the plug-in metadata for XChat
__module_name__ = "Pidgin Status Plug-in"
__module_version__ = "1.0"
__module_description__ = "Set Pidgin status according to XChat nick"

# Specify status ID values

def nick(words, word_eol, userdata):
# Get new nick
if len(words) < 2:
return None
new_nick = words[1]

# Check for status
pipe_index = new_nick.find("|")
if pipe_index > 0 and pipe_index < len(new_nick):
message = new_nick[pipe_index + 1:]
# set away with status message
set_status("", STATUS_AWAY, message)
# set available
set_status("", STATUS_AVAILABLE, "Workin")

def set_status(name, kind, message):
# Create a new saved status with the specified name and kind
status = purple.PurpleSavedstatusNew(name, kind)
# Associate the specified availability message with the new saved status
purple.PurpleSavedstatusSetMessage(status, message)
# Activate the new saved status

# Initiate a connection to the Session Bus
bus = dbus.SessionBus()

# Associate Pidgin's D-Bus interface with Python objects
obj = bus.get_object(
"im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

# Associate the nick function with the /nick command in XChat
xchat.hook_command("nick", nick)


Anonymous said...

This is a really bad idea - not the plugin in itself, but what it relies on. It is generally frowned upon to have your status in your nick on IRC.

I'd recommend using the AWAY feature of the IRC protocol (/away [reason] in most clients) instead.

Sandy said...

@some visitor: In the IRC communities I frequent, the practice of including status in your nick is very common. Even if I were to use the AWAY feature (which nobody ever seems to use), I would continue to change my nick.

It should be easy to modify the plugin to respond to the /away command, of course.

Anonymous said...

Why don't you use pidgin for IRC?

Sandy said...

@anonymous: Because Pidgin is a horrible IRC client. Also, my *real* IRC client is an irssi instance running on my home server, so that I will always be connected (good for making logs, etc). I can connect to it with any IRC client I like using irssi_proxy. But Pidgin, being a horrible IRC client, tells irssi to close all channels when I quit, defeating the whole point of my setup.

Marius Gedminas said...

Coincidentally, Ian Weller recently sent me a patch for to support producing MediaWiki markup.

I was wondering then (and am still wondering now) whether the script should do some sort of quoting to prevent random things said by people on IRC confusing the MediaWiki parser. I'm not myself familiar with MediaWiki.