| 1 #!/usr/bin/env python |
|
| 2 |
|
| 3 # This is a simple gaim notification server. |
|
| 4 # It shows notifications when your buddy signs on or you get an IM message. |
|
| 5 # |
|
| 6 # This script requires Python 2.4 and PyGTK bindings |
|
| 7 # |
|
| 8 # Note that all function names are resolved dynamically, no |
|
| 9 # gaim-specific library is needed. |
|
| 10 |
|
| 11 import dbus |
|
| 12 import dbus.glib |
|
| 13 import dbus.decorators |
|
| 14 import gobject |
|
| 15 import os |
|
| 16 |
|
| 17 def ensureimconversation(conversation, account, name): |
|
| 18 if conversation != 0: |
|
| 19 return conversation |
|
| 20 else: |
|
| 21 # 1 = GAIM_CONV_IM |
|
| 22 return gaim.GaimConversationNew(1, account, name) |
|
| 23 |
|
| 24 def receivedimmsg(account, name, message, conversation, flags): |
|
| 25 buddy = gaim.GaimFindBuddy(account, name) |
|
| 26 if buddy != 0: |
|
| 27 alias = gaim.GaimBuddyGetAlias(buddy) |
|
| 28 else: |
|
| 29 alias = name |
|
| 30 |
|
| 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) |
|
| 34 |
|
| 35 if code == 101: # so what? |
|
| 36 pass |
|
| 37 else: |
|
| 38 conversation = ensureimconversation(conversation, account, name) |
|
| 39 |
|
| 40 if code == 102: # show me |
|
| 41 window = gaim.GaimConversationGetWindow(conversation) |
|
| 42 gaim.GaimConvWindowRaise(window) |
|
| 43 |
|
| 44 if code == 103: # close |
|
| 45 gaim.GaimConversationDestroy(conversation) |
|
| 46 |
|
| 47 if code == 104: # abuse |
|
| 48 im = gaim.GaimConversationGetImData(conversation) |
|
| 49 gaim.GaimConvImSend(im, "Go away you f...") |
|
| 50 |
|
| 51 |
|
| 52 def buddysignedon(buddyid): |
|
| 53 alias = gaim.GaimBuddyGetAlias(buddyid) |
|
| 54 text = "%s is online" % alias |
|
| 55 |
|
| 56 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", |
|
| 57 "'So what?','Let's talk'", text) |
|
| 58 |
|
| 59 if code == 101: # so what? |
|
| 60 pass |
|
| 61 |
|
| 62 if code == 102: # let's talk |
|
| 63 name = gaim.GaimBuddyGetName(buddyid) |
|
| 64 account = gaim.GaimBuddyGetAccount(buddyid) |
|
| 65 gaim.GaimConversationNew(1, account, name) |
|
| 66 |
|
| 67 |
|
| 68 bus = dbus.SessionBus() |
|
| 69 obj = bus.get_object("org.gaim.GaimService", "/org/gaim/GaimObject") |
|
| 70 gaim = dbus.Interface(obj, "org.gaim.GaimInterface") |
|
| 71 |
|
| 72 bus.add_signal_receiver(receivedimmsg, |
|
| 73 dbus_interface = "org.gaim.GaimInterface", |
|
| 74 signal_name = "ReceivedImMsg") |
|
| 75 |
|
| 76 bus.add_signal_receiver(buddysignedon, |
|
| 77 dbus_interface = "org.gaim.GaimInterface", |
|
| 78 signal_name = "BuddySignedOn") |
|
| 79 |
|
| 80 print """This is a simple gaim notification server. |
|
| 81 It shows notifications when your buddy signs on or you get an IM message.""" |
|
| 82 |
|
| 83 loop = gobject.MainLoop() |
|
| 84 loop.run() |
|
| 85 |
|
| 86 |
|