Pidgin autoresponder, using Jabberwacky
Daniel - Sep 28, 2009 - Humour Tech CodeThe following python script will auto respond to pidgin contacts when your status is either away or idle, using the well known Jabberwacky bot. Just a bit of fun. Tested on Ubuntu linux.
#!/usr/bin/env python
import re, urllib, os
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object('im.pidgin.purple.PurpleService', '/im/pidgin/purple/PurpleObject')
purple = dbus.Interface(obj, 'im.pidgin.purple.PurpleInterface')
class Jabber(object):
regex = ('vText%s|' * 7) %tuple(range(2, 9)) + 'conv_id|prevref'
regex = re.compile('NAME=(%s) TYPE=hidden VALUE="([^"]*)"' % regex, re.M)
data = {}
def initiate(self):
return self.speak()
def speak(self, text=''):
if self.data:
self.data['vText1'] = text
html = urllib.urlopen('http://jabberwacky.com/', urllib.urlencode(self.data)).read()
self.data = dict(self.regex.findall(html))
return self.data['vText2']
conversations = {}
def msg(account, sender, msg, convo, flags):
if purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent()) in (3, 5):
if not convo in conversations:
conversations[convo] = Jabber()
msg = conversations[convo].initiate()
else:
msg = conversations[convo].speak(msg)
purple.PurpleConvImSend(purple.PurpleConvIm(convo), msg)
bus.add_signal_receiver(msg, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg")
loop = gobject.MainLoop()
loop.run()
To use: place in 'pidgin_jabberwacky.py', then execute! The script should run in the background, and will only come into play when your status is set to 'away' or 'idle'.

Anongimis
Dbus should be platform independent?
Daniel
Anongimis: yeah, you're right, bad call on my part - just me making assumptions.
Brian Kennedy
This is awesome, and I'm definitely going to use it.