Mercurial > xib
annotate bot.py @ 17:32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Thu, 20 Aug 2009 01:00:54 +0200 |
parents | 1a1f2a0d35c7 |
children | 3cdf7bb580da |
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 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
26 import xmppony as xmpp |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
27 from threading import Thread |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 from bridge import * |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
29 from time import sleep |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
30 import re |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
31 import sys |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
32 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
33 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
34 class bot(Thread): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
35 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
36 def __init__(self, jid, password, nickname, error_fd=sys.stderr, debug=False): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 Thread.__init__(self) |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
38 self.commands = ['!xmpp_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
|
39 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
|
40 self.bare_jid.setResource('') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
41 self.jid = xmpp.protocol.JID(jid=jid) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
42 self.nickname = 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
|
43 self.jid.setResource(self.nickname) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
44 self.password = password |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
45 self.error_fd = error_fd |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
46 self.debug = debug |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
47 self.bridges = [] |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
48 self.xmpp_connections = {} |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
49 self.irc = irclib.IRC() |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
50 self.irc.bot = self |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
51 self.irc.add_global_handler('all_events', self._irc_event_handler) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
52 self.irc_thread = Thread(target=self.irc.process_forever) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
53 self.irc_thread.start() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
54 # Open connection with XMPP server |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
55 try: |
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
|
56 self.xmpp_c = self.get_xmpp_connection(self.jid.getResource()) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
57 except: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
58 self.error('Error: XMPP Connection failed') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
59 raise |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
60 self.xmpp_thread = Thread(target=self._xmpp_loop) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
61 self.xmpp_thread.start() |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
62 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
63 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
64 def error(self, s, debug=False): |
17
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
65 """Output an error message.""" |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
66 if not debug or debug and self.debug: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
67 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
68 self.error_fd.write(auto_encode(s)+"\n") |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
69 except EncodingException: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
70 self.error_fd.write('Error message cannot be transcoded.\n') |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
71 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
72 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
73 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
|
74 """[Internal] XMPP infinite loop.""" |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
75 while True: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 self.xmpp_c.Process(5) |
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
|
77 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
|
78 for c in self.xmpp_connections.itervalues(): |
32a35f7eff70
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 if hasattr(c, 'Process'): |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
80 c.Process(5) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
81 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
|
82 sleep(1) |
32a35f7eff70
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 except RuntimeError: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
84 pass |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
85 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
86 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
87 def _xmpp_presence_handler(self, xmpp_c, presence): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
88 """[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
|
89 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
90 if presence.getTo() != self.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
|
91 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
|
92 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
|
93 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
94 self.error('==> Debug: Received XMPP presence.', debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
95 self.error(presence.__str__(fancy=1), debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
96 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
97 from_ = xmpp.protocol.JID(presence.getFrom()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
98 bare_jid = unicode(from_.getNode()+'@'+from_.getDomain()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
99 for bridge in self.bridges: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
100 if bare_jid == bridge.xmpp_room.room_jid: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
101 # presence comes from a muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
102 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
|
103 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
104 if resource == '': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
105 # presence comes from the muc itself |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
106 # TODO: handle room deletion and muc server reboot |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
107 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
|
108 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
109 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
110 # presence comes from a participant of the muc |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
111 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
112 p = bridge.getParticipant(resource) |
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
|
113 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
114 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
|
115 if presence.getType() != 'unavailable' and resource != bridge.bot.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
|
116 bridge.addParticipant('xmpp', resource) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
117 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
|
118 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
119 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
120 if p.protocol == 'xmpp' and presence.getType() == 'unavailable': |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
121 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
122 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
|
123 # participant changed its 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
|
124 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
|
125 if not 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
|
126 self.error('Debug: bad stanza, no item element', 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
|
127 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
|
128 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
|
129 if not new_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
|
130 self.error('Debug: bad stanza, new nick is not given', 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
|
131 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
|
132 p.changeNickname(new_nick, 'irc') |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
133 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
134 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
|
135 # participant left |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
136 bridge.removeParticipant('xmpp', resource, presence.getStatus()) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
137 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
138 return |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
139 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
140 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
141 def _xmpp_iq_handler(self, xmpp_c, iq): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
142 """[Internal] Manage XMPP IQs.""" |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
143 self.error('=> Debug: Received XMPP iq.', debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
144 self.error(iq.__str__(fancy=1), debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
145 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
146 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
147 def _xmpp_message_handler(self, xmpp_c, message): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
148 """[Internal] Manage XMPP messages.""" |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
149 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
|
150 self.error('==> Debug: Received XMPP chat message.', debug=True) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
151 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
|
152 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
|
153 for bridge in self.bridges: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
154 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
|
155 # 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
|
156 |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
157 try: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
158 from_ = bridge.getParticipant(message.getFrom().getResource()) |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
159 to_ = bridge.getParticipant(message.getTo().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
|
160 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
161 if from_.protocol == 'xmpp': |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
162 from_.sayOnIRCTo(to_.nickname, message.getBody()) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
163 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
|
164 self.error('==> Debug: received XMPP chat message from a non-XMPP participant, WTF ?', 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
|
165 |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
166 except NoSuchParticipantException: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
167 if message.getTo() == self.jid: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
168 xmpp_c.send(xmpp.protocol.Message(to=message.getFrom(), body=self.respond(message.getBody(), from_), typ='chat')) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
169 return |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
170 self.error('==> Debug: XMPP chat message not relayed, from_bare_jid='+from_bare_jid+' to='+str(message.getTo().getResource())+' from='+message.getFrom().getResource(), debug=True) |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
171 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
172 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
173 elif message.getType() == 'groupchat': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
174 # 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
|
175 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
176 for child in message.getChildren(): |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
177 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
|
178 # MUC delayed message |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
179 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
|
180 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
181 if message.getTo() != self.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
|
182 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
|
183 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
|
184 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
185 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
186 from_ = xmpp.protocol.JID(message.getFrom()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
187 room_jid = unicode(from_.getNode()+'@'+from_.getDomain()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
188 for bridge in self.bridges: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
189 if room_jid == bridge.xmpp_room.room_jid: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
190 resource = unicode(from_.getResource()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
191 if resource == '': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
192 # 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
|
193 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
|
194 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
195 else: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
196 # 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
|
197 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
|
198 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
|
199 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
200 try: |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
201 participant_ = bridge.getParticipant(resource) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
202 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
|
203 if resource != 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
|
204 self.error('=> Debug: NoSuchParticipantException "'+resource+'", WTF ?', debug=True) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
205 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
|
206 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
207 if participant_.protocol == 'xmpp': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
208 participant_.sayOnIRC(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
|
209 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
210 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
|
211 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
|
212 self.error(message.__str__(fancy=1), debug=True) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
213 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
214 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
215 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
|
216 """[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
|
217 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
218 # Answer ping |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
219 if event.eventtype() == 'ping': |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
220 connection.pong(connection.get_server_name()) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
221 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
|
222 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
223 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
224 # 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
|
225 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
|
226 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
|
227 if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes']: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
228 self.error('=> Debug: ignoring '+event.eventtype(), 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
|
229 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
|
230 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
231 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
232 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
|
233 if '!' in event.source(): |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
234 nickname = event.source().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
|
235 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
236 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
237 # 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
249 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
250 # A string representation of the event |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
251 event_str = '==> Debug: Received IRC event.\nconnection='+str(connection)+'\neventtype='+event.eventtype()+'\nsource='+str(event.source())+'\ntarget='+str(event.target())+'\narguments='+str(event.arguments()) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
252 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
253 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
254 if event.eventtype() in ['pubmsg', 'privmsg', 'quit', 'part', '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
|
255 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
|
256 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
|
257 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
258 # 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
|
259 for bridge in self.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
|
260 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
|
261 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
|
262 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
263 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
|
264 self.error('===> Debug: NoSuchParticipantException "'+nickname+'" in bridge "'+str(bridge)+'"', 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
|
265 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
|
266 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
267 |
32a35f7eff70
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 # 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
|
269 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
|
270 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
|
271 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
|
272 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
279 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
|
280 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
|
281 # 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
|
282 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
|
283 connection.privmsg(from_.nickname, self.respond(event.arguments()[0], from_)) |
32a35f7eff70
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 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
|
285 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
|
286 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
|
287 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
288 |
32a35f7eff70
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 # From here we skip if the event was not received on bot connection |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
290 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
|
291 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
|
292 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
|
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 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
|
295 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
296 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
297 # Leaving 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
|
298 if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target() == bridge.irc_room: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
299 if from_.protocol == 'irc': |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
300 bridge.removeParticipant('irc', from_.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
|
301 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
|
302 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
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
|
304 # Nickname change |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
305 if event.eventtype() == 'nick' and from_.protocol == 'irc': |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
306 from_.changeNickname(event.target(), 'xmpp') |
32a35f7eff70
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 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
|
308 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
309 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
310 # Chan 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
|
311 if event.eventtype() == 'pubmsg': |
32a35f7eff70
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 if bridge.irc_room == event.target() and bridge.irc_server == connection.server: |
32a35f7eff70
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 if from_.protocol != 'xmpp': |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
314 from_.sayOnXMPP(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
|
315 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
|
316 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
|
317 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
|
318 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
319 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
|
320 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
321 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
327 if event.eventtype() == 'namreply': |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
328 # 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
|
329 for bridge in self.getBridges(irc_room=event.arguments()[1], irc_server=connection.server): |
32a35f7eff70
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 for nickname in re.split('(?:^[@\+]?|(?: [@\+]?)*)', event.arguments()[2].strip()): |
32a35f7eff70
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 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
|
332 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
|
333 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
|
334 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
|
335 elif event.eventtype() == '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
|
336 bridges = self.getBridges(irc_room=event.target(), irc_server=connection.server) |
32a35f7eff70
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 if len(bridges) == 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
|
338 self.error('===> Debug: no bridge found for "'+event.target()+' at '+connection.server+'"', 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 |
32a35f7eff70
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 # 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
|
346 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
|
347 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
348 if event.eventtype() == 'disconnect': |
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
|
349 # 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
|
350 for bridge in self.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
|
351 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
|
352 bridge.getParticipant(connection.get_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
|
353 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
|
354 bridge.switchFromNormalToLimitedMode() |
32a35f7eff70
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 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
|
356 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
|
357 return |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
358 elif 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
|
359 connection._call_nick_callbacks('nicknameinuse') |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
360 return |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
361 elif 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
|
362 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
|
363 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
|
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 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
366 # 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
|
367 self.error('=> Debug: event not handled', debug=True) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
368 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
369 |
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 def new_bridge(self, xmpp_room, irc_room, irc_server, mode, say_participants_list, irc_port=6667): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
371 """Create a bridge between xmpp_room and irc_room at irc_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
|
372 b = bridge(self, xmpp_room, irc_room, irc_server, mode, say_participants_list, irc_port=irc_port) |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
373 self.bridges.append(b) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
374 return b |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
375 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
376 |
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
|
377 def getBridges(self, irc_room=None, irc_server=None, xmpp_room_jid=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
|
378 bridges = [b for b in self.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
|
379 if irc_room != 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
|
380 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
|
381 if bridge.irc_room != irc_room: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
382 if 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
|
383 bridges.remove(bridge) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
384 if irc_server != 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
|
385 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
|
386 if bridge.irc_server != irc_server: |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
387 if 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
|
388 bridges.remove(bridge) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
389 if xmpp_room_jid != 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
|
390 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
|
391 if bridge.xmpp_room.room_jid != xmpp_room_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
|
392 if 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
|
393 bridges.remove(bridge) |
32a35f7eff70
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 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
|
395 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
396 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
397 def get_xmpp_connection(self, resource): |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
398 if self.xmpp_connections.has_key(resource): |
32a35f7eff70
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 c = self.xmpp_connections[resource] |
32a35f7eff70
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 c.used_by += 1 |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
401 self.error('===> Debug: using existing XMPP connection for "'+str(self.bare_jid)+'/'+resource+'", now used by '+str(c.used_by)+' bridges', debug=True) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
402 return 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
|
403 self.error('===> Debug: opening new XMPP connection for "'+str(self.bare_jid)+'/'+resource+'"', 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
|
404 c = xmpp.client.Client(self.jid.getDomain(), debug=[]) |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
405 self.xmpp_connections[resource] = 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
|
406 c.used_by = 1 |
32a35f7eff70
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 c.connect() |
32a35f7eff70
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 c.auth(self.jid.getNode(), self.password, resource=resource) |
32a35f7eff70
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 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
|
410 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
|
411 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
|
412 c.sendInitPresence() |
32a35f7eff70
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 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
|
414 |
32a35f7eff70
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 |
32a35f7eff70
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 def close_xmpp_connection(self, resource): |
32a35f7eff70
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 self.xmpp_connections[resource].used_by -= 1 |
32a35f7eff70
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 self.xmpp_connections[resource].used_by < 1: |
32a35f7eff70
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 self.error('===> Debug: closing XMPP connection for "'+str(self.bare_jid)+'/'+resource+'"', 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
|
420 del self.xmpp_connections[resource] |
32a35f7eff70
Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents:
14
diff
changeset
|
421 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
|
422 self.error('===> Debug: XMPP connection for "'+str(self.bare_jid)+'/'+resource+'" is now used by '+str(self.xmpp_connections[resource].used_by)+' bridges', 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
|
423 |
32a35f7eff70
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 |
32a35f7eff70
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 def removeBridge(self, bridge): |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
426 self.bridges.remove(bridge) |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
427 del bridge |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
428 |
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
429 |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
430 def respond(self, message, participant): |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
431 if message.strip() == '!xmpp_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
|
432 xmpp_participants_nicknames = participant.bridge.get_participants_nicknames_list(protocols=['xmpp']) |
11
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
433 return 'participants on '+participant.bridge.xmpp_room.room_jid+': '+' '.join(xmpp_participants_nicknames) |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
434 else: |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
435 return 'commands: '+' '.join(self.commands) |
79b0a7f48a3e
Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents:
10
diff
changeset
|
436 |
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
|
437 |
0
4c842d23d4ce
Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
438 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
|
439 for bridge in self.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
|
440 self.removeBridge(bridge) |