-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpidgin-message.py
executable file
·99 lines (82 loc) · 3.04 KB
/
pidgin-message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# pidgin.py
#
# Original Copyright 2012 Ángel Araya <angel@angel-TECRA-A8>
# def listener(conv, type):
# print (type) #Debug line
# if type == 4: # Corresponds to UNSEEN_STATE_CHANGED and others I can't distinguish now
# print ("Status changed, possibly read messages")
import sys
from subprocess import call
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")
ims = purple.PurpleGetIms()
if len(sys.argv) == 1:
print "Usage: pidgin-message user message (no quotes needed)\n"
print "number of open chats:", len(ims)
print
for conv in ims:
print purple.PurpleConversationGetName(conv) + " (" + \
purple.PurpleConversationGetTitle(conv) + ")"
# print "Focus: ", purple.PurpleConversationHasFocus(conv)
# print "IM data: ", purple.PurpleConversationGetImData(conv)
# print "data: ", purple.PurpleConversationGetChatData(conv)
# print
exit()
user = sys.argv[1] # first argument = user name
msg = ' '.join(sys.argv[2:]) # the rest is message
# msg = sys.argv[1][1:-1] # remove quotes
if msg == "":
print "Usage: pidgin-message user message (no quotes needed)\n"
exit()
# if len(ims) == 1, always send to that person
# if len != 1, send to Pudding if Pudding exists
# if len != 1, send to Hanasaki if Hanasaki exists
if user == "auto":
if len(ims) != 1:
call(["beep", "-f", "100"])
exit()
for conv in ims:
purple.PurpleConvImSend(purple.PurpleConvIm(conv), msg)
exit()
# to specific user:
for conv in ims:
if purple.PurpleConversationGetName(conv) == user:
purple.PurpleConvImSend(purple.PurpleConvIm(conv), msg)
exit()
#~ if len(ims) == 1:
#~ for conv in ims:
#~ purple.PurpleConvImSend(purple.PurpleConvIm(conv), msg)
#~ exit()
# 軟軟小布丁
#~ for conv in ims:
#~ # print "conversation number:", conv
#~ # purple.PurpleConversationGetTitle(conv).encode('utf-8-sig') == "軟軟小布丁":
#~ if purple.PurpleConversationGetName(conv) == "886939769022": # 軟軟小布丁's number
#~ # print purple.PurpleConvIm(conv)
#~ # print "sending message:", msg
#~ purple.PurpleConvImSend(purple.PurpleConvIm(conv), msg)
#~ exit()
# Hanasaki
#~ for conv in ims:
#~ if purple.PurpleConversationGetName(conv) == "8615010095417": # Hanasaki
#~ purple.PurpleConvImSend(purple.PurpleConvIm(conv), msg)
#~ exit()
# if len != 1, send to all windows that are on screen
#~ for conv in ims:
#~ print purple.PurpleConversationGetName(conv)
#~ print "Focus:", purple.PurpleConversationHasFocus(conv)
#~ print "IM data: ", purple.PurpleConversationGetImData(conv)
#~ print "data: ", purple.PurpleConversationGetChatData(conv)
#~ print
# bus.add_signal_receiver(listener,
# dbus_interface="im.pidgin.purple.PurpleInterface",
# signal_name="ConversationUpdated")
# loop = gobject.MainLoop()
# loop.run()