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, xchat-nick-pidgin-status.py:
#!/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:
# http://arstechnica.com/reviews/apps/pidgin-2-0.ars/4
# http://arstechnica.com/journals/linux.ars/2007/08/29/send-twitter-updates-from-xchat-using-python
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
STATUS_AVAILABLE = 2
STATUS_AWAY = 5
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)
else:
# 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
purple.PurpleSavedstatusActivate(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)