annotate participant.py @ 5:cb0daec4b778

Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 16 Aug 2009 17:59:00 +0200
parents 012593ed4e12
children 7cb790f5f243
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 #!/usr/bin/env python
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4 # This program is free software: you can redistribute it and/or modify
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # the Free Software Foundation, either version 3 of the License, or
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 # (at your option) any later version.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 # GNU General Public License for more details.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18 import muc
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
19 xmpp = muc.xmpp
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
20 del muc
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
21 import irclib
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
22 from encoding import *
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
23 from threading import Thread
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
24 from time import sleep
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
25
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
26
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
27 class participant:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
28 def __init__(self, owner_bridge, protocol, nickname):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
29 self.bridge = owner_bridge
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
30 self.protocol = protocol
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
31 self.nickname = nickname
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
32 self.irc_connection = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
33 self.xmpp_c = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
34 if protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
35 self.createDuplicateOnIRC()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
36 elif protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
37 self.createDuplicateOnXMPP()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
38 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 raise Exception('Internal Error: bad protocol')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
40 quit(1)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
41
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43 def createDuplicateOnXMPP(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
44 if self.xmpp_c != None or self.irc_connection != None or self.protocol == 'both' or self.bridge.mode == 'minimal':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
46 self.xmpp_c = xmpp.client.Client(self.bridge.bot.jid.getDomain(), debug=[])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
47 self.xmpp_c.connect()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
48 self.xmpp_c.auth(self.bridge.bot.jid.getNode(), self.bridge.bot.password, resource=self.nickname)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
49 self.xmpp_c.RegisterHandler('presence', self.bridge.bot._xmpp_presence_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
50 self.xmpp_c.RegisterHandler('iq', self.bridge.bot._xmpp_iq_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
51 self.xmpp_c.RegisterHandler('message', self.bridge.bot._xmpp_message_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
52 self.xmpp_thread = Thread(target=self._xmpp_loop)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
53 self.xmpp_thread.start()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
54 self.xmpp_c.sendInitPresence()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
55 self.muc = xmpp.muc(self.bridge.xmpp_room.room_jid)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
56 self.muc.join(self.xmpp_c, self.nickname, status='From IRC', callback=self._xmpp_join_callback)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
57
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
58
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
59 def createDuplicateOnIRC(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
60 if self.irc_connection != None or self.xmpp_c != None or self.protocol == 'both' or self.bridge.mode != 'normal':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
61 return
4
012593ed4e12 Prevent bot from trying to connect on IRC with a nickname containing one or more white space character(s)
Charly COSTE <changaco@changaco.net>
parents: 3
diff changeset
62 if ' ' in self.nickname:
012593ed4e12 Prevent bot from trying to connect on IRC with a nickname containing one or more white space character(s)
Charly COSTE <changaco@changaco.net>
parents: 3
diff changeset
63 self.bridge.bot.error('===> Debug: "'+self.nickname+'" contains a white space character, duplicate cannot be created on the IRC chan of bridge "'+str(self.bridge)+'"', debug=True)
012593ed4e12 Prevent bot from trying to connect on IRC with a nickname containing one or more white space character(s)
Charly COSTE <changaco@changaco.net>
parents: 3
diff changeset
64 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains a white space character, duplicate cannot be created on IRC, please avoid that if possible')
012593ed4e12 Prevent bot from trying to connect on IRC with a nickname containing one or more white space character(s)
Charly COSTE <changaco@changaco.net>
parents: 3
diff changeset
65 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
66 sleep(1) # try to prevent "reconnecting too fast" shit
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
67 self.irc_connection = self.bridge.bot.irc.server()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
68 self.irc_connection.bridge = self.bridge
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
69 self.irc_connection.nick_callback = self._irc_nick_callback
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
70 self.irc_connection.connect(self.bridge.irc_server, self.bridge.irc_port, self.nickname)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
71
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
72
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
73 def _irc_nick_callback(self, error):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
74 if error == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
75 self.irc_connection.join(self.bridge.irc_room)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
76 self.irc_connection.nick_callback = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
77 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
78 elif self.protocol != 'both':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
79 if error == 'nicknameinuse':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
80 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the IRC chan of bridge "'+str(self.bridge)+'"', debug=True)
3
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 0
diff changeset
81 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the IRC server, please avoid that if possible')
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
82 self.protocol = 'both'
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
83 self.irc_connection.closing = True
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
84 self.irc_connection.disconnect()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
85 self.irc_connection = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
86 elif error == 'erroneusnickname':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
87 self.bridge.bot.error('===> Debug: "'+self.nickname+'" got "erroneusnickname" on bridge "'+str(self.bridge)+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
88 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains non-ASCII characters and cannot be used in the IRC channel, please avoid that if possible')
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
89 self.irc_connection.closing = True
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
90 self.irc_connection.disconnect()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
91 self.irc_connection = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
92
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
93
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
94 def _xmpp_join_callback(self, errors):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
95 if len(errors) == 0:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
96 self.bridge.bot.error('===> Debug: "'+self.nickname+'" duplicate succesfully created on XMPP side of bridge "'+str(self.bridge)+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
97 elif self.protocol != 'both':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
98 for error in errors:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
99 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
100 raise error
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
101 except xmpp.muc.NicknameConflict:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
102 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self.bridge)+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
103 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server, please avoid that if possible')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
104 self.protocol = 'both'
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
105 self.xmpp_c = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
106
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
107
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
108 def _xmpp_loop(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
109 while True:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
110 if self.xmpp_c != None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
111 self.xmpp_c.Process(5)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
112 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
113 sleep(5)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
114
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
115
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
116 def changeNickname(self, newnick, on_protocol):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
117 if self.protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
118 if on_protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
119 raise Exception('Internal Error: wanted to change nickname on bad protocol')
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
120 self.nickname = newnick
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
121 if ' ' in self.nickname:
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
122 self.bridge.bot.error('===> Debug: "'+self.nickname+'" contains a white space character, duplicate cannot be created on the IRC chan of bridge "'+str(self.bridge)+'"', debug=True)
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
123 self.bridge.say('[Warning] The nickname "'+self.nickname+'" contains a white space character, duplicate cannot be created on IRC, please avoid that if possible')
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
124 if self.irc_connection != None:
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
125 self.irc_connection.closing = True
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
126 self.irc_connection.disconnect()
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
127 self.irc_connection = None
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
128 return
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
129 if self.irc_connection != None:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
130 self.irc_connection.nick(newnick)
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
131 else:
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
132 self.createDuplicateOnIRC()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
133 elif self.protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
134 if on_protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
135 raise Exception('Internal Error: wanted to change nickname on bad protocol')
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
136 self.nickname = newnick
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
137 if self.muc:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
138 self.muc.change_nick(newnick, callback=self._xmpp_join_callback)
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
139 else:
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
140 self.createDuplicateOnXMPP()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
141 elif self.protocol == 'both':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
142 if on_protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
143 self.protocol = 'xmpp'
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
144 self.createDuplicateOnIRC()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
145 elif on_protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
146 self.protocol = 'irc'
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
147 self.createDuplicateOnXMPP()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
148
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
149
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
150 def sayOnIRC(self, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
151 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
152 if self.protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
153 raise Exception('Internal Error: "'+self.nickname+'" comes from IRC')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
154 elif self.protocol == 'both' or self.irc_connection == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
155 self.bridge.irc_connection.privmsg(self.bridge.irc_room, '<'+self.nickname+'> '+message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
156 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
157 self.irc_connection.privmsg(self.bridge.irc_room, message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
158 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
159 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
160
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
161
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
162 def sayOnIRCTo(self, to, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
163 if self.protocol == 'irc':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
164 raise Exception('Internal Error: "'+self.nickname+'" comes from IRC')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
165 elif self.irc_connection == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
166 if self.bridge.mode != 'normal':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
167 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but cross-protocol private messages are disabled in limited mode.')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
168 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
169 self.bridge.getParticipant(to).sayOnXMPPTo(self.nickname, 'Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
170 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
171 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
172 self.irc_connection.privmsg(to, message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
173 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
174 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
175
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
176
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
177 def sayOnXMPP(self, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
178 if self.protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
179 raise Exception('Internal Error: "'+self.nickname+'" comes from XMPP')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
180 elif self.protocol == 'both' or self.xmpp_c == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
181 self.bridge.xmpp_room.say('<'+self.nickname+'> '+auto_decode(message))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
182 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
183 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
184 self.muc.say(auto_decode(message))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
185 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
186 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
187
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
188
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
189 def sayOnXMPPTo(self, to, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
190 if self.protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
191 raise Exception('Internal Error: "'+self.nickname+'" comes from XMPP')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
192 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
193 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
194 self.muc.sayTo(to, auto_decode(message))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
195 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
196 self.bridge.say('[Warning] "'+self.nickname+'" is sending messages using an unknown encoding')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
197
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
198
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
199 def leave(self, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
200 if message == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
201 message = ''
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
202 if self.muc:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
203 self.muc.leave(message)
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
204 if self.irc_connection:
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
205 self.irc_connection.closing = True
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
206 self.irc_connection.disconnect(message)
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 4
diff changeset
207 self.irc_connection = None
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
208 self.nickname = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
209
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
210
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
211 def __del__(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
212 if self.nickname != None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
213 self.leave('')