annotate bot.py @ 119:ae55fc0d783d

cleanup Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 03 Dec 2009 22:42:14 +0100
parents b29fd5696a78
children 765e460bc20a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 #!/usr/bin/env python
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4 # This program is free software: you can redistribute it and/or modify
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # the Free Software Foundation, either version 3 of the License, or
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 # (at your option) any later version.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 # GNU General Public License for more details.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18 import irclib
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
19 import muc
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
20 xmpp = muc.xmpp
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
21 del muc
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
22 import threading
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
23 from bridge import *
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 import re
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
26 import sys
20
08cde283621a Fixed a little bug in exception handling.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
27 import xml.parsers.expat
51
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
28 import traceback
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
29 from argparse_modified import *
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
30 import shlex
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
31
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
32
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
33 class bot(Thread):
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
34
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
35 commands = ['xmpp-participants', 'irc-participants', 'bridges']
110
ec4fbec1f160 new stop-bridge command
Charly COSTE <changaco@changaco.net>
parents: 108
diff changeset
36 admin_commands = ['add-bridge', 'add-xmpp-admin', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge']
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
37
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
38 def __init__(self, jid, password, nickname, admins_jid=[], error_fd=sys.stderr, debug=False):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 Thread.__init__(self)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
40 self.bare_jid = xmpp.protocol.JID(jid=jid)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
41 self.bare_jid.setResource('')
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42 self.nickname = nickname
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43 self.password = password
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
44 self.error_fd = error_fd
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 self.debug = debug
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
46 self.admins_jid = admins_jid
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
47 self.bridges = []
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
48 self.xmpp_connections = {}
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
49 self.irc = irclib.IRC()
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
50 self.irc.bot = self
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
51 self.irc.add_global_handler('all_events', self._irc_event_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
52 self.irc_thread = Thread(target=self.irc.process_forever)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
53 self.irc_thread.start()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
54 # Open connection with XMPP server
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
55 try:
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
56 self.xmpp_c = self.get_xmpp_connection(self.nickname)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
57 except:
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
58 self.error('[Error] XMPP Connection failed')
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
59 raise
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
60 self.xmpp_thread = Thread(target=self._xmpp_loop)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
61 self.xmpp_thread.start()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
62
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
63
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
64 def error(self, s, debug=False, send_to_admins=False):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
65 """Output an error message."""
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
66 if send_to_admins == True:
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
67 self._send_message_to_admins(s)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
68 if not debug or debug and self.debug:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
69 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
70 self.error_fd.write(auto_encode(s)+"\n")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
71 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
72 self.error_fd.write('Error message cannot be transcoded.\n')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
73
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
74
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
75 def _xmpp_loop(self):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
76 """[Internal] XMPP infinite loop."""
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
77 i = 1
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
78 while True:
79
73a30fc1922b Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents: 78
diff changeset
79 unlock = False
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
80 try:
51
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
81 if len(self.xmpp_connections) == 1:
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
82 sleep(0.5) # avoid bot connection being locked all the time
101
29d3b85c6286 Minor fixes/improvements
Charly COSTE <changaco@changaco.net>
parents: 100
diff changeset
83 for j, c in enumerate(self.xmpp_connections.itervalues()):
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
84 i += 1
51
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
85 if hasattr(c, 'lock'):
49
714e78fb912e Tried to improve thread-safety during XMPP connection closing.
Charly COSTE <changaco@changaco.net>
parents: 48
diff changeset
86 c.lock.acquire()
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
87 if i == j:
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
88 ping = xmpp.protocol.Iq(typ='get')
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
89 ping.addChild(name='ping', namespace='urn:xmpp:ping')
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
90 self.error('=> Debug: sending XMPP ping', debug=True)
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
91 c.pings.append(c.send(ping))
52
5aabf124c78d Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents: 51
diff changeset
92 if hasattr(c, 'Process'):
5aabf124c78d Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents: 51
diff changeset
93 c.Process(0.01)
5aabf124c78d Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents: 51
diff changeset
94 c.lock.release()
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
95 if i > 5000:
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
96 i = 0
51
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
97 except RuntimeError:
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
98 pass
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
99 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed):
72
6c4b841144f6 Better handling of participants
Charly COSTE <changaco@changaco.net>
parents: 70
diff changeset
100 self.error('=> Debug: invalid stanza', debug=True)
101
29d3b85c6286 Minor fixes/improvements
Charly COSTE <changaco@changaco.net>
parents: 100
diff changeset
101 self.reopen_xmpp_connection(c)
79
73a30fc1922b Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents: 78
diff changeset
102 unlock = True
91
69e4fc0f015c Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents: 90
diff changeset
103 except xmpp.Conflict:
101
29d3b85c6286 Minor fixes/improvements
Charly COSTE <changaco@changaco.net>
parents: 100
diff changeset
104 self.error('=> Debug: conflict', debug=True)
100
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
105 self.reopen_xmpp_connection(c)
91
69e4fc0f015c Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents: 90
diff changeset
106 unlock = True
51
2737ed5b9003 Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents: 50
diff changeset
107 except:
101
29d3b85c6286 Minor fixes/improvements
Charly COSTE <changaco@changaco.net>
parents: 100
diff changeset
108 error = '[Error] Unknown exception on XMPP thread:\n'
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
109 error += traceback.format_exc()
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
110 self.error(error, send_to_admins=True)
79
73a30fc1922b Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents: 78
diff changeset
111 unlock = True
73a30fc1922b Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents: 78
diff changeset
112 if unlock == True:
73a30fc1922b Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents: 78
diff changeset
113 c.lock.release()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
114
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
115
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
116 def _xmpp_presence_handler(self, dispatcher, presence):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
117 """[Internal] Manage XMPP presence."""
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
118
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
119 xmpp_c = dispatcher._owner
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
120
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
121 if xmpp_c.nickname != self.nickname:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
122 self.error('=> Debug: Skipping XMPP presence not received on bot connection.', debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
123 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
124
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
125 self.error('==> Debug: Received XMPP presence.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
126 self.error(presence.__str__(fancy=1), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
127
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
128 from_ = xmpp.protocol.JID(presence.getFrom())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
129 bare_jid = unicode(from_.getNode()+'@'+from_.getDomain())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
130 for bridge in self.bridges:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
131 if bare_jid == bridge.xmpp_room_jid:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
132 # presence comes from a muc
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
133 resource = unicode(from_.getResource())
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
134
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
135 if resource == '':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
136 # presence comes from the muc itself
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
137 pass
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
138
108
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
139 elif resource == xmpp_c.nickname:
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
140 # presence comes from self
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
141 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user')
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
142 if x:
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
143 d = x.getTag('destroy')
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
144 if d:
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
145 # room was destroyed
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
146 # problem is that this is used by some MUC servers when they shut down or restart
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
147 # considering this lack of semantic we have no choice but to do a check on the reason
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
148 reason = d.getTag('reason')
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
149 if reason:
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
150 r = reason.getData()
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
151 if r == 'The conference component is shutting down':
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
152 # MUC server is going down, try to restart the bridge in 1 minute
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
153 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)
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
154 bridge.stop(message='MUC server seems to be going down, will try to recreate the bridge in 1 minute')
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
155 self.irc.execute_delayed(60, bridge.init2)
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
156 return
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
157 elif r == '':
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
158 r = 'None given'
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
159 else:
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
160 r = 'None given'
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
161
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
162 # room has been destroyed, stop the bridge
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
163 self.error('[Error] The MUC room of the bridge '+str(bridge)+' has been destroyed with reason "'+r+'", stopping the bridge', send_to_admins=True)
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
164 bridge.stop(message='The MUC room of the bridge has been destroyed with reason "'+r+'", stopping the bridge')
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
165
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
166 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
167 # presence comes from a participant of the muc
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
168
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
169 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
170 item = None
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
171 if x:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
172 item = x.getTag('item')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
173
93
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
174 if presence.getType() == 'unavailable':
96
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
175 try:
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
176 p = bridge.getParticipant(resource)
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
177 except NoSuchParticipantException:
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
178 p = None
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
179
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
180 if x and x.getTag('status', attrs={'code': '303'}):
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
181 # participant changed its nickname
93
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
182 if p == None:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
183 return
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
184 if p.protocol != 'xmpp':
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
185 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
186 item = x.getTag('item')
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
187 if not item:
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
188 self.error('=> Debug: bad stanza, no item element', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
189 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
190 new_nick = item.getAttr('nick')
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
191 if not new_nick:
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
192 self.error('=> Debug: bad stanza, new nick is not given', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
193 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
194 p.changeNickname(new_nick, 'irc')
93
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
195
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
196 elif x and x.getTag('status', attrs={'code': '307'}):
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
197 # participant was kicked
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
198 if p == None:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
199 bridge.xmpp_room.rejoin()
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
200 return
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
201 if isinstance(p.xmpp_c, xmpp.client.Client):
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
202 p.muc.rejoin()
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
203 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
204 if item:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
205 reason = item.getTag('reason')
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
206 actor = item.getTag('actor')
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
207 if actor and actor.has_attr('jid'):
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
208 kicker = actor.getAttr('jid')
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
209 s1 = 'Kicked by '+kicker
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
210 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
211 s1 = 'Kicked from XMPP'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
212 if reason:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
213 s2 = ' with reason: '+reason.getData()
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
214 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
215 s2 = ' (no reason was given)'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
216 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
217 s1 = 'Kicked from XMPP'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
218 s2 = ' (no reason was given)'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
219
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
220 bridge.removeParticipant('xmpp', p.nickname, s1+s2)
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
221
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
222 elif x and x.getTag('status', attrs={'code': '301'}):
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
223 # participant was banned
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
224 if p == None:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
225 m = '[Error] bot got banned from XMPP'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
226 self.error(m)
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
227 bridge.say(m, on_xmpp=False)
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
228 self.removeBridge(bridge)
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
229 return
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
230 if item:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
231 reason = item.getTag('reason')
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
232 actor = item.getTag('actor')
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
233 if actor and actor.has_attr('jid'):
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
234 kicker = actor.getAttr('jid')
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
235 s1 = 'Banned by '+kicker
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
236 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
237 s1 = 'Banned from XMPP'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
238 if reason:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
239 s2 = ' with reason: '+reason.getData()
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
240 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
241 s2 = ' (no reason was given)'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
242 else:
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
243 s1 = 'Banned from XMPP'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
244 s2 = ' (no reason was given)'
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
245
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
246 bridge.removeParticipant('xmpp', p.nickname, s1+s2)
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
247
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
248 else:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
249 # participant left
99
5390e9abfa44 Don't try to remove a participant that does not exist
Charly COSTE <changaco@changaco.net>
parents: 96
diff changeset
250 if p != None:
5390e9abfa44 Don't try to remove a participant that does not exist
Charly COSTE <changaco@changaco.net>
parents: 96
diff changeset
251 bridge.removeParticipant('xmpp', resource, presence.getStatus())
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
252
111
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
253 elif presence.getType() == 'error':
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
254 error = presence.getTag('error')
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
255 if error:
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
256 for c in error.getChildren():
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
257 if c.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and c.getName() != 'text':
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
258 err = error.getAttr('type')+' '+c.getName()
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
259 if err == 'cancel remote-server-not-found':
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
260 # Remote server not found
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
261 error_message = '[Error] XMPP Remote server not found: '+from_.getDomain()
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
262
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
263 # Stop bridges that depend on this server
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
264 bridges = self.findBridges([from_.getDomain()])
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
265 if len(bridges) > 0:
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
266 error_message += '\nThese bridges will be stopped:'
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
267 for b in bridges:
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
268 error_message += '\n'+str(b)
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
269 if hasattr(b, 'reconnecting'):
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
270 leave_message = 'MUC server seems to be down'
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
271 else:
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
272 leave_message = 'MUC server seems to be down, will try to recreate the bridge in 1 minute'
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
273 self.reconnecting = True
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
274 self.irc.execute_delayed(60, b.init2)
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
275 b.stop(message=leave_message)
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
276
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
277 self.error(error_message, send_to_admins=True)
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
278 self.error(presence.__str__(fancy=1).encode('utf-8'), debug=True)
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
279 else:
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
280 raise Exception(presence.__str__(fancy=1).encode('utf-8'))
59401ac0f47a handle XMPP remote-server-not-found
Charly COSTE <changaco@changaco.net>
parents: 110
diff changeset
281
96
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
282 elif resource != bridge.bot.nickname:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
283 real_jid = None
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
284 if item and item.has_attr('jid'):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
285 real_jid = item.getAttr('jid')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
286
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
287 p = bridge.addParticipant('xmpp', resource, real_jid)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
288
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
289 # if we have the real jid check if the participant is a bot admin
118
b29fd5696a78 new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
290 if real_jid and isinstance(p, participant):
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
291 for jid in self.admins_jid:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
292 if xmpp.protocol.JID(jid).bareMatch(real_jid):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
293 p.bot_admin = True
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
294 break
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
295
96
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
296 return
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
297
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
298 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
299
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
300
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
301 def _xmpp_iq_handler(self, dispatcher, iq):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
302 """[Internal] Manage XMPP IQs."""
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
303
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
304 xmpp_c = dispatcher._owner
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
305
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
306 # Ignore pongs
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
307 if iq.getType() in ['result', 'error'] and iq.getID() in xmpp_c.pings:
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
308 xmpp_c.pings.remove(iq.getID())
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
309 self.error('=> Debug: received XMPP pong', debug=True)
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
310 return
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
311
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
312 self.error('==> Debug: Received XMPP iq.', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
313 self.error(iq.__str__(fancy=1), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
314
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
315
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
316 def _xmpp_message_handler(self, dispatcher, message):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
317 """[Internal] Manage XMPP messages."""
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
318
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
319 xmpp_c = dispatcher._owner
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
320
34
57d0e66378b0 Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents: 33
diff changeset
321 if message.getBody() == None:
57d0e66378b0 Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents: 33
diff changeset
322 return
57d0e66378b0 Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents: 33
diff changeset
323
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
324 if message.getType() == 'chat':
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
325 from_bare_jid = unicode(message.getFrom().getNode()+'@'+message.getFrom().getDomain())
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
326 for bridge in self.bridges:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
327 if from_bare_jid == bridge.xmpp_room_jid:
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
328 # message comes from a room participant
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
329
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
330 self.error('==> Debug: Received XMPP chat message.', debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
331 self.error(message.__str__(fancy=1), debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
332
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
333 try:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
334 from_ = bridge.getParticipant(message.getFrom().getResource())
27
9b7a628ca612 Fixed XMPP message handling, again.
Charly COSTE <changaco@changaco.net>
parents: 25
diff changeset
335 to_ = bridge.getParticipant(xmpp_c.nickname)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
336
34
57d0e66378b0 Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents: 33
diff changeset
337 from_.sayOnIRCTo(to_.nickname, message.getBody())
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
338
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
339 except NoSuchParticipantException:
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
340 if xmpp_c.nickname == self.nickname:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
341 r = self.respond(str(message.getBody()), participant_=from_)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
342 if isinstance(r, basestring) and len(r) > 0:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
343 s = xmpp.protocol.Message(to=message.getFrom(), body=r, typ='chat')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
344 self.error('==> Debug: Sending', debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
345 self.error(s.__str__(fancy=1), debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
346 xmpp_c.send(s)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
347 else:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
348 self.error('=> Debug: won\'t answer.', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
349 return
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
350 self.error('=> Debug: XMPP chat message not relayed', debug=True)
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
351 return
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
352
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
353 # message does not come from a room
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
354 if xmpp_c.nickname == self.nickname:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
355 self.error('==> Debug: Received XMPP chat message.', debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
356 self.error(message.__str__(fancy=1), debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
357
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
358 # Find out if the message comes from a bot admin
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
359 bot_admin = False
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
360 for jid in self.admins_jid:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
361 if xmpp.protocol.JID(jid).bareMatch(message.getFrom()):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
362 bot_admin = True
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
363 break
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
364
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
365 # Respond
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
366 r = self.respond(str(message.getBody()), bot_admin=bot_admin)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
367 if isinstance(r, basestring) and len(r) > 0:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
368 s = xmpp.protocol.Message(to=message.getFrom(), body=r, typ='chat')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
369 self.error('==> Debug: Sending', debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
370 self.error(s.__str__(fancy=1), debug=True)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
371 xmpp_c.send(s)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
372
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
373 else:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
374 self.error('=> Debug: Ignoring XMPP chat message not received on bot connection.', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
375
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
376 elif message.getType() == 'groupchat':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
377 # message comes from a room
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
378
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
379 for child in message.getChildren():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
380 if child.getName() == 'delay':
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
381 # MUC delayed message
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
382 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
383
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
384 if xmpp_c.nickname != self.nickname:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
385 self.error('=> Debug: Ignoring XMPP MUC message not received on bot connection.', debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
386 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
387
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
388
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
389 from_ = xmpp.protocol.JID(message.getFrom())
23
abdb7a2b6c6d Minor fixes.
Charly COSTE <changaco@changaco.net>
parents: 22
diff changeset
390
abdb7a2b6c6d Minor fixes.
Charly COSTE <changaco@changaco.net>
parents: 22
diff changeset
391 if unicode(from_.getResource()) == self.nickname:
abdb7a2b6c6d Minor fixes.
Charly COSTE <changaco@changaco.net>
parents: 22
diff changeset
392 self.error('=> Debug: Ignoring XMPP MUC message sent by self.', debug=True)
abdb7a2b6c6d Minor fixes.
Charly COSTE <changaco@changaco.net>
parents: 22
diff changeset
393 return
abdb7a2b6c6d Minor fixes.
Charly COSTE <changaco@changaco.net>
parents: 22
diff changeset
394
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
395 room_jid = unicode(from_.getNode()+'@'+from_.getDomain())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
396 for bridge in self.bridges:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
397 if room_jid == bridge.xmpp_room_jid:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
398 resource = unicode(from_.getResource())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
399 if resource == '':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
400 # message comes from the room itself
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
401 self.error('=> Debug: Ignoring XMPP groupchat message sent by the room.', debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
402 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
403 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
404 # message comes from a participant of the room
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
405 self.error('==> Debug: Received XMPP groupchat message.', debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
406 self.error(message.__str__(fancy=1), debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
407
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
408 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
409 participant_ = bridge.getParticipant(resource)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
410 except NoSuchParticipantException:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
411 if resource != self.nickname:
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
412 self.error('=> Debug: NoSuchParticipantException "'+resource+'" on "'+str(bridge)+'", WTF ?', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
413 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
414
25
a9066c416533 Added an XMPP disconnect handler, fixed XMPP message handling.
Charly COSTE <changaco@changaco.net>
parents: 24
diff changeset
415 participant_.sayOnIRC(message.getBody())
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
416 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
417
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
418 elif message.getType() == 'error':
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
419 for b in self.bridges:
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
420 if message.getFrom() == b.xmpp_room_jid:
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
421 # message comes from a room
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
422 for c in message.getChildren():
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
423 if c.getName() == 'error':
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
424 for cc in c.getChildren():
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
425 if cc.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and cc.getName() != 'text':
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
426 err = cc.getName()
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
427 if err == 'not-acceptable':
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
428 # we sent a message to a room we are not in
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
429 # probable cause is a MUC server restart
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
430 # let's restart the bot
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
431 self.restart()
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
432 elif err == 'forbidden':
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
433 # we don't have the permission to speak
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
434 # let's remove the bridge and tell admins
112
a817ad05dd1d stop bridge on error instead of removing it
Charly COSTE <changaco@changaco.net>
parents: 111
diff changeset
435 self.error('[Error] Not allowed to speak on the XMPP MUC of bridge '+str(b)+', stopping it', send_to_admins=True)
a817ad05dd1d stop bridge on error instead of removing it
Charly COSTE <changaco@changaco.net>
parents: 111
diff changeset
436 b.stop(message='Not allowed to speak on the XMPP MUC, stopping bridge.')
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
437 else:
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
438 self.error('==> Debug: recevied unknown error message', debug=True)
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
439 self.error(message.__str__(fancy=1), debug=True)
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
440 return
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
441
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
442 self.error('==> Debug: recevied unknown error message', debug=True)
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
443 self.error(message.__str__(fancy=1), debug=True)
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
444
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
445 else:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
446 self.error('==> Debug: Received XMPP message of unknown type "'+message.getType()+'".', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
447 self.error(message.__str__(fancy=1), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
448
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
449
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
450 def _irc_event_handler(self, connection, event):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
451 """[Internal] Manage IRC events"""
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
452
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
453 # Answer ping
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
454 if event.eventtype() == 'ping':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
455 connection.pong(connection.get_server_name())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
456 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
457
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
458
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
459 # Events we always want to ignore
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
460 if 'all' in event.eventtype() or 'motd' in event.eventtype():
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
461 return
23
abdb7a2b6c6d Minor fixes.
Charly COSTE <changaco@changaco.net>
parents: 22
diff changeset
462 if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo']:
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
463 self.error('=> Debug: ignoring IRC '+event.eventtype(), debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
464 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
465
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
466
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
467 nickname = None
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
468 if event.source() != None:
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
469 if '!' in event.source():
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
470 nickname = event.source().split('!')[0]
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
471
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
472
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
473 # Events that we want to ignore only in some cases
14
1a1f2a0d35c7 Fixed bug that prevented the bot from connecting to freenode and all other servers that don't send "umode"
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
474 if event.eventtype() in ['umode', 'welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'endofnames', 'luserunknown', 'luserconns']:
1a1f2a0d35c7 Fixed bug that prevented the bot from connecting to freenode and all other servers that don't send "umode"
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
475 if connection.really_connected == False:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
476 if event.target() == connection.nickname:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
477 connection.really_connected = True
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
478 connection._call_nick_callbacks(None)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
479 elif len(connection.nick_callbacks) > 0:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
480 self.error('===> Debug: event target ('+event.target()+') and connection nickname ('+connection.nickname+') don\'t match')
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
481 connection._call_nick_callbacks('nicknametoolong', arguments=[len(event.target())])
14
1a1f2a0d35c7 Fixed bug that prevented the bot from connecting to freenode and all other servers that don't send "umode"
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
482 self.error('=> Debug: ignoring '+event.eventtype(), debug=True)
1a1f2a0d35c7 Fixed bug that prevented the bot from connecting to freenode and all other servers that don't send "umode"
Charly COSTE <changaco@changaco.net>
parents: 11
diff changeset
483 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
484
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
485
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
486 # A string representation of the event
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 55
diff changeset
487 event_str = '==> Debug: Received IRC event.\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+auto_decode(event.source().__str__())+'\ntarget='+auto_decode(event.target().__str__())+'\narguments='+auto_decode(event.arguments().__str__())
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
488
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
489
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
490 if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
491 if nickname == None:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
492 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
493
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
494 handled = False
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
495
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
496 if event.eventtype() in ['quit', 'part', 'nick', 'kick']:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
497 if connection.get_nickname() != self.nickname:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
498 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True)
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
499 return
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
500 else:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
501 self.error(event_str, debug=True)
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
502
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
503 if event.eventtype() == 'kick' and len(event.arguments()) < 1:
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
504 self.error('=> Debug: length of arguments should be greater than 0 for a '+event.eventtype()+' event')
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
505 return
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
506
54
2507f424773a Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents: 53
diff changeset
507 if event.eventtype() in ['pubmsg', 'action']:
55
c09f9523fe2e I'm stupid ...
Charly COSTE <changaco@changaco.net>
parents: 54
diff changeset
508 if connection.get_nickname() != self.nickname:
54
2507f424773a Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents: 53
diff changeset
509 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bot connection', debug=True)
2507f424773a Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents: 53
diff changeset
510 return
2507f424773a Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents: 53
diff changeset
511 if nickname == self.nickname:
2507f424773a Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents: 53
diff changeset
512 self.error('=> Debug: ignoring IRC '+event.eventtype()+' sent by self', debug=True)
2507f424773a Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents: 53
diff changeset
513 return
50
dbb7c29a71e2 Ignore messages sent by self
Charly COSTE <changaco@changaco.net>
parents: 49
diff changeset
514
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
515 # TODO: lock self.bridges for thread safety
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
516 for bridge in self.bridges:
32
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
517 if connection.server != bridge.irc_server:
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
518 continue
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
519
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
520 try:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
521 from_ = bridge.getParticipant(nickname)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
522
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
523 except NoSuchParticipantException:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
524 continue
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
525
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
526
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
527 # Private message
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
528 if event.eventtype() == 'privmsg':
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
529 if event.target() == None:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
530 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
531
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
532 try:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
533 to_ = bridge.getParticipant(event.target().split('!')[0])
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
534 self.error(event_str, debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
535 from_.sayOnXMPPTo(to_.nickname, event.arguments()[0])
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
536 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
537
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
538 except NoSuchParticipantException:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
539 if event.target().split('!')[0] == self.nickname:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
540 # Message is for the bot
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
541 self.error(event_str, 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
542 connection.privmsg(from_.nickname, self.respond(event.arguments()[0]))
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
543 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
544 else:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
545 continue
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
546
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
547
92
aae8870b3727 Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents: 91
diff changeset
548 # kick handling
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
549 if event.eventtype() == 'kick':
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
550 if event.target().lower() == bridge.irc_room:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
551 try:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
552 kicked = bridge.getParticipant(event.arguments()[0])
72
6c4b841144f6 Better handling of participants
Charly COSTE <changaco@changaco.net>
parents: 70
diff changeset
553 if isinstance(kicked.irc_connection, irclib.ServerConnection):
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
554 kicked.irc_connection.join(bridge.irc_room)
93
c95fe0b319d9 XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents: 92
diff changeset
555 else:
92
aae8870b3727 Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents: 91
diff changeset
556 if len(event.arguments()) > 1:
aae8870b3727 Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents: 91
diff changeset
557 bridge.removeParticipant('irc', kicked.nickname, 'Kicked by '+nickname+' with reason: '+event.arguments()[1])
aae8870b3727 Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents: 91
diff changeset
558 else:
aae8870b3727 Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents: 91
diff changeset
559 bridge.removeParticipant('irc', kicked.nickname, 'Kicked by '+nickname+' (no reason was given)')
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
560 return
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
561 except NoSuchParticipantException:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
562 self.error('=> Debug: a participant that was not here has been kicked ? WTF ?')
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
563 return
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
564 else:
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
565 continue
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
566
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
567
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
568 # Leaving events
45
41394ddb3aff Lower before comparing strings.
Charly COSTE <changaco@changaco.net>
parents: 44
diff changeset
569 if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target().lower() == bridge.irc_room:
78
a8749705fe94 Fixed IRC quit event handling
Charly COSTE <changaco@changaco.net>
parents: 77
diff changeset
570 if event.eventtype() == 'quit' and ( bridge.mode != 'normal' or isinstance(from_.irc_connection, irclib.ServerConnection) ):
a8749705fe94 Fixed IRC quit event handling
Charly COSTE <changaco@changaco.net>
parents: 77
diff changeset
571 continue
30
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
572 if len(event.arguments()) > 0:
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
573 leave_message = event.arguments()[0]
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
574 elif event.eventtype() == 'quit':
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
575 leave_message = 'Left server.'
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
576 elif event.eventtype() == 'part':
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
577 leave_message = 'Left channel.'
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
578 else:
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
579 leave_message = ''
c0fb916cb0a0 Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents: 29
diff changeset
580 bridge.removeParticipant('irc', from_.nickname, leave_message)
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
581 handled = True
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
582 continue
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
583
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
584
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
585 # Nickname change
41
4c4f4ee72e17 Fixed IRC "nick" event handling. Fixed bot's XMPP infinite loop.
Charly COSTE <changaco@changaco.net>
parents: 39
diff changeset
586 if event.eventtype() == 'nick':
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
587 from_.changeNickname(event.target(), 'xmpp')
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
588 handled = True
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
589 continue
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
590
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
591
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
592 # Chan message
32
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
593 if event.eventtype() in ['pubmsg', 'action']:
45
41394ddb3aff Lower before comparing strings.
Charly COSTE <changaco@changaco.net>
parents: 44
diff changeset
594 if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server:
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
595 self.error(event_str, debug=True)
32
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
596 message = event.arguments()[0]
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
597 if event.eventtype() == 'action':
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
598 message = '/me '+message
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
599 from_.sayOnXMPP(message)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
600 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
601 else:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
602 continue
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
603
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
604 if handled == False:
53
a2258a705a17 Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents: 52
diff changeset
605 if not event.eventtype() in ['quit', 'part', 'nick', 'kick']:
39
3b06450d60cd Improved debug output.
Charly COSTE <changaco@changaco.net>
parents: 37
diff changeset
606 self.error(event_str, debug=True)
44
3d964ca1cf89 Fixed XMPP infinite loop and a debug message that wasn't flagged as a debug one.
Charly COSTE <changaco@changaco.net>
parents: 42
diff changeset
607 self.error('=> Debug: event was not handled', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
608 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
609
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
610
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
611 # Handle bannedfromchan
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
612 if event.eventtype() == 'bannedfromchan':
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
613 if len(event.arguments()) < 1:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
614 self.error('=> Debug: length of arguments should be greater than 0 for a '+event.eventtype()+' event')
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
615 return
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
616
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
617 for bridge in self.bridges:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
618 if connection.server != bridge.irc_server or event.arguments()[0].lower() != bridge.irc_room:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
619 continue
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
620
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
621 if event.target() == self.nickname:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
622 self.error('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
623 raise Exception('[Error] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
624 else:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
625 try:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
626 banned = bridge.getParticipant(event.target())
72
6c4b841144f6 Better handling of participants
Charly COSTE <changaco@changaco.net>
parents: 70
diff changeset
627 if banned.irc_connection != 'bannedfromchan':
6c4b841144f6 Better handling of participants
Charly COSTE <changaco@changaco.net>
parents: 70
diff changeset
628 banned.irc_connection = 'bannedfromchan'
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
629 self.error(event_str, debug=True)
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
630 self.error('[Notice] the nickname "'+event.target()+'" is banned from the IRC chan of bridge "'+str(bridge)+'"')
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
631 bridge.say('[Warning] the nickname "'+event.target()+'" is banned from the IRC chan')
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
632 else:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
633 self.error('=> Debug: ignoring '+event.eventtype(), debug=True)
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
634 except NoSuchParticipantException:
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
635 self.error('=> Debug: no such participant. WTF ?')
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
636 return
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
637
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
638 return
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
639
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
640
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
641 # Joining events
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
642 if event.eventtype() in ['namreply', 'join']:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
643 if connection.get_nickname() != self.nickname:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
644 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
645 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
646
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
647 if event.eventtype() == 'namreply':
48
cb08ea878db9 lower() for "join" and "namreply" IRC events
Charly COSTE <changaco@changaco.net>
parents: 47
diff changeset
648 for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server):
77
686724c5183c Fixed IRC namreply handling
Charly COSTE <changaco@changaco.net>
parents: 75
diff changeset
649 for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
650 if nickname == '' or nickname == self.nickname:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
651 continue
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
652 bridge.addParticipant('irc', nickname)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
653 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
654 elif event.eventtype() == 'join':
48
cb08ea878db9 lower() for "join" and "namreply" IRC events
Charly COSTE <changaco@changaco.net>
parents: 47
diff changeset
655 bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
656 if len(bridges) == 0:
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
657 self.error(event_str, debug=True)
48
cb08ea878db9 lower() for "join" and "namreply" IRC events
Charly COSTE <changaco@changaco.net>
parents: 47
diff changeset
658 self.error('===> Debug: no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
659 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
660 for bridge in bridges:
115
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 113
diff changeset
661 bridge.addParticipant('irc', nickname, irc_id=event.source())
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
662 return
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
663
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
664
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
665 # From here the event is shown
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
666 self.error(event_str, debug=True)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
667
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
668
88
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
669 if event.eventtype() in ['disconnect', 'kill']:
70
01f1c6cb7447 Prevent unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 64
diff changeset
670 if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer':
01f1c6cb7447 Prevent unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 64
diff changeset
671 return
01f1c6cb7447 Prevent unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 64
diff changeset
672
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
673 # TODO: lock self.bridges for thread safety
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
674 for bridge in self.bridges:
63
71508f22edb4 Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 58
diff changeset
675 if connection.server != bridge.irc_server:
71508f22edb4 Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 58
diff changeset
676 continue
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
677 try:
88
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
678 p = bridge.getParticipant(connection.get_nickname())
118
b29fd5696a78 new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
679 if bridge.mode in ['normal', 'bypass']:
b29fd5696a78 new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
680 bridge.changeMode('limited')
88
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
681 else:
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
682 if p.irc_connection.really_connected == True:
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
683 p.irc_connection.part(bridge.irc_room, message=message)
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
684 p.irc_connection.used_by -= 1
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
685 if p.irc_connection.used_by < 1:
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
686 p.irc_connection.close(message)
8b071629558e Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
687 p.irc_connection = None
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
688 except NoSuchParticipantException:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
689 pass
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 3
diff changeset
690 return
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
691
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
692
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
693 # Nickname callbacks
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
694 # TODO: move this into irclib.py
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
695 if event.eventtype() == 'nicknameinuse':
118
b29fd5696a78 new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
696 connection._call_nick_callbacks('nicknameinuse', arguments=[event])
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
697 return
64
8fc496eaa17b Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents: 63
diff changeset
698 if event.eventtype() == 'nickcollision':
118
b29fd5696a78 new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
699 connection._call_nick_callbacks('nickcollision', arguments=[event])
64
8fc496eaa17b Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents: 63
diff changeset
700 return
58
92341dbfb8b7 Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
701 if event.eventtype() == 'erroneusnickname':
118
b29fd5696a78 new mode bypass and new method bridge.changeMode
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
702 connection._call_nick_callbacks('erroneusnickname', arguments=[event])
5
cb0daec4b778 Added support for IRC "nick" event, fixed participant.changeNickname(), fixed handling of IRC "namreply" event, removed muc._check() because waiting does not solve the problem if it is blocking incoming messages handling
Charly COSTE <changaco@changaco.net>
parents: 3
diff changeset
703 return
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
704
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
705
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
706 # Unhandled events
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
707 self.error('=> Debug: event not handled', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
708
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
709
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
710 def _send_message_to_admins(self, message):
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
711 """[Internal] Send XMPP Message to bot admin(s)"""
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
712 for admin_jid in self.admins_jid:
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
713 try:
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
714 self.xmpp_c.send(xmpp.protocol.Message(to=admin_jid, body=message, typ='chat'))
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
715 except:
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
716 pass
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
717
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 79
diff changeset
718
21
801160b4136f Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents: 20
diff changeset
719 def new_bridge(self, xmpp_room, irc_room, irc_server, mode, say_level, irc_port=6667):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
720 """Create a bridge between xmpp_room and irc_room at irc_server."""
21
801160b4136f Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents: 20
diff changeset
721 b = bridge(self, xmpp_room, irc_room, irc_server, mode, say_level, irc_port=irc_port)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
722 self.bridges.append(b)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
723 return b
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
724
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
725
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
726 def findBridges(self, str_array):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
727 # TODO: lock self.bridges for thread safety
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
728 bridges = [b for b in self.bridges]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
729 for bridge in [b for b in bridges]:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
730 for s in str_array:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
731 if not s in str(bridge):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
732 bridges.remove(bridge)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
733 break
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
734 return bridges
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
735
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
736
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
737 def getBridges(self, irc_room=None, irc_server=None, xmpp_room_jid=None):
96
dd7e1b935894 Code cleaning
Charly COSTE <changaco@changaco.net>
parents: 93
diff changeset
738 # TODO: lock self.bridges for thread safety
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
739 bridges = [b for b in self.bridges]
32
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
740 for bridge in [b for b in bridges]:
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
741 if irc_room != None and bridge.irc_room != irc_room:
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
742 bridges.remove(bridge)
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
743 continue
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
744 if irc_server != None and bridge.irc_server != irc_server:
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
745 bridges.remove(bridge)
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
746 continue
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
747 if xmpp_room_jid != None and bridge.xmpp_room_jid != xmpp_room_jid:
32
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
748 bridges.remove(bridge)
8aa261545662 Implemented "/me" in the IRC->XMPP way (ie "action" event is now handled). Re-written bot.getBridges because the old one didn't always work and was slow.
Charly COSTE <changaco@changaco.net>
parents: 30
diff changeset
749 continue
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
750 return bridges
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
751
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
752
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
753 def get_xmpp_connection(self, nickname):
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
754 if self.xmpp_connections.has_key(nickname):
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
755 c = self.xmpp_connections[nickname]
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
756 c.used_by += 1
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
757 self.error('===> Debug: using existing XMPP connection for "'+nickname+'", now used by '+str(c.used_by)+' bridges', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
758 return c
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
759 self.error('===> Debug: opening new XMPP connection for "'+nickname+'"', debug=True)
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
760 c = xmpp.client.Client(self.bare_jid.getDomain(), debug=[])
35
ebf516b2e5c9 Switched from Lock() to RLock().
Charly COSTE <changaco@changaco.net>
parents: 34
diff changeset
761 c.lock = threading.RLock()
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
762 c.lock.acquire()
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
763 self.xmpp_connections[nickname] = c
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
764 c.used_by = 1
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
765 c.nickname = nickname
90
965dd6f5fcc3 Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents: 88
diff changeset
766 c.mucs = []
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 72
diff changeset
767 c.pings = []
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
768 c.connect()
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
769 c.auth(self.bare_jid.getNode(), self.password)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
770 c.RegisterHandler('presence', self._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: 14
diff changeset
771 c.RegisterHandler('iq', self._xmpp_iq_handler)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
772 c.RegisterHandler('message', self._xmpp_message_handler)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
773 c.sendInitPresence()
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
774 if nickname == self.nickname:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
775 c.send(xmpp.protocol.Presence(priority=127))
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
776 c.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: 14
diff changeset
777 return c
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
778
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
779
100
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
780 def reopen_xmpp_connection(self, c):
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
781 if not isinstance(c, xmpp.client.Client):
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
782 return
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
783 bot_connection = False
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
784 if c == self.xmpp_c:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
785 bot_connection = True
100
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
786 mucs = c.mucs
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
787 nickname = c.nickname
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
788 used_by = c.used_by
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
789 participants = []
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
790 for b in self.bridges:
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
791 for p in b.participants:
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
792 if p.xmpp_c == c:
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
793 participants.append(p)
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
794 p.xmpp_c = None
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
795 self.error('===> Debug: reopening XMPP connection for "'+nickname+'"', debug=True)
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
796 self.xmpp_connections.pop(nickname)
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
797 c.send(xmpp.protocol.Presence(typ='unavailable'))
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
798 del c
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
799 c = self.get_xmpp_connection(nickname)
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
800 c.used_by = used_by
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
801 if bot_connection:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
802 self.xmpp_c = c
100
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
803 for p in participants:
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
804 p.xmpp_c = c
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
805 c.mucs = mucs
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
806 for m in c.mucs:
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
807 m.rejoin()
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
808
6289ac5a2db7 Reconnect when a connection is closed
Charly COSTE <changaco@changaco.net>
parents: 99
diff changeset
809
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
810 def close_xmpp_connection(self, nickname):
29
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 27
diff changeset
811 if not self.xmpp_connections.has_key(nickname):
a694ffe6a973 Fixed nickname change.
Charly COSTE <changaco@changaco.net>
parents: 27
diff changeset
812 return
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
813 c = self.xmpp_connections[nickname]
42
b8c9ddf320f8 Thread safety for bot.close_xmpp_connection().
Charly COSTE <changaco@changaco.net>
parents: 41
diff changeset
814 c.lock.acquire()
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
815 c.used_by -= 1
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
816 if c.used_by < 1:
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
817 self.error('===> Debug: closing XMPP connection for "'+nickname+'"', debug=True)
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
818 self.xmpp_connections.pop(nickname)
52
5aabf124c78d Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents: 51
diff changeset
819 c.send(xmpp.protocol.Presence(typ='unavailable'))
49
714e78fb912e Tried to improve thread-safety during XMPP connection closing.
Charly COSTE <changaco@changaco.net>
parents: 48
diff changeset
820 c.lock.release()
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
821 del c
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
822 else:
42
b8c9ddf320f8 Thread safety for bot.close_xmpp_connection().
Charly COSTE <changaco@changaco.net>
parents: 41
diff changeset
823 c.lock.release()
37
7e500d4064fb Cosmetics.
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
824 self.error('===> Debug: XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
825
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
826
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
827 def removeBridge(self, bridge, message='Removing bridge'):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
828 self.bridges.remove(bridge)
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
829 bridge.stop(message)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
830
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
831
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
832 def respond(self, message, participant_=None, bot_admin=False):
18
3cdf7bb580da Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents: 17
diff changeset
833 ret = ''
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
834 command = shlex.split(message)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
835 args_array = []
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
836 if len(command) > 1:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
837 args_array = command[1:]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
838 command = command[0]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
839
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
840 if isinstance(participant_, participant) and bot_admin != participant_.bot_admin:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
841 bot_admin = participant_.bot_admin
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
842
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
843 if command == 'xmpp-participants':
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
844 if not isinstance(participant_, participant):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
845 for b in self.bridges:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
846 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp'])
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
847 ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
848 return ret
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
849 else:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
850 xmpp_participants_nicknames = participant_.bridge.get_participants_nicknames_list(protocols=['xmpp'])
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
851 return '\nparticipants on '+participant_.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames)
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
852
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
853 elif command == 'irc-participants':
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
854 if not isinstance(participant_, participant):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
855 for b in self.bridges:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
856 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc'])
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
857 ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames)
18
3cdf7bb580da Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents: 17
diff changeset
858 return ret
3cdf7bb580da Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents: 17
diff changeset
859 else:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
860 irc_participants_nicknames = participant_.bridge.get_participants_nicknames_list(protocols=['irc'])
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
861 return '\nparticipants on '+participant_.bridge.irc_room+' at '+participant_.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames)
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
862
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
863 elif command == 'bridges':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
864 parser = ArgumentParser(prog=command)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
865 parser.add_argument('--show-mode', default=False, action='store_true')
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
866 parser.add_argument('--show-say-level', default=False, action='store_true')
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
867 parser.add_argument('--show-participants', default=False, action='store_true')
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
868 try:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
869 args = parser.parse_args(args_array)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
870 except ParseException as e:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
871 return '\n'+e.args[1]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
872 ret = 'List of bridges:'
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
873 for i, b in enumerate(self.bridges):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
874 ret += '\n'+str(i+1)+' - '+str(b)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
875 if args.show_mode:
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
876 ret += ' - mode='+b.mode
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
877 if args.show_say_level:
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
878 ret += ' - say_level='+bridge._say_levels[b.say_level]
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
879 if args.show_participants:
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
880 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp'])
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
881 ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames)
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
882 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc'])
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
883 ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames)
108
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
884 if b.irc_connection == None:
dff9746aa508 XMPP room deletion (and server shut down) handling
Charly COSTE <changaco@changaco.net>
parents: 105
diff changeset
885 ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it'
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
886 return ret
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
887
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
888 elif command in bot.admin_commands:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
889 if bot_admin == False:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
890 return 'You have to be a bot admin to use this command.'
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
891
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
892 if command == 'add-bridge':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
893 parser = ArgumentParser(prog=command)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
894 parser.add_argument('xmpp_room_jid', type=str)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
895 parser.add_argument('irc_chan', type=str)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
896 parser.add_argument('irc_server', type=str)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
897 parser.add_argument('--mode', choices=bridge._modes, default='normal')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
898 parser.add_argument('--say-level', choices=bridge._say_levels, default='all')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
899 parser.add_argument('--irc-port', type=int, default=6667)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
900 try:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
901 args = parser.parse_args(args_array)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
902 except ParseException as e:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
903 return '\n'+e.args[1]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
904
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
905 self.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
906
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
907 return 'Bridge added.'
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
908
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
909 elif command == 'add-xmpp-admin':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
910 parser = ArgumentParser(prog=command)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
911 parser.add_argument('jid', type=str)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
912 try:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
913 args = parser.parse_args(args_array)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
914 except ParseException as e:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
915 return '\n'+e.args[1]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
916 self.admins_jid.append(args.jid)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
917 for b in self.bridges:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
918 for p in b.participants:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
919 if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
920 p.bot_admin = True
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
921
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
922 return 'XMPP admin added.'
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
923
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
924 elif command == 'restart-bot':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
925 self.restart()
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
926 return
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
927 elif command == 'halt':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
928 self.__del__()
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
929 return
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
930
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
931
110
ec4fbec1f160 new stop-bridge command
Charly COSTE <changaco@changaco.net>
parents: 108
diff changeset
932 elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']:
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
933 # we need to know which bridge the command is for
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
934 if len(args_array) == 0:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
935 if isinstance(participant_, participant):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
936 b = participant_.bridge
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
937 else:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
938 return 'You must specify a bridge. '+self.respond('bridges')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
939 else:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
940 try:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
941 bn = int(args_array[0])
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
942 if bn < 1:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
943 raise IndexError
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
944 b = self.bridges[bn-1]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
945 except IndexError:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
946 return 'Invalid bridge number "'+str(bn)+'". '+self.respond('bridges')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
947 except ValueError:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
948 bridges = self.findBridges(args_array)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
949 if len(bridges) == 0:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
950 return 'No bridge found matching "'+' '.join(args_array)+'". '+self.respond('bridges')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
951 elif len(bridges) == 1:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
952 b = bridges[0]
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
953 elif len(bridges) > 1:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
954 return 'More than one bridge matches "'+' '.join(args_array)+'", please be more specific. '+self.respond('bridges')
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
955
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
956 if command == 'remove-bridge':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
957 self.removeBridge(b)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
958 return 'Bridge removed.'
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
959 elif command == 'restart-bridge':
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
960 b.restart()
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
961 return 'Bridge restarted.'
110
ec4fbec1f160 new stop-bridge command
Charly COSTE <changaco@changaco.net>
parents: 108
diff changeset
962 elif command == 'stop-bridge':
ec4fbec1f160 new stop-bridge command
Charly COSTE <changaco@changaco.net>
parents: 108
diff changeset
963 b.stop()
ec4fbec1f160 new stop-bridge command
Charly COSTE <changaco@changaco.net>
parents: 108
diff changeset
964 return 'Bridge stopped.'
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
965
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
966 else:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
967 ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(bot.commands)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
968 if bot_admin == True:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
969 return ret+'\n'+'admin commands: '+' '.join(bot.admin_commands)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
970 else:
18
3cdf7bb580da Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents: 17
diff changeset
971 return ret
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
972
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
973
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
974 def restart(self):
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
975 # Stop the bridges
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
976 for b in self.bridges:
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
977 b.stop(message='Restarting bot')
103
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
978
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
979 # Reopen the bot's XMPP connection
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
980 self.reopen_xmpp_connection(self.xmpp_c)
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
981
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
982 # Restart the bridges
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
983 for b in self.bridges:
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
984 b.init2()
23416c27b592 New command system
Charly COSTE <changaco@changaco.net>
parents: 101
diff changeset
985
105
d8acff763731 Handle MUC error messages
Charly COSTE <changaco@changaco.net>
parents: 103
diff changeset
986 self.error('Bot restarted.', send_to_admins=True)
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
987
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
988
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
989 def __del__(self):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
990 for bridge in self.bridges:
52
5aabf124c78d Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents: 51
diff changeset
991 self.removeBridge(bridge)