annotate bot.py @ 14:1a1f2a0d35c7

Fixed bug that prevented the bot from connecting to freenode and all other servers that don't send "umode" Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 17 Aug 2009 13:20:25 +0200
parents 79b0a7f48a3e
children 32a35f7eff70
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 #!/usr/bin/env python
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4 # This program is free software: you can redistribute it and/or modify
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # the Free Software Foundation, either version 3 of the License, or
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 # (at your option) any later version.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 # GNU General Public License for more details.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18 # *** 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']
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 self.jid = xmpp.protocol.JID(jid=jid)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
40 self.nickname = nickname
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
41 self.password = password
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42 self.error_fd = error_fd
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43 self.debug = debug
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
44 self.bridges = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 self.irc = irclib.IRC()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
46 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
47 self.irc_thread = Thread(target=self.irc.process_forever)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
48 self.irc_thread.start()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
49 # Open connection with XMPP server
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
50 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
51 self.xmpp_c = xmpp.client.Client(self.jid.getDomain(), debug=[])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
52 self.xmpp_c.connect()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
53 if self.jid.getResource() == '':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
54 self.jid.setResource('xib-bot')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
55 self.xmpp_c.auth(self.jid.getNode(), password, resource=self.jid.getResource())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
56 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
57 self.xmpp_c.RegisterHandler('iq', self._xmpp_iq_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
58 self.xmpp_c.RegisterHandler('message', self._xmpp_message_handler)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
59 self.xmpp_c.sendInitPresence()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
60 except:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
61 self.error('Error: XMPP Connection failed')
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
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
67 def error(self, s, debug=False):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
68 if not debug or debug and self.debug:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
69 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
70 self.error_fd.write(auto_encode(s)+"\n")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
71 except EncodingException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
72 self.error_fd.write('Error message cannot be transcoded.\n')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
73
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
74
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
75 def _xmpp_loop(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
76 while True:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
77 self.xmpp_c.Process(5)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
78
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
79
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
80 def _xmpp_presence_handler(self, xmpp_c, presence):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
81 """[Internal] Manage XMPP presence."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
82 self.error('==> Debug: Received XMPP presence.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
83 self.error(presence.__str__(fancy=1), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
84
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
85 if presence.getTo() != self.jid:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
86 #self.error('=> Debug: Skipping XMPP presence not received on bot connection.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
87 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
88 from_ = xmpp.protocol.JID(presence.getFrom())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
89 bare_jid = unicode(from_.getNode()+'@'+from_.getDomain())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
90 for bridge in self.bridges:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
91 if bare_jid == bridge.xmpp_room.room_jid:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
92 # presence comes from a muc
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
93 resource = unicode(from_.getResource())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
94 if resource == '':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
95 # presence comes from the muc itself
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
96 # TODO: handle room deletion and muc server reboot
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
97 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
98 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
99 # presence comes from a participant of the muc
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
100 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
101 p = bridge.getParticipant(resource)
3
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
102 if p.protocol in ['xmpp', 'both']:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
103 if presence.getType() == 'unavailable':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
104 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
105 if x and x.getTag('status', attrs={'code': '303'}):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
106 # participant changed its nickname
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
107 item = x.getTag('item')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
108 if not item:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
109 self.error('Debug: bad stanza, no item element', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
110 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
111 new_nick = item.getAttr('nick')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
112 if not new_nick:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
113 self.error('Debug: bad stanza, new nick is not given', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
114 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
115 p.changeNickname(new_nick, 'irc')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
116 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
117 # participant left
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
118 bridge.removeParticipant('xmpp', resource, presence.getStatus())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
119 except NoSuchParticipantException:
3
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
120 if presence.getType() != 'unavailable':
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
121 try:
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
122 bridge.addParticipant('xmpp', resource)
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
123 except Exception:
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
124 pass
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
125 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
126
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
127
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
128 def _xmpp_iq_handler(self, xmpp_c, iq):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
129 """[Internal] Manage XMPP IQs."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
130 self.error('=> Debug: Received XMPP iq.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
131 self.error(iq.__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
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
134 def _xmpp_message_handler(self, xmpp_c, message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
135 """[Internal] Manage XMPP messages."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
136 if message.getType() == 'chat':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
137 self.error('==> Debug: Received XMPP message.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
138 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
139 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
140 for bridge in self.bridges:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
141 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
142 # message comes from a room participant
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
143 try:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
144 from_ = bridge.getParticipant(message.getFrom().getResource())
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
145 to_ = bridge.getParticipant(message.getTo().getResource())
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
146 except NoSuchParticipantException:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
147 if message.getTo() == self.jid:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
148 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
149 return
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
150 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
151 return
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
152 if from_.protocol in ['xmpp', 'both']:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
153 from_.sayOnIRCTo(to_.nickname, message.getBody())
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
154 else:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
155 self.error('==> Debug: received XMPP chat message from a non-XMPP participant, WTF ?', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
156
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
157 elif message.getType() == 'groupchat':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
158 # message comes from a room
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
159 if message.getTo() != self.jid:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
160 self.error('=> Debug: Skipping XMPP MUC message not received on bot connection.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
161 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
162 for child in message.getChildren():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
163 if child.getName() == 'delay':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
164 self.error('=> Debug: Skipping XMPP MUC delayed message.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
165 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
166 self.error('==> Debug: Received XMPP message.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
167 self.error(message.__str__(fancy=1), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
168 from_ = xmpp.protocol.JID(message.getFrom())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
169 room_jid = unicode(from_.getNode()+'@'+from_.getDomain())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
170 for bridge in self.bridges:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
171 if room_jid == bridge.xmpp_room.room_jid:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
172 resource = unicode(from_.getResource())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
173 if resource == '':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
174 # message comes from the room itself
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
175 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
176 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
177 # message comes from a participant of the room
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
178 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
179 participant_ = bridge.getParticipant(resource)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
180 except NoSuchParticipantException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
181 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
182 if participant_.protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
183 participant_.sayOnIRC(message.getBody())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
184 elif participant_.protocol == 'both':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
185 bridge.irc_connection.privmsg(bridge.irc_room, '<'+participant_.nickname+'> '+message.getBody())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
186 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
187 self.error('==> Debug: Received XMPP message.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
188 self.error(message.__str__(fancy=1), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
189
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
190
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
191 def _irc_event_handler(self, connection, event):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
192 """[internal] Manage IRC events"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
193 if not connection.bridge in self.bridges:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
194 # Not for us, ignore
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
195 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
196 if 'all' in event.eventtype():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
197 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
198 if 'motd' in event.eventtype():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
199 self.error('=> Debug: ignoring event containing "motd" in the eventtype ('+event.eventtype()+')', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
200 return
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
201 if event.eventtype() in ['pong', 'privnotice']:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
202 self.error('=> Debug: ignoring '+event.eventtype(), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
203 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
204 if event.eventtype() == 'pubmsg' and connection.get_nickname() != connection.bridge.irc_connection.get_nickname():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
205 self.error('=> Debug: ignoring IRC pubmsg not received on bridge connection', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
206 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
207 if event.eventtype() == 'ping':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
208 connection.pong(connection.get_server_name())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
209 return
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
210 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
211 if connection.really_connected == False:
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
212 connection.really_connected = 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
213 self.error('===> Debug: now really connected', 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
214 if connection.nick_callback:
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
215 connection.nick_callback(None)
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
216 else:
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
217 self.error('=> Debug: no nick callback for "'+str(event.target())+'"', 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
218 self.error('connection.nick_callback='+str(connection.nick_callback), 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
219 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
220 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
221 self.error('==> Debug: Received IRC event.', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
222 self.error('server='+connection.get_server_name(), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
223 self.error('eventtype='+event.eventtype(), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
224 self.error('source='+str(event.source()), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
225 self.error('target='+str(event.target()), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
226 self.error('arguments='+str(event.arguments()), debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
227 if event.eventtype() == 'disconnect':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
228 if connection.get_nickname() == connection.bridge.irc_connection.get_nickname():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
229 # Lost bridge IRC connection, we must reconnect if we want the bridge to work
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
230 self.recreate_bridge(connection.bridge)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
231 return
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
232 if connection.bridge.mode == 'normal' and connection.closing == False:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
233 connection.bridge.switchToLimitedMode()
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
234 if connection.closing == True:
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
235 connection.close()
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
236 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
237 elif event.eventtype() == 'nicknameinuse':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
238 if connection.nick_callback:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
239 connection.nick_callback('nicknameinuse')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
240 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
241 self.error('=> Debug: no nick callback for "'+str(event.target())+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
242 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
243 elif event.eventtype() == 'erroneusnickname':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
244 if connection.nick_callback:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
245 connection.nick_callback('erroneusnickname')
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
246 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
247 self.error('=> Debug: no nick callback for "'+str(event.target())+'"', debug=True)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
248 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
249 elif event.eventtype() == 'namreply':
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
250 for nickname in re.split('(?:^[@\+]?|(?: [@\+]?)*)', event.arguments()[2].strip()):
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
251 if nickname == '':
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
252 continue
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
253 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
254 connection.bridge.addParticipant('irc', nickname)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
255 except:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
256 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
257 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
258 elif event.eventtype() == 'join':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
259 nickname = event.source().split('!')[0]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
260 if nickname == self.nickname:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
261 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
262 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
263 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
264 connection.bridge.getParticipant(nickname)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
265 except NoSuchParticipantException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
266 connection.bridge.addParticipant('irc', nickname)
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
267 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
268 try:
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
269 if event.source() == None or not '!' in event.source():
10
7cb790f5f243 No comment.
Charly COSTE <changaco@changaco.net>
parents: 5
diff changeset
270 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
271 from_ = connection.bridge.getParticipant(event.source().split('!')[0])
3
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
272 if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target() == connection.bridge.irc_room:
3f651f4fdb4f Added IRC "part" event handling
Charly COSTE <changaco@changaco.net>
parents: 2
diff changeset
273 if from_.protocol in ['irc', 'both']:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
274 connection.bridge.removeParticipant('irc', from_.nickname, event.arguments()[0])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
275 return
10
7cb790f5f243 No comment.
Charly COSTE <changaco@changaco.net>
parents: 5
diff changeset
276 if event.eventtype() == 'nick' and from_.protocol in ['irc', 'both']:
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
277 from_.changeNickname(event.target(), 'xmpp')
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
278 except NoSuchParticipantException:
10
7cb790f5f243 No comment.
Charly COSTE <changaco@changaco.net>
parents: 5
diff changeset
279 self.error('===> Debug: NoSuchParticipantException "'+event.source().split('!')[0]+'"', debug=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
280 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
281 if event.eventtype() == 'pubmsg':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
282 if from_.protocol == 'irc' or from_.protocol == 'both':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
283 from_.sayOnXMPP(event.arguments()[0])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
284 elif event.eventtype() == 'privmsg':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
285 if event.target() == None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
286 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
287 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
288 to_ = connection.bridge.getParticipant(event.target().split('!')[0])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
289 except NoSuchParticipantException:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
290 if event.target().split('!')[0] == self.nickname:
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
291 connection.privmsg(from_.nickname, self.respond(event.arguments()[0], from_))
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
292 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
293 if to_.protocol == 'xmpp':
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
294 from_.sayOnXMPPTo(to_.nickname, event.arguments()[0])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
295
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
296
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
297 def new_bridge(self, xmpp_room, irc_room, irc_server, irc_port=6667):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
298 """Create a bridge between xmpp_room and irc_room at irc_server."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
299 b = bridge(self, xmpp_room, irc_room, irc_server, irc_port=irc_port)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
300 self.bridges.append(b)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
301 return b
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
302
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
303
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
304 def recreate_bridge(self, bridge):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
305 """Disconnect and reconnect."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
306 self.new_bridge(bridge.xmpp_room.room_jid, bridge.irc_room, bridge.irc_server)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
307 self.bridges.remove(bridge)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
308 del bridge
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
309
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
310
11
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
311 def respond(self, message, participant):
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
312 if message.strip() == '!xmpp_participants':
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
313 xmpp_participants_nicknames = participant.bridge.get_xmpp_participants_nicknames_list()
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
314 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
315 else:
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
316 return 'commands: '+' '.join(self.commands)
79b0a7f48a3e Introduced the command mechanism and fixed a bug
Charly COSTE <changaco@changaco.net>
parents: 10
diff changeset
317
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
318 def __del__(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
319 for bridge in bridges:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
320 del bridge