comparison bot.py @ 108:dff9746aa508

XMPP room deletion (and server shut down) handling Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 22 Nov 2009 11:39:33 +0100
parents d8acff763731
children ec4fbec1f160
comparison
equal deleted inserted replaced
107:b9263a9aaa34 108:dff9746aa508
139 # presence comes from a muc 139 # presence comes from a muc
140 resource = unicode(from_.getResource()) 140 resource = unicode(from_.getResource())
141 141
142 if resource == '': 142 if resource == '':
143 # presence comes from the muc itself 143 # presence comes from the muc itself
144 # TODO: handle room deletion and muc server reboot
145 pass 144 pass
145
146 elif resource == xmpp_c.nickname:
147 # presence comes from self
148 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user')
149 if x:
150 d = x.getTag('destroy')
151 if d:
152 # room was destroyed
153 # problem is that this is used by some MUC servers when they shut down or restart
154 # considering this lack of semantic we have no choice but to do a check on the reason
155 reason = d.getTag('reason')
156 if reason:
157 r = reason.getData()
158 if r == 'The conference component is shutting down':
159 # MUC server is going down, try to restart the bridge in 1 minute
160 self.error('[Warning] The MUC server '+from_.getDomain()+' seems to be going down, the bot will try to recreate the bridge '+str(bridge)+' in 1 minute', send_to_admins=True)
161 bridge.stop(message='MUC server seems to be going down, will try to recreate the bridge in 1 minute')
162 self.irc.execute_delayed(60, bridge.init2)
163 return
164 elif r == '':
165 r = 'None given'
166 else:
167 r = 'None given'
168
169 # room has been destroyed, stop the bridge
170 self.error('[Error] The MUC room of the bridge '+str(bridge)+' has been destroyed with reason "'+r+'", stopping the bridge', send_to_admins=True)
171 bridge.stop(message='The MUC room of the bridge has been destroyed with reason "'+r+'", stopping the bridge')
146 172
147 else: 173 else:
148 # presence comes from a participant of the muc 174 # presence comes from a participant of the muc
149 175
150 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') 176 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user')
822 ret = 'List of bridges:' 848 ret = 'List of bridges:'
823 for i, b in enumerate(self.bridges): 849 for i, b in enumerate(self.bridges):
824 ret += '\n'+str(i+1)+' - '+str(b) 850 ret += '\n'+str(i+1)+' - '+str(b)
825 if args.show_mode: 851 if args.show_mode:
826 ret += ' - '+b.mode+' mode' 852 ret += ' - '+b.mode+' mode'
853 if b.irc_connection == None:
854 ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it'
827 return ret 855 return ret
828 856
829 elif command in bot.admin_commands: 857 elif command in bot.admin_commands:
830 if bot_admin == False: 858 if bot_admin == False:
831 return 'You have to be a bot admin to use this command.' 859 return 'You have to be a bot admin to use this command.'