13
proxies = urllib.getproxies()
15
if 'https' not in proxies and \
17
url = proxies['http'].replace("http://", "https://")
18
result['https'] = pymsn.Proxy(url)
19
for type, url in proxies.items():
20
if type == 'no': continue
21
if type == 'https' and url.startswith('http://'):
22
url = url.replace('http://', 'https://', 1)
23
result[type] = pymsn.Proxy(url)
26
class ClientEvents(pymsn.event.ClientEventInterface):
27
def on_client_state_changed(self, state):
28
if state == pymsn.event.ClientState.CLOSED:
30
elif state == pymsn.event.ClientState.OPEN:
31
self._client.profile.presence = pymsn.Presence.ONLINE
34
def on_client_error(self, error_type, error):
35
print "ERROR :", error_type, " ->", error
37
class InviteEvents(pymsn.event.InviteEventInterface):
38
def __init__(self, client):
40
def on_invite_conversation(self, conversation):
41
self.conv = conversation
43
class AnnoyingConversation(pymsn.event.ConversationEventInterface):
45
def __init__(self, conv, body):
46
pymsn.event.ConversationEventInterface.__init__(self, conv)
49
self.last_message = ""
52
def on_conversation_user_joined(self, contact):
53
gobject.timeout_add(5000, self.annoy_user)
57
self._client.send_text_message(pymsn.ConversationMessage(self.body))
61
def on_conversation_user_typing(self, contact):
65
def on_conversation_message_received(self, sender, message):
66
self.last_message = message.content
67
self.last_sender = sender.account
70
def on_conversation_error(self, error_type, error):
71
print "ERROR :", error_type, " ->", error
73
class ClientMSN(pymsn.Client):
74
def __init__(self, account, debug=False):
75
server = ('messenger.hotmail.com', 1863)
77
self.main_loop = gobject.MainLoop()
78
self.is_connected = False
80
self._exception = None
83
self.account = account
84
self.is_talking = False
87
self._convo_events = None
89
pymsn.Client.__init__(self, server, proxies = get_proxies())
90
self._event_handler = ClientEvents(self)
91
self._invite_events = InviteEvents(self)
93
def connect(self, register):
94
self.is_connected = True
95
self.login(*self.account)
99
self.is_connected = False
102
def start_conversation(self, userid, body):
103
self.is_talking = True
104
contacts = self.address_book.contacts.\
105
search_by_presence(pymsn.Presence.ONLINE)
107
if len(contacts) == 0:
108
print "No online contacts"
111
for contact in contacts:
112
if contact.account == userid:
113
print "Inviting %s for a conversation" % contact.display_name
114
self.conv = pymsn.Conversation(self, [contact])
115
self.current = contact.account
116
self._convo_events = AnnoyingConversation(self.conv, body)
117
self._convo_events.talking = True
120
def send_text_message_to_current_conversation(self, body):
121
self.conv.send_text_message(pymsn.ConversationMessage(body))
129
def connection_stablished(self):
130
if self.state == pymsn.event.ClientState.OPEN: