Mercurial > xib
annotate bot.py @ 99:5390e9abfa44
Don't try to remove a participant that does not exist
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 04 Oct 2009 14:00:31 +0200 |
parents | dd7e1b935894 |
children | 6289ac5a2db7 |
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 # *** Versioning *** |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
19 # Major will pass to 1 when xib will be considered fault-tolerant |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
20 # After that major will only be changed if the new version is not retro-compatible (e.g. requires changes in config file) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
21 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
22 version = 0, 1 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
23 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
24 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 import irclib |
75 | 26 import muc |
27 xmpp = muc.xmpp | |
28 del muc | |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
23
diff
changeset
|
29 import threading |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
30 from bridge import * |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
31 from time import sleep |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
32 import re |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
33 import sys |
20
08cde283621a
Fixed a little bug in exception handling.
Charly COSTE <changaco@changaco.net>
parents:
19
diff
changeset
|
34 import xml.parsers.expat |
51
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
35 import traceback |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
36 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
38 class bot(Thread): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
39 |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
40 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
|
41 Thread.__init__(self) |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
42 self.commands = ['!xmpp_participants', '!irc_participants'] |
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
|
43 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
|
44 self.bare_jid.setResource('') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
45 self.nickname = nickname |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
46 self.password = password |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
47 self.error_fd = error_fd |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
48 self.debug = debug |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
49 self.admins_jid = admins_jid |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
50 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
|
51 self.xmpp_connections = {} |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
52 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
|
53 self.irc.bot = self |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
54 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
|
55 self.irc_thread = Thread(target=self.irc.process_forever) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
56 self.irc_thread.start() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
57 # Open connection with XMPP server |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
58 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
|
59 self.xmpp_c = self.get_xmpp_connection(self.nickname) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
60 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
|
61 self.error('[Error] XMPP Connection failed') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
62 raise |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
63 self.xmpp_thread = Thread(target=self._xmpp_loop) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
64 self.xmpp_thread.start() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
65 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
66 |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
67 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
|
68 """Output an error message.""" |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
69 if send_to_admins == True: |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
70 self._send_message_to_admins(s) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
71 if not debug or debug and self.debug: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
72 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
73 self.error_fd.write(auto_encode(s)+"\n") |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
74 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
75 self.error_fd.write('Error message cannot be transcoded.\n') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
77 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
78 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
|
79 """[Internal] XMPP infinite loop.""" |
75 | 80 i = 1 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
81 while True: |
79
73a30fc1922b
Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
82 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
|
83 try: |
51
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
84 if len(self.xmpp_connections) == 1: |
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
85 sleep(0.5) # avoid bot connection being locked all the time |
75 | 86 j = 0 |
51
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
87 for c in self.xmpp_connections.itervalues(): |
75 | 88 i += 1 |
89 j += 1 | |
51
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
90 if hasattr(c, 'lock'): |
49
714e78fb912e
Tried to improve thread-safety during XMPP connection closing.
Charly COSTE <changaco@changaco.net>
parents:
48
diff
changeset
|
91 c.lock.acquire() |
75 | 92 if i == j: |
93 ping = xmpp.protocol.Iq(typ='get') | |
94 ping.addChild(name='ping', namespace='urn:xmpp:ping') | |
95 self.error('=> Debug: sending XMPP ping', debug=True) | |
96 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
|
97 if hasattr(c, 'Process'): |
5aabf124c78d
Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents:
51
diff
changeset
|
98 c.Process(0.01) |
5aabf124c78d
Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents:
51
diff
changeset
|
99 c.lock.release() |
75 | 100 if i > 5000: |
101 i = 0 | |
51
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
102 except RuntimeError: |
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
103 pass |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
23
diff
changeset
|
104 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed): |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
70
diff
changeset
|
105 self.error('=> Debug: invalid stanza', debug=True) |
79
73a30fc1922b
Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
106 unlock = True |
91
69e4fc0f015c
Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
107 except xmpp.Conflict: |
69e4fc0f015c
Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
108 c.reconnectAndReauth() |
69e4fc0f015c
Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
109 for m in c.mucs: |
69e4fc0f015c
Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
110 m.rejoin() |
69e4fc0f015c
Tried to fix XMPP «Replaced by new connection» problem
Charly COSTE <changaco@changaco.net>
parents:
90
diff
changeset
|
111 unlock = True |
51
2737ed5b9003
Tried to improve the XMPP loop, again.
Charly COSTE <changaco@changaco.net>
parents:
50
diff
changeset
|
112 except: |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
113 error = '[Error] Unkonwn exception on XMPP thread:\n' |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
114 error += traceback.format_exc() |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
115 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
|
116 unlock = True |
73a30fc1922b
Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
117 if unlock == True: |
73a30fc1922b
Fixed the XMPP loop (release the lock)
Charly COSTE <changaco@changaco.net>
parents:
78
diff
changeset
|
118 c.lock.release() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
119 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
120 |
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
|
121 def _xmpp_presence_handler(self, dispatcher, presence): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
122 """[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
|
123 |
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
|
124 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
|
125 |
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
|
126 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
|
127 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
|
128 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
|
129 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
130 self.error('==> Debug: Received XMPP presence.', debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
131 self.error(presence.__str__(fancy=1), debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
132 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
133 from_ = xmpp.protocol.JID(presence.getFrom()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
134 bare_jid = unicode(from_.getNode()+'@'+from_.getDomain()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
135 for bridge in self.bridges: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
136 if bare_jid == bridge.xmpp_room.room_jid: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
137 # presence comes from a muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
138 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
|
139 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
140 if resource == '': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
141 # presence comes from the muc itself |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
142 # TODO: handle room deletion and muc server reboot |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
143 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
|
144 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
145 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
146 # 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
|
147 |
93
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
148 if presence.getType() == 'unavailable': |
96 | 149 try: |
150 p = bridge.getParticipant(resource) | |
151 except NoSuchParticipantException: | |
152 p = None | |
153 | |
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
|
154 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') |
93
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
155 item = None |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
156 if x: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
157 item = x.getTag('item') |
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
|
158 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
|
159 # participant changed its nickname |
93
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
160 if p == None: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
161 return |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
162 if p.protocol != 'xmpp': |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 p.changeNickname(new_nick, 'irc') |
93
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
173 |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
174 elif x and x.getTag('status', attrs={'code': '307'}): |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
175 # participant was kicked |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
176 if p == None: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
177 bridge.xmpp_room.rejoin() |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
178 return |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
179 if isinstance(p.xmpp_c, xmpp.client.Client): |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
180 p.muc.rejoin() |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
181 else: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
182 if item: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
183 reason = item.getTag('reason') |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
184 actor = item.getTag('actor') |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
185 if actor and actor.has_attr('jid'): |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
186 kicker = actor.getAttr('jid') |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
187 s1 = 'Kicked by '+kicker |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
188 else: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
189 s1 = 'Kicked from XMPP' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
190 if reason: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
191 s2 = ' with reason: '+reason.getData() |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
192 else: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
193 s2 = ' (no reason was given)' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
194 else: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
195 s1 = 'Kicked from XMPP' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
196 s2 = ' (no reason was given)' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
197 |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
198 bridge.removeParticipant('xmpp', p.nickname, s1+s2) |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
199 |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
200 elif x and x.getTag('status', attrs={'code': '301'}): |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
201 # participant was banned |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
202 if p == None: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
203 m = '[Error] bot got banned from XMPP' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
204 self.error(m) |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
205 bridge.say(m, on_xmpp=False) |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
206 self.removeBridge(bridge) |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
207 return |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
208 if item: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
209 reason = item.getTag('reason') |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
210 actor = item.getTag('actor') |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
211 if actor and actor.has_attr('jid'): |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
212 kicker = actor.getAttr('jid') |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
213 s1 = 'Banned by '+kicker |
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 s1 = 'Banned from XMPP' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
216 if reason: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
217 s2 = ' with reason: '+reason.getData() |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
218 else: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
219 s2 = ' (no reason was given)' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
220 else: |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
221 s1 = 'Banned from XMPP' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
222 s2 = ' (no reason was given)' |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
223 |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
224 bridge.removeParticipant('xmpp', p.nickname, s1+s2) |
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
225 |
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
|
226 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
|
227 # participant left |
99
5390e9abfa44
Don't try to remove a participant that does not exist
Charly COSTE <changaco@changaco.net>
parents:
96
diff
changeset
|
228 if p != None: |
5390e9abfa44
Don't try to remove a participant that does not exist
Charly COSTE <changaco@changaco.net>
parents:
96
diff
changeset
|
229 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
|
230 |
96 | 231 elif resource != bridge.bot.nickname: |
232 bridge.addParticipant('xmpp', resource) | |
233 return | |
234 | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
235 return |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
236 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
237 |
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
|
238 def _xmpp_iq_handler(self, dispatcher, iq): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
239 """[Internal] Manage XMPP IQs.""" |
75 | 240 |
241 xmpp_c = dispatcher._owner | |
242 | |
243 # Ignore pongs | |
244 if iq.getType() in ['result', 'error'] and iq.getID() in xmpp_c.pings: | |
245 xmpp_c.pings.remove(iq.getID()) | |
246 self.error('=> Debug: received XMPP pong', debug=True) | |
247 return | |
248 | |
249 self.error('==> Debug: Received XMPP iq.', debug=True) | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
250 self.error(iq.__str__(fancy=1), debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
251 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
252 |
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
|
253 def _xmpp_message_handler(self, dispatcher, message): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
254 """[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
|
255 |
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
|
256 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
|
257 |
34
57d0e66378b0
Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents:
33
diff
changeset
|
258 if message.getBody() == None: |
57d0e66378b0
Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents:
33
diff
changeset
|
259 return |
57d0e66378b0
Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents:
33
diff
changeset
|
260 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
261 if message.getType() == 'chat': |
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
|
262 self.error('==> Debug: Received XMPP chat message.', debug=True) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
263 self.error(message.__str__(fancy=1), debug=True) |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
264 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
|
265 for bridge in self.bridges: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
266 if from_bare_jid == bridge.xmpp_room.room_jid: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
267 # 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
|
268 |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
269 try: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
270 from_ = bridge.getParticipant(message.getFrom().getResource()) |
27
9b7a628ca612
Fixed XMPP message handling, again.
Charly COSTE <changaco@changaco.net>
parents:
25
diff
changeset
|
271 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
|
272 |
34
57d0e66378b0
Fixed XMPP message handling and removed disconnect handler.
Charly COSTE <changaco@changaco.net>
parents:
33
diff
changeset
|
273 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
|
274 |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
275 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
|
276 if xmpp_c.nickname == self.nickname: |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
277 xmpp_c.send(xmpp.protocol.Message(to=message.getFrom(), body=self.respond(message.getBody(), participant=from_), typ='chat')) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
278 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
|
279 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
|
280 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
281 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
282 elif message.getType() == 'groupchat': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
283 # 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
|
284 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
285 for child in message.getChildren(): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
286 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
|
287 # MUC delayed message |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
288 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
|
289 |
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
|
290 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
|
291 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
|
292 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
|
293 |
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
|
294 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
295 from_ = xmpp.protocol.JID(message.getFrom()) |
23 | 296 |
297 if unicode(from_.getResource()) == self.nickname: | |
298 self.error('=> Debug: Ignoring XMPP MUC message sent by self.', debug=True) | |
299 return | |
300 | |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
301 room_jid = unicode(from_.getNode()+'@'+from_.getDomain()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
302 for bridge in self.bridges: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
303 if room_jid == bridge.xmpp_room.room_jid: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
304 resource = unicode(from_.getResource()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
305 if resource == '': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
306 # 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
|
307 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
|
308 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
309 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
310 # 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
|
311 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
|
312 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
|
313 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
314 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
315 participant_ = bridge.getParticipant(resource) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
316 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
|
317 if resource != self.nickname: |
37 | 318 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
|
319 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
|
320 |
25
a9066c416533
Added an XMPP disconnect handler, fixed XMPP message handling.
Charly COSTE <changaco@changaco.net>
parents:
24
diff
changeset
|
321 participant_.sayOnIRC(message.getBody()) |
37 | 322 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
|
323 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
324 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
|
325 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
|
326 self.error(message.__str__(fancy=1), debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
327 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
328 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
329 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
|
330 """[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
|
331 |
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
|
332 # Answer ping |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
333 if event.eventtype() == 'ping': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
334 connection.pong(connection.get_server_name()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
335 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
|
336 |
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
|
337 |
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 # 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
|
339 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
|
340 return |
23 | 341 if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo']: |
75 | 342 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
|
343 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
|
344 |
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
|
345 |
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
|
346 nickname = None |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
23
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 |
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
|
351 |
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
|
352 # 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 |
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
|
364 |
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
|
365 # A string representation of the event |
56 | 366 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
|
367 |
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
|
368 |
53
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 |
39 | 373 handled = False |
374 | |
53
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
375 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
|
376 if connection.get_nickname() != self.nickname: |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
377 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
|
378 return |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
379 else: |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
380 self.error(event_str, debug=True) |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
381 |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
382 if event.eventtype() == 'kick' and len(event.arguments()) < 1: |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
383 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
|
384 return |
39 | 385 |
54
2507f424773a
Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents:
53
diff
changeset
|
386 if event.eventtype() in ['pubmsg', 'action']: |
55 | 387 if connection.get_nickname() != self.nickname: |
54
2507f424773a
Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents:
53
diff
changeset
|
388 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
|
389 return |
2507f424773a
Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents:
53
diff
changeset
|
390 if nickname == self.nickname: |
2507f424773a
Fixed a bug introduced in previous commit
Charly COSTE <changaco@changaco.net>
parents:
53
diff
changeset
|
391 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
|
392 return |
50
dbb7c29a71e2
Ignore messages sent by self
Charly COSTE <changaco@changaco.net>
parents:
49
diff
changeset
|
393 |
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
|
394 # 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
|
395 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
|
396 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
|
397 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
|
398 |
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
|
399 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
|
400 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
|
401 |
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 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
|
403 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
|
404 |
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 |
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 # 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
|
407 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
|
408 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
|
409 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
|
410 |
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 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 |
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 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
|
418 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
|
419 # 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 |
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
|
426 |
92
aae8870b3727
Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents:
91
diff
changeset
|
427 # kick handling |
53
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
428 if event.eventtype() == 'kick': |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
429 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
|
430 try: |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
431 kicked = bridge.getParticipant(event.arguments()[0]) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
70
diff
changeset
|
432 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
|
433 kicked.irc_connection.join(bridge.irc_room) |
93
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
434 else: |
92
aae8870b3727
Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents:
91
diff
changeset
|
435 if len(event.arguments()) > 1: |
aae8870b3727
Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents:
91
diff
changeset
|
436 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
|
437 else: |
aae8870b3727
Better handling of IRC kick
Charly COSTE <changaco@changaco.net>
parents:
91
diff
changeset
|
438 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
|
439 return |
53
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
440 except NoSuchParticipantException: |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
441 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
|
442 return |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
443 else: |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
444 continue |
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
445 |
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 |
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
|
447 # Leaving events |
45
41394ddb3aff
Lower before comparing strings.
Charly COSTE <changaco@changaco.net>
parents:
44
diff
changeset
|
448 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
|
449 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
|
450 continue |
30
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
451 if len(event.arguments()) > 0: |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
452 leave_message = event.arguments()[0] |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
453 elif event.eventtype() == 'quit': |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
454 leave_message = 'Left server.' |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
455 elif event.eventtype() == 'part': |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
456 leave_message = 'Left channel.' |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
457 else: |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
458 leave_message = '' |
c0fb916cb0a0
Fixed IRC leaving events handling.
Charly COSTE <changaco@changaco.net>
parents:
29
diff
changeset
|
459 bridge.removeParticipant('irc', from_.nickname, leave_message) |
39 | 460 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
|
461 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
|
462 |
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
|
463 |
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 # Nickname change |
41
4c4f4ee72e17
Fixed IRC "nick" event handling. Fixed bot's XMPP infinite loop.
Charly COSTE <changaco@changaco.net>
parents:
39
diff
changeset
|
465 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
|
466 from_.changeNickname(event.target(), 'xmpp') |
39 | 467 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
|
468 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
|
469 |
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
|
470 |
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 # 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
|
472 if event.eventtype() in ['pubmsg', 'action']: |
45
41394ddb3aff
Lower before comparing strings.
Charly COSTE <changaco@changaco.net>
parents:
44
diff
changeset
|
473 if bridge.irc_room == event.target().lower() and bridge.irc_server == connection.server: |
39 | 474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 |
39 | 483 if handled == False: |
53
a2258a705a17
Handle kick (by simply rejoining) on IRC side
Charly COSTE <changaco@changaco.net>
parents:
52
diff
changeset
|
484 if not event.eventtype() in ['quit', 'part', 'nick', 'kick']: |
39 | 485 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
|
486 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
|
487 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
|
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 |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
490 # Handle bannedfromchan |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
491 if event.eventtype() == 'bannedfromchan': |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
492 if len(event.arguments()) < 1: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
493 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
|
494 return |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
495 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
496 for bridge in self.bridges: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
497 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
|
498 continue |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
499 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
500 if event.target() == self.nickname: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
501 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
|
502 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
|
503 else: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
504 try: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
505 banned = bridge.getParticipant(event.target()) |
72
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
70
diff
changeset
|
506 if banned.irc_connection != 'bannedfromchan': |
6c4b841144f6
Better handling of participants
Charly COSTE <changaco@changaco.net>
parents:
70
diff
changeset
|
507 banned.irc_connection = 'bannedfromchan' |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
508 self.error(event_str, debug=True) |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
509 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
|
510 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
|
511 else: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
512 self.error('=> Debug: ignoring '+event.eventtype(), debug=True) |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
513 except NoSuchParticipantException: |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
514 self.error('=> Debug: no such participant. WTF ?') |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
515 return |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
516 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
517 return |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
518 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
519 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
520 # 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
|
521 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
|
522 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
|
523 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
|
524 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
|
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 if event.eventtype() == 'namreply': |
48
cb08ea878db9
lower() for "join" and "namreply" IRC events
Charly COSTE <changaco@changaco.net>
parents:
47
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 elif event.eventtype() == 'join': |
48
cb08ea878db9
lower() for "join" and "namreply" IRC events
Charly COSTE <changaco@changaco.net>
parents:
47
diff
changeset
|
534 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
|
535 if len(bridges) == 0: |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
536 self.error(event_str, debug=True) |
48
cb08ea878db9
lower() for "join" and "namreply" IRC events
Charly COSTE <changaco@changaco.net>
parents:
47
diff
changeset
|
537 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
|
538 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
|
539 for bridge in 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
|
540 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
|
541 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
|
542 |
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 |
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 # 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
|
545 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
|
546 |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
547 |
88
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
548 if event.eventtype() in ['disconnect', 'kill']: |
70
01f1c6cb7447
Prevent unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents:
64
diff
changeset
|
549 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
|
550 return |
01f1c6cb7447
Prevent unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents:
64
diff
changeset
|
551 |
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
|
552 # 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
|
553 for bridge in self.bridges: |
63
71508f22edb4
Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents:
58
diff
changeset
|
554 if connection.server != bridge.irc_server: |
71508f22edb4
Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents:
58
diff
changeset
|
555 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
|
556 try: |
88
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
557 p = bridge.getParticipant(connection.get_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
|
558 if bridge.mode == 'normal': |
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
|
559 bridge.switchFromNormalToLimitedMode() |
88
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
560 else: |
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
561 if p.irc_connection.really_connected == True: |
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
562 p.irc_connection.part(bridge.irc_room, message=message) |
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
563 p.irc_connection.used_by -= 1 |
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
564 if p.irc_connection.used_by < 1: |
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
565 p.irc_connection.close(message) |
8b071629558e
Handle IRC "kill" event
Charly COSTE <changaco@changaco.net>
parents:
86
diff
changeset
|
566 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
|
567 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
|
568 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
|
569 return |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
570 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
571 |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
572 # Nickname callbacks |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
573 # TODO: move this into irclib.py |
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
574 if event.eventtype() == 'nicknameinuse': |
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
|
575 connection._call_nick_callbacks('nicknameinuse') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
576 return |
64
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
577 if event.eventtype() == 'nickcollision': |
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
578 connection._call_nick_callbacks('nickcollision') |
8fc496eaa17b
Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents:
63
diff
changeset
|
579 return |
58
92341dbfb8b7
Handle bannedfromchan IRC event
Charly COSTE <changaco@changaco.net>
parents:
56
diff
changeset
|
580 if event.eventtype() == 'erroneusnickname': |
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
|
581 connection._call_nick_callbacks('erroneusnickname') |
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
|
582 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
|
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 # 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
|
586 self.error('=> Debug: event not handled', debug=True) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
587 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
588 |
86
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
589 def _send_message_to_admins(self, message): |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
590 """[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
|
591 for admin_jid in self.admins_jid: |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
592 try: |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
593 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
|
594 except: |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
595 pass |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
596 |
bfa32b017fc9
First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents:
79
diff
changeset
|
597 |
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
|
598 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
|
599 """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
|
600 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
|
601 self.bridges.append(b) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
602 return b |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
603 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
604 |
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
|
605 def getBridges(self, irc_room=None, irc_server=None, xmpp_room_jid=None): |
96 | 606 # 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 if xmpp_room_jid != None and bridge.xmpp_room.room_jid != xmpp_room_jid: |
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
|
616 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
|
617 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
|
618 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
|
619 |
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
|
620 |
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
|
621 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
|
622 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
|
623 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
|
624 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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 c.nickname = nickname |
90
965dd6f5fcc3
Tried to improve XMPP disconnections handling
Charly COSTE <changaco@changaco.net>
parents:
88
diff
changeset
|
634 c.mucs = [] |
75 | 635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 c.sendInitPresence() |
24
4e1f27ea527b
First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents:
23
diff
changeset
|
642 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
|
643 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
|
644 |
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 |
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
|
646 def close_xmpp_connection(self, nickname): |
29 | 647 if not self.xmpp_connections.has_key(nickname): |
648 return | |
37 | 649 c = self.xmpp_connections[nickname] |
42
b8c9ddf320f8
Thread safety for bot.close_xmpp_connection().
Charly COSTE <changaco@changaco.net>
parents:
41
diff
changeset
|
650 c.lock.acquire() |
37 | 651 c.used_by -= 1 |
652 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
|
653 self.error('===> Debug: closing XMPP connection for "'+nickname+'"', debug=True) |
37 | 654 self.xmpp_connections.pop(nickname) |
52
5aabf124c78d
Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents:
51
diff
changeset
|
655 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
|
656 c.lock.release() |
37 | 657 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
|
658 else: |
42
b8c9ddf320f8
Thread safety for bot.close_xmpp_connection().
Charly COSTE <changaco@changaco.net>
parents:
41
diff
changeset
|
659 c.lock.release() |
37 | 660 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
|
661 |
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 |
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 def removeBridge(self, bridge): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
664 self.bridges.remove(bridge) |
93
c95fe0b319d9
XMPP kick and ban handling
Charly COSTE <changaco@changaco.net>
parents:
92
diff
changeset
|
665 bridge.__del__() |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
666 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
667 |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
668 def respond(self, message, participant=None): |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
669 ret = '' |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
670 if message.strip() == '!xmpp_participants': |
18
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
671 if participant == None: |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
672 for bridge in self.bridges: |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
673 xmpp_participants_nicknames = bridge.get_participants_nicknames_list(protocols=['xmpp']) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
674 ret += '\nparticipants on '+bridge.xmpp_room.room_jid+': '+' '.join(xmpp_participants_nicknames) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
675 return ret |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
676 else: |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
677 xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
678 return 'participants on '+participant.bridge.xmpp_room.room_jid+': '+' '.join(xmpp_participants_nicknames) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
679 elif message.strip() == '!irc_participants': |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
680 if participant == None: |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
681 for bridge in self.bridges: |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
682 irc_participants_nicknames = bridge.get_participants_nicknames_list(protocols=['irc']) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
683 ret += '\nparticipants on '+bridge.irc_room+' at '+bridge.irc_server+': '+' '.join(irc_participants_nicknames) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
684 return ret |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
685 else: |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
686 irc_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['irc']) |
3cdf7bb580da
Fixed bot.respond(), boosted XMPP thread to lower latency, fixed mode notice.
Charly COSTE <changaco@changaco.net>
parents:
17
diff
changeset
|
687 return 'participants on '+participant.bridge.irc_room+' at '+participant.bridge.irc_server+': '+' '.join(irc_participants_nicknames) |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
688 else: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
689 return 'commands: '+' '.join(self.commands) |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
690 |
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
|
691 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
692 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
|
693 for bridge in self.bridges: |
52
5aabf124c78d
Fixed XMPP connection closing and the XMPP loop
Charly COSTE <changaco@changaco.net>
parents:
51
diff
changeset
|
694 self.removeBridge(bridge) |