3 # This is a simple purple notification server.
4 # It shows notifications when your buddy signs on or you get an IM message.
6 # This script requires Python 2.4 and PyGTK bindings
8 # Note that all function names are resolved dynamically, no
9 # purple-specific library is needed.
13 import dbus
.decorators
17 def ensureimconversation(conversation
, account
, name
):
22 return purple
.PurpleConversationNew(1, account
, name
)
24 def receivedimmsg(account
, name
, message
, conversation
, flags
):
25 buddy
= purple
.PurpleFindBuddy(account
, name
)
27 alias
= purple
.PurpleBuddyGetAlias(buddy
)
31 text
= "%s says %s" % (alias
, message
)
32 code
= os
.spawnlp(os
.P_WAIT
, "xmessage", "xmessage", "-buttons",
33 "'So what?','Show me',Close,Abuse", text
)
35 if code
== 101: # so what?
38 conversation
= ensureimconversation(conversation
, account
, name
)
40 if code
== 102: # show me
41 window
= purple
.PurpleConversationGetWindow(conversation
)
42 purple
.PurpleConvWindowRaise(window
)
44 if code
== 103: # close
45 purple
.PurpleConversationDestroy(conversation
)
47 if code
== 104: # abuse
48 im
= purple
.PurpleConversationGetImData(conversation
)
49 purple
.PurpleConvImSend(im
, "Go away you f...")
52 def buddysignedon(buddyid
):
53 alias
= purple
.PurpleBuddyGetAlias(buddyid
)
54 text
= "%s is online" % alias
56 code
= os
.spawnlp(os
.P_WAIT
, "xmessage", "xmessage", "-buttons",
57 "'So what?','Let's talk'", text
)
59 if code
== 101: # so what?
62 if code
== 102: # talk
63 name
= purple
.PurpleBuddyGetName(buddyid
)
64 account
= purple
.PurpleBuddyGetAccount(buddyid
)
65 purple
.PurpleConversationNew(1, account
, name
)
68 bus
= dbus
.SessionBus()
69 obj
= bus
.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
70 purple
= dbus
.Interface(obj
, "im.pidgin.purple.PurpleInterface")
72 bus
.add_signal_receiver(receivedimmsg
,
73 dbus_interface
= "im.pidgin.purple.PurpleInterface",
74 signal_name
= "ReceivedImMsg")
76 bus
.add_signal_receiver(buddysignedon
,
77 dbus_interface
= "im.pidgin.purple.PurpleInterface",
78 signal_name
= "BuddySignedOn")
80 print "This is a simple purple notification server."
81 print "It shows notifications when your buddy signs on or you get an IM message."
83 loop
= gobject
.MainLoop()