Mercurial > xib
annotate bridge.py @ 175:8378da7844f2
minor fix in Bridge.addParticipant(), don't rely on Bridge.irc_connection or Bridge.xmpp_room when not necessary
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Mon, 08 Feb 2010 19:01:04 +0100 |
parents | c158ad24ef3c |
children | bca516d04bdb |
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 |
124 | 18 import re |
19 import threading | |
20 import traceback | |
21 | |
22 from irclib import ServerConnection | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
23 import muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
24 xmpp = muc.xmpp |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 del muc |
124 | 26 |
27 from participant import Participant | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
29 |
124 | 30 class Bridge: |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
31 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
32 _all = 0 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
33 _info = 1 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
34 _notice = 2 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
35 _warning = 3 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
36 _error = 4 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
37 _nothing = 5 |
103 | 38 _say_levels = ['all', 'info', 'notice', 'warning', 'error', 'nothing'] |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
39 _modes = ['normal', 'bypass', 'limited', 'minimal'] |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
40 |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
41 |
124 | 42 class NoSuchParticipantException(Exception): pass |
43 | |
44 | |
174
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
45 def __init__(self, owner_bot, xmpp_room_jid, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=None, irc_charsets=None): |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
46 """Create a new bridge.""" |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
47 self.bot = owner_bot |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
48 self.irc_server = irc_server |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
49 self.irc_port = irc_port |
45
41394ddb3aff
Lower before comparing strings.
Charly COSTE <changaco@changaco.net>
parents:
40
diff
changeset
|
50 self.irc_room = irc_room.lower() |
150
e0eea72ea493
new bridge attribute "irc_connection_interval" (in seconds)
Charly COSTE <changaco@changaco.net>
parents:
139
diff
changeset
|
51 self.irc_connection_interval = irc_connection_interval |
172
64a0e9636ae6
removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents:
169
diff
changeset
|
52 self.irc_charsets = irc_charsets |
103 | 53 self.xmpp_room_jid = xmpp_room_jid |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
54 if hasattr(self.__class__, '_'+say_level): |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
55 self.say_level = getattr(self.__class__, '_'+say_level) |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
56 else: |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
57 raise Exception('[Error] "'+say_level+'" is not a correct value for a bridge\'s "say_level" attribute') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
58 self.participants = [] |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
59 if mode not in self.__class__._modes: |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
60 raise Exception('[Error] "'+mode+'" is not a correct value for a bridge\'s "mode" attribute') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
61 self.mode = mode |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
62 |
40
faa468731d8a
Tried to get thread safety and handle disconnections in muc.py
Charly COSTE <changaco@changaco.net>
parents:
38
diff
changeset
|
63 self.lock = threading.RLock() |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
64 |
103 | 65 self.init2() |
66 | |
67 | |
68 def init2(self): | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
69 # Join XMPP room |
174
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
70 self.xmpp_room = xmpp.muc(self.xmpp_room_jid) |
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
71 self.xmpp_room.join(self.bot.xmpp_c, self.bot.nickname, callback=self._xmpp_join_callback) |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
72 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
73 # Join IRC room |
174
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
74 self.irc_connection = self.bot.irc.open_connection(self.irc_server, self.irc_port, self.bot.nickname, delay=self.irc_connection_interval) |
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
75 self.irc_connection.connect(nick_callback=self._irc_nick_callback, charsets=self.irc_charsets) |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
76 |
114 | 77 self.bot.error('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode and a say_level of "'+self.__class__._say_levels[self.say_level]+'"') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
78 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
79 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
80 def _irc_nick_callback(self, error, arguments=[]): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
81 if error == None: |
85
dfa030c141f1
Fixed callbacks in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
84
diff
changeset
|
82 if self.mode == None: |
dfa030c141f1
Fixed callbacks in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
84
diff
changeset
|
83 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
84 self.irc_connection.join(self.irc_room) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
85 self.bot.error('===> Debug: successfully connected on IRC side of bridge "'+str(self)+'"', debug=True) |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
86 self.say('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False) |
174
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
87 if self.mode not in ['normal', 'bypass']: |
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
88 self.show_participants_list_on(protocols=['irc']) |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
89 else: |
85
dfa030c141f1
Fixed callbacks in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
84
diff
changeset
|
90 self.mode = None |
101
29d3b85c6286
Minor fixes/improvements
Charly COSTE <changaco@changaco.net>
parents:
100
diff
changeset
|
91 if self.xmpp_room.connected == True: |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
92 self.say('[Error] failed to connect to the IRC chan, leaving ...', on_irc=False) |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
93 try: |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
94 if error == 'nicknameinuse': |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
95 raise Exception('[Error] "'+self.bot.nickname+'" is already used in the IRC chan or reserved on the IRC server of bridge "'+str(self)+'"') |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
96 elif error == 'nickcollision': |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
97 raise Exception('[Error] "'+self.bot.nickname+'" is already used or reserved on the IRC server of bridge "'+str(self)+'"') |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
98 elif error == 'erroneusnickname': |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
99 raise Exception('[Error] "'+self.bot.nickname+'" got "erroneusnickname" on bridge "'+str(self)+'"') |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
100 elif error == 'nicknametoolong': |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
101 raise Exception('[Error] "'+self.bot.nickname+'" got "nicknametoolong" on bridge "'+str(self)+'", limit seems to be '+str(arguments[0])) |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
102 else: |
169
271c35321497
minor fix in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
155
diff
changeset
|
103 raise Exception('[Error] unknown error for "'+self.bot.nickname+'" on bridge "'+str(self)+'"') |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
104 except: |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
105 traceback.print_exc() |
112
a817ad05dd1d
stop bridge on error instead of removing it
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
106 self.bot.error('[Error] failed to connect to the IRC chan of bridge "'+str(self)+'", stopping bridge', send_to_admins=True) |
a817ad05dd1d
stop bridge on error instead of removing it
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
107 self.stop(message='failed to connect to the IRC chan') |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
108 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
109 |
135
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
110 def _RemoteServerNotFound_handler(self): |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
111 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain() |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
112 bridges = self.bot.findBridges([server]) |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
113 error_message = '[Warning] The MUC server '+server+' seems to be down, the bot will try to recreate all bridges related to this server in 5 minutes' |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
114 self.bot.restart_bridges_delayed(bridges, 300, error_message) |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
115 |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
116 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
117 def _xmpp_join_callback(self, errors): |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
118 """Called by muc._xmpp_presence_handler""" |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
119 if len(errors) == 0: |
113
6daf0854aa9f
added "--show-say-level" and "--show-participants" options to the "bridges" command, renamed {irc,xmpp}_participants commands
Charly COSTE <changaco@changaco.net>
parents:
112
diff
changeset
|
120 if hasattr(self, 'reconnecting'): |
111
59401ac0f47a
handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents:
109
diff
changeset
|
121 del self.reconnecting |
85
dfa030c141f1
Fixed callbacks in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
84
diff
changeset
|
122 if self.mode == None: |
dfa030c141f1
Fixed callbacks in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
84
diff
changeset
|
123 return |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
124 self.bot.error('===> Debug: succesfully connected on XMPP side of bridge "'+str(self)+'"', debug=True) |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
125 self.say('[Notice] bridge "'+str(self)+'" is running in '+self.mode+' mode', on_irc=False) |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
126 else: |
85
dfa030c141f1
Fixed callbacks in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
84
diff
changeset
|
127 self.mode = None |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
128 if self.irc_connection.really_connected == True: |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
129 self.say('[Error] failed to connect to the XMPP room, leaving ...', on_xmpp=False) |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
130 for error in errors: |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
131 try: |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
132 raise error |
135
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
133 except xmpp.muc.RemoteServerNotFound: |
922858915907
handle xmpp.muc.RemoteServerNotFound
Charly COSTE <changaco@changaco.net>
parents:
132
diff
changeset
|
134 self._RemoteServerNotFound_handler() |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
135 except: |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
136 traceback.print_exc() |
112
a817ad05dd1d
stop bridge on error instead of removing it
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
137 self.bot.error('[Error] failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge', send_to_admins=True) |
a817ad05dd1d
stop bridge on error instead of removing it
Charly COSTE <changaco@changaco.net>
parents:
111
diff
changeset
|
138 self.stop(message='failed to connect to the XMPP room') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
139 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
140 |
115
0ae0f8836a7a
split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents:
114
diff
changeset
|
141 def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
142 """Add a participant to the bridge.""" |
175
8378da7844f2
minor fix in Bridge.addParticipant(), don't rely on Bridge.irc_connection or Bridge.xmpp_room when not necessary
Charly COSTE <changaco@changaco.net>
parents:
174
diff
changeset
|
143 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
144 self.bot.error('===> Debug: not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
145 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
146 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
147 p = self.getParticipant(nickname) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
64
diff
changeset
|
148 if p.protocol != from_protocol: |
120
de00bbe026a7
bugfix related to the bypass mode
Charly COSTE <changaco@changaco.net>
parents:
118
diff
changeset
|
149 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: |
115
0ae0f8836a7a
split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents:
114
diff
changeset
|
150 if irc_id: |
0ae0f8836a7a
split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents:
114
diff
changeset
|
151 p.irc_connection.irc_id = irc_id |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
152 return p |
123
75a03f10a863
Code refactoring (new method participant.set_both_sides())
Charly COSTE <changaco@changaco.net>
parents:
122
diff
changeset
|
153 p.set_both_sides() |
109 | 154 return p |
124 | 155 except self.NoSuchParticipantException: |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
156 pass |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
157 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
158 if nickname == 'ChanServ' and from_protocol == 'irc': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
159 return |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
160 |
97
c71861491968
bridge.addParticipant improvements
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
161 self.lock.acquire() |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
64
diff
changeset
|
162 self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
163 try: |
124 | 164 p = Participant(self, from_protocol, nickname, real_jid=real_jid) |
22
e2bd4de698e5
Solved an XMPP resource conflict that would have happened when someone on IRC changed its nickname and later its old nickname would be used again. In other words, the bot no longer uses nicknames as XMPP resources.
Charly COSTE <changaco@changaco.net>
parents:
21
diff
changeset
|
165 except IOError: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
64
diff
changeset
|
166 self.bot.error('===> Debug: IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) |
22
e2bd4de698e5
Solved an XMPP resource conflict that would have happened when someone on IRC changed its nickname and later its old nickname would be used again. In other words, the bot no longer uses nicknames as XMPP resources.
Charly COSTE <changaco@changaco.net>
parents:
21
diff
changeset
|
167 p.xmpp_c.reconnectAndReauth() |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
168 except: |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
64
diff
changeset
|
169 self.bot.error('===> Debug: unknown error while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
170 traceback.print_exc() |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
171 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
172 self.participants.append(p) |
97
c71861491968
bridge.addParticipant improvements
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
173 self.lock.release() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
174 if self.mode not in ['normal', 'bypass']: |
102
b3eba9489329
In minimal mode, display the participants' list on XMPP when someone joins on IRC
Charly COSTE <changaco@changaco.net>
parents:
101
diff
changeset
|
175 if from_protocol == 'xmpp': |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
176 self.show_participants_list_on(protocols=['irc']) |
102
b3eba9489329
In minimal mode, display the participants' list on XMPP when someone joins on IRC
Charly COSTE <changaco@changaco.net>
parents:
101
diff
changeset
|
177 elif self.mode == 'minimal' and from_protocol == 'irc': |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
178 self.show_participants_list_on(protocols=['xmpp']) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
179 return p |
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 |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
182 def createDuplicatesOn(self, protocols): |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
183 for p in self.participants: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
184 if p.protocol == 'xmpp' and 'irc' in protocols: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
185 p.createDuplicateOnIRC() |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
186 elif p.protocol == 'irc' and 'xmpp' in protocols: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
187 p.createDuplicateOnXMPP() |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
188 |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
189 |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
190 def changeMode(self, new_mode): |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
191 if new_mode == self.mode: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
192 return 'Mode is already equal to '+self.mode |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
193 |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
194 old_mode = self.mode |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
195 self.mode = new_mode |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
196 |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
197 unhandled = False |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
198 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
199 if new_mode in ['normal', 'bypass']: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
200 |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
201 if old_mode == 'limited': |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
202 # From limited to {normal,bypass} |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
203 self.createDuplicatesOn(['irc']) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
204 |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
205 elif old_mode in ['minimal', 'normal']: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
206 # From {minimal,normal} to {normal,bypass} |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
207 self.createDuplicatesOn(['irc', 'xmpp']) |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
208 |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
209 elif old_mode == 'bypass': |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
210 # From bypass to normal |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
211 pass # Handled below |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
212 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
213 else: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
214 # Unhandled mode changing |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
215 unhandled = True |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
216 |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
217 elif new_mode == 'limited': |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
218 |
139
38eb220142a1
fixed minimal→*limited mode changing
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
219 if old_mode == 'minimal': |
38eb220142a1
fixed minimal→*limited mode changing
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
220 self.createDuplicatesOn(['xmpp']) |
38eb220142a1
fixed minimal→*limited mode changing
Charly COSTE <changaco@changaco.net>
parents:
137
diff
changeset
|
221 |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
222 i = 0 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
223 for p in self.participants: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
224 if p.protocol == 'xmpp': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
225 i += 1 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
226 p._close_irc_connection('Bridge is switching to limited mode') |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
227 |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
228 self.show_participants_list_on(protocols=['irc']) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
229 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
230 elif new_mode == 'minimal': |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
231 for p in self.participants: |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
232 p.leave('Bridge is switching to minimal mode') |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
233 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
234 else: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
235 # Unhandled mode changing |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
236 unhandled = True |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
237 |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
238 if unhandled: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
239 self.mode = old_mode |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
240 return 'Error: unhandled mode changing from '+self.mode+' to '+new_mode |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
241 |
132
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
242 if old_mode == 'bypass': |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
243 # From bypass to * |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
244 for p in self.participants: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
245 if p.nickname != p.duplicate_nickname: |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
246 p.leave('Bridge is switching to '+new_mode+' mode') |
6a6885dbed25
handle more mode changing cases (added bridge.createDuplicatesOn())
Charly COSTE <changaco@changaco.net>
parents:
131
diff
changeset
|
247 |
137
9f39cead20cb
reduced duplication of error messages
Charly COSTE <changaco@changaco.net>
parents:
135
diff
changeset
|
248 self.say('[Notice] Bridge is switching from '+old_mode+' to '+new_mode+' mode.', log=True) |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
249 |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
250 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
251 def getParticipant(self, nickname): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
252 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise.""" |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
253 self.lock.acquire() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
254 for p in self.participants: |
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
255 if nickname in [p.nickname, p.duplicate_nickname]: |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
256 self.lock.release() |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
257 return p |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
258 self.lock.release() |
124 | 259 raise self.NoSuchParticipantException('there is no participant using the nickname "'+nickname+'" in this bridge') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
260 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
261 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
262 def get_participants_nicknames_list(self, protocols=['irc', 'xmpp']): |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
263 """Returns a list of the nicknames of the bridge's participants that are connected on the XMPP side.""" |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
264 self.lock.acquire() |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
265 participants_nicknames = [] |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
266 for p in self.participants: |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
267 if p.protocol in protocols: |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
268 participants_nicknames.append('"'+p.nickname+'"') |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
269 self.lock.release() |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
270 return participants_nicknames |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
271 |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
272 |
62
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
273 def hasParticipant(self, nickname): |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
274 try: |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
275 self.getParticipant(nickname) |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
276 return True |
124 | 277 except self.NoSuchParticipantException: |
62
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
278 return False |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
279 |
61491895c607
Added bridge.hasParticipant() and fixed participant.changeNickname()
Charly COSTE <changaco@changaco.net>
parents:
60
diff
changeset
|
280 |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
281 def removeParticipant(self, left_protocol, nickname, leave_message): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
282 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge.""" |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
283 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
284 was_on_both = None |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
285 p = self.getParticipant(nickname) |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
286 if p.protocol == 'xmpp': |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
287 if p.irc_connection == 'both': |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
288 was_on_both = True |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
289 if left_protocol == 'xmpp': |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
290 p.protocol = 'irc' |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
291 p.createDuplicateOnXMPP() |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
292 elif left_protocol == 'irc': |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
293 p.createDuplicateOnIRC() |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
294 else: |
100
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
295 if left_protocol == 'xmpp': |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
296 was_on_both = False |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
297 elif left_protocol == 'irc': |
131
46af7f2744a9
added irclib.ServerConnection.left_channels
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
298 if isinstance(p.irc_connection, ServerConnection): |
100
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
299 p.irc_connection.join(self.irc_room) |
131
46af7f2744a9
added irclib.ServerConnection.left_channels
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
300 else: |
46af7f2744a9
added irclib.ServerConnection.left_channels
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
301 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname) |
46af7f2744a9
added irclib.ServerConnection.left_channels
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
302 if not (c and self.irc_room in c.left_channels): |
46af7f2744a9
added irclib.ServerConnection.left_channels
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
303 p._close_irc_connection(leave_message) |
46af7f2744a9
added irclib.ServerConnection.left_channels
Charly COSTE <changaco@changaco.net>
parents:
125
diff
changeset
|
304 p.createDuplicateOnIRC() |
100
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
305 return |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
306 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
307 elif p.protocol == 'irc': |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
308 if p.xmpp_c == 'both': |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
309 was_on_both = True |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
310 if left_protocol == 'irc': |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
311 p.protocol = 'xmpp' |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
312 p.createDuplicateOnIRC() |
84
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
313 elif left_protocol == 'xmpp': |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
314 p.createDuplicateOnXMPP() |
844ccdcf66be
Fixed callbacks, addParticipant, removeParticipant and __del__ in bridge.py
Charly COSTE <changaco@changaco.net>
parents:
72
diff
changeset
|
315 else: |
100
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
316 if left_protocol == 'irc': |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
317 was_on_both = False |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
318 elif left_protocol == 'xmpp': |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
319 if isinstance(p.xmpp_c, xmpp.client.Client): |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
320 self.bot.reopen_xmpp_connection(p.xmpp_c) |
6289ac5a2db7
Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents:
97
diff
changeset
|
321 return |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
322 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
323 else: |
19
c1b84196c100
Changed format of non-debug error messages, fixed IRC namreply handling, prevented crash when receiving bad XMPP stanza.
Charly COSTE <changaco@changaco.net>
parents:
18
diff
changeset
|
324 raise Exception('[Internal Error] bad protocol') |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
325 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
326 if was_on_both == True: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
327 self.bot.error('===> Debug: "'+nickname+'" was on both sides of bridge "'+str(self)+'" but left '+left_protocol, debug=True) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
328 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
329 elif was_on_both == False: |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
330 self.lock.acquire() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
331 self.bot.error('===> Debug: removing participant "'+nickname+'" from bridge "'+str(self)+'"', debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
332 self.participants.remove(p) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
333 p.leave(leave_message) |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
334 del p |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
335 self.lock.release() |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
336 if left_protocol == 'xmpp': |
118
b29fd5696a78
new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents:
115
diff
changeset
|
337 if self.mode not in ['normal', 'bypass']: |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
338 self.show_participants_list_on(protocols=['irc']) |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
339 elif left_protocol == 'irc': |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
22
diff
changeset
|
340 if self.mode == 'minimal': |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
341 self.show_participants_list_on(protocols=['xmpp']) |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
342 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
343 else: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
344 self.bot.error('=> Debug: Bad decision tree, p.protocol='+p.protocol+' left_protocol='+left_protocol+'\np.xmpp_c='+str(p.xmpp_c)+'\np.irc_connection='+str(p.irc_connection), debug=True) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
345 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
346 |
103 | 347 def restart(self): |
348 """Restart the bridge""" | |
349 | |
105
d8acff763731
Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents:
103
diff
changeset
|
350 # Tell admins |
d8acff763731
Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents:
103
diff
changeset
|
351 self.bot.error('Restarting bridge '+str(self), send_to_admins=True) |
d8acff763731
Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents:
103
diff
changeset
|
352 |
103 | 353 # Stop the bridge |
354 self.stop(message='Restarting bridge') | |
355 | |
356 # Recreate the bridge | |
357 self.init2() | |
358 | |
359 | |
137
9f39cead20cb
reduced duplication of error messages
Charly COSTE <changaco@changaco.net>
parents:
135
diff
changeset
|
360 def say(self, message, on_irc=True, on_xmpp=True, log=False): |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
15
diff
changeset
|
361 """Make the bot say something.""" |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
362 if message[0] != '[': |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
363 raise Exception('[Internal Error] message does not start with "["') |
137
9f39cead20cb
reduced duplication of error messages
Charly COSTE <changaco@changaco.net>
parents:
135
diff
changeset
|
364 if log: |
9f39cead20cb
reduced duplication of error messages
Charly COSTE <changaco@changaco.net>
parents:
135
diff
changeset
|
365 self.bot.error(message+' ('+str(self)+')') |
21
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
366 if self.say_level == self.__class__._nothing: |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
367 return |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
368 level = re.findall('^\[(Info|Notice|Warning|Error)\]', message) |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
369 if len(level) == 0: |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
370 raise Exception('[Internal Error] unknown message importance "'+re.findall('^\[([^[\]]+)', message)[0]+'"') |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
371 level = level[0].lower() |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
372 if getattr(self.__class__, '_'+level) < self.say_level: |
801160b4136f
Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
373 return |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
374 if on_xmpp == True: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
375 self.xmpp_room.say(message) |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
376 if on_irc == True: |
56 | 377 self.irc_connection.privmsg(self.irc_room, message) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
378 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
379 |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
380 def show_participants_list_on(self, protocols=[]): |
174
c158ad24ef3c
moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents:
172
diff
changeset
|
381 if 'irc' in protocols and self.irc_connection.really_connected: |
152
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
382 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
383 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
384 if 'xmpp' in protocols: |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
385 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
386 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
387 |
17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Charly COSTE <changaco@changaco.net>
parents:
150
diff
changeset
|
388 |
103 | 389 def stop(self, message='Stopping bridge'): |
390 """Stop the bridge""" | |
391 | |
392 # Close IRC connection if not used by an other bridge, just leave the room otherwise | |
109 | 393 if isinstance(self.irc_connection, ServerConnection): |
394 self.irc_connection.used_by -= 1 | |
395 if self.irc_connection.used_by < 1: | |
396 self.irc_connection.close(message) | |
397 else: | |
398 self.irc_connection.part(self.irc_room, message=message) | |
399 self.irc_connection = None | |
103 | 400 |
401 # Leave the MUC | |
109 | 402 if isinstance(self.xmpp_room, xmpp.muc): |
403 self.xmpp_room.leave(message=message) | |
404 self.xmpp_room.__del__() | |
405 self.xmpp_room = None | |
103 | 406 |
407 # Delete participants objects | |
408 for p in self.participants: | |
409 p.leave(message) | |
410 self.participants = [] | |
411 | |
412 | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
413 def __str__(self): |
103 | 414 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room_jid |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
415 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
416 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
417 def __del__(self): |
103 | 418 self.stop(message='Removing bridge') |