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.
11 from __future__
import absolute_import
, division
, print_function
17 import dbus
.decorators
21 def ensureimconversation(conversation
, account
, name
):
26 return purple
.PurpleConversationNew(1, account
, name
)
29 def receivedimmsg(account
, name
, message
, conversation
, flags
):
30 buddy
= purple
.PurpleFindBuddy(account
, name
)
32 alias
= purple
.PurpleBuddyGetAlias(buddy
)
36 text
= "%s says %s" % (alias
, message
)
37 code
= os
.spawnlp(os
.P_WAIT
, "xmessage", "xmessage", "-buttons",
38 "'So what?','Show me',Close,Abuse", text
)
40 if code
== 101: # so what?
43 conversation
= ensureimconversation(conversation
, account
, name
)
45 if code
== 102: # show me
46 window
= purple
.PurpleConversationGetWindow(conversation
)
47 purple
.PurpleConvWindowRaise(window
)
49 if code
== 103: # close
50 purple
.PurpleConversationDestroy(conversation
)
52 if code
== 104: # abuse
53 im
= purple
.PurpleConversationGetImData(conversation
)
54 purple
.PurpleConvImSend(im
, "Go away you f...")
57 def buddysignedon(buddyid
):
58 alias
= purple
.PurpleBuddyGetAlias(buddyid
)
59 text
= "%s is online" % alias
61 code
= os
.spawnlp(os
.P_WAIT
, "xmessage", "xmessage", "-buttons",
62 "'So what?','Let's talk'", text
)
64 if code
== 101: # so what?
67 if code
== 102: # talk
68 name
= purple
.PurpleBuddyGetName(buddyid
)
69 account
= purple
.PurpleBuddyGetAccount(buddyid
)
70 purple
.PurpleConversationNew(1, account
, name
)
73 bus
= dbus
.SessionBus()
74 obj
= bus
.get_object("im.pidgin.purple.PurpleService",
75 "/im/pidgin/purple/PurpleObject")
76 purple
= dbus
.Interface(obj
, "im.pidgin.purple.PurpleInterface")
78 bus
.add_signal_receiver(receivedimmsg
,
79 dbus_interface
="im.pidgin.purple.PurpleInterface",
80 signal_name
="ReceivedImMsg")
82 bus
.add_signal_receiver(buddysignedon
,
83 dbus_interface
="im.pidgin.purple.PurpleInterface",
84 signal_name
="BuddySignedOn")
86 print("This is a simple purple notification server.")
87 print("It shows notifications when your buddy signs on or you get an "
90 loop
= gobject
.MainLoop()