|
|
@ -76,9 +76,9 @@ class IRC(LoggedClass): |
|
|
|
irc_client.ServerConnection.buffer_class = \ |
|
|
|
buffer.LenientDecodingLineBuffer |
|
|
|
|
|
|
|
# Register handlers for events we're interested in |
|
|
|
reactor = irc_client.Reactor() |
|
|
|
for event in ['welcome', 'join', 'quit', 'kick', 'whoreply', |
|
|
|
'namreply', 'disconnect']: |
|
|
|
for event in 'welcome join quit kick whoreply disconnect'.split(): |
|
|
|
reactor.add_global_handler(event, getattr(self, 'on_' + event)) |
|
|
|
|
|
|
|
# Note: Multiple nicks in same channel will trigger duplicate events |
|
|
@ -117,6 +117,12 @@ class IRC(LoggedClass): |
|
|
|
|
|
|
|
def on_join(self, connection, event): |
|
|
|
'''Called when someone new connects to our channel, including us.''' |
|
|
|
# /who the channel when we join. We used to /who on each |
|
|
|
# namreply event, but the IRC server would frequently kick us |
|
|
|
# for flooding. This requests only once including the tor case. |
|
|
|
if event.source.startswith(self.nick + '!'): |
|
|
|
connection.who(self.channel) |
|
|
|
else: |
|
|
|
match = self.peer_regexp.match(event.source) |
|
|
|
if match: |
|
|
|
connection.who(match.group(1)) |
|
|
@ -134,16 +140,6 @@ class IRC(LoggedClass): |
|
|
|
if match: |
|
|
|
self.peers.pop(match.group(1), None) |
|
|
|
|
|
|
|
def on_namreply(self, connection, event): |
|
|
|
'''Called repeatedly when we first connect to inform us of all users |
|
|
|
in the channel. |
|
|
|
|
|
|
|
The users are space-separated in the 2nd argument. |
|
|
|
''' |
|
|
|
for peer in event.arguments[2].split(): |
|
|
|
if peer.startswith(self.prefix): |
|
|
|
connection.who(peer) |
|
|
|
|
|
|
|
def on_whoreply(self, connection, event): |
|
|
|
'''Called when a response to our who requests arrives. |
|
|
|
|
|
|
@ -152,6 +148,7 @@ class IRC(LoggedClass): |
|
|
|
''' |
|
|
|
try: |
|
|
|
nick = event.arguments[4] |
|
|
|
if nick.startswith(self.prefix): |
|
|
|
line = event.arguments[6].split() |
|
|
|
try: |
|
|
|
ip_addr = socket.gethostbyname(line[1]) |
|
|
|