Mercurial > xib
annotate participant.py @ 1:7d1745ca1dc2
Add dependencies to README
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 16 Aug 2009 13:13:40 +0200 |
parents | 4c842d23d4ce |
children | 3f651f4fdb4f |
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 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
62 sleep(1) # try to prevent "reconnecting too fast" shit |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
63 self.irc_connection = self.bridge.bot.irc.server() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
64 self.irc_connection.bridge = self.bridge |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
65 self.irc_connection.nick_callback = self._irc_nick_callback |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
66 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
|
67 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
68 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
69 def _irc_nick_callback(self, error): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
70 if error == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
71 self.irc_connection.join(self.bridge.irc_room) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
72 self.irc_connection.nick_callback = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
73 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
|
74 elif self.protocol != 'both': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
75 if error == 'nicknameinuse': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the IRC chan of bridge "'+str(self.bridge)+'"', debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
77 self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms, please avoid that if possible') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
78 self.protocol = 'both' |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
79 self.irc_connection.close() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
80 self.irc_connection = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
81 elif error == 'erroneusnickname': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
82 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
|
83 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') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
84 self.irc_connection.close() |
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 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
87 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
88 def _xmpp_join_callback(self, errors): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
89 if len(errors) == 0: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
90 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
|
91 elif self.protocol != 'both': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
92 for error in errors: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
93 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
94 raise error |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
95 except xmpp.muc.NicknameConflict: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
96 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
|
97 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
|
98 self.protocol = 'both' |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
99 self.xmpp_c = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
100 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
101 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
102 def _xmpp_loop(self): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
103 while True: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
104 if self.xmpp_c != None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
105 self.xmpp_c.Process(5) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
106 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
107 sleep(5) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
108 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
109 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
110 def changeNickname(self, newnick, on_protocol): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
111 if self.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
112 if on_protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
113 raise Exception('Internal Error: wanted to change nickname on bad protocol') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
114 if self.irc_connection: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
115 self.irc_connection.nick(newnick) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
116 self.nickname = newnick |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
117 elif self.protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
118 if on_protocol == 'irc': |
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') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
120 if self.muc: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
121 self.muc.change_nick(newnick, callback=self._xmpp_join_callback) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
122 self.nickname = newnick |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
123 elif self.protocol == 'both': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
124 if on_protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
125 self.protocol = 'xmpp' |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
126 self.createDuplicateOnIRC() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
127 elif on_protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
128 self.protocol = 'irc' |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
129 self.createDuplicateOnXMPP() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
130 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
131 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
132 def sayOnIRC(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
133 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
134 if self.protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
135 raise Exception('Internal Error: "'+self.nickname+'" comes from IRC') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
136 elif self.protocol == 'both' or self.irc_connection == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
137 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
|
138 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
139 self.irc_connection.privmsg(self.bridge.irc_room, message) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
140 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
141 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
|
142 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
143 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
144 def sayOnIRCTo(self, to, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
145 if self.protocol == 'irc': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
146 raise Exception('Internal Error: "'+self.nickname+'" comes from IRC') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
147 elif self.irc_connection == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
148 if self.bridge.mode != 'normal': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
149 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
|
150 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
151 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
|
152 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
153 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
154 self.irc_connection.privmsg(to, message) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
155 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
156 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
|
157 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
158 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
159 def sayOnXMPP(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
160 if self.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
161 raise Exception('Internal Error: "'+self.nickname+'" comes from XMPP') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
162 elif self.protocol == 'both' or self.xmpp_c == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
163 self.bridge.xmpp_room.say('<'+self.nickname+'> '+auto_decode(message)) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
164 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
165 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
166 self.muc.say(auto_decode(message)) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
167 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
168 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
|
169 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
170 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
171 def sayOnXMPPTo(self, to, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
172 if self.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
173 raise Exception('Internal Error: "'+self.nickname+'" comes from XMPP') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
174 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
175 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
176 self.muc.sayTo(to, auto_decode(message)) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
177 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
178 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
|
179 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
180 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
181 def leave(self, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
182 if message == None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
183 message = '' |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
184 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
185 self.muc.leave(message) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
186 except AttributeError: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
187 pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
188 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
189 self.irc_connection.disconnect(message) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
190 except AttributeError: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
191 pass |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
192 self.nickname = None |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
193 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
194 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
195 def __del__(self): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
196 if self.nickname != None: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
197 self.leave('') |