Fix IRC flood issues
Tweaked version of suggestions from Valesi, petrkr, and bauerj. Fixes #93
This commit is contained in:
parent
5cbe878cb8
commit
517f78858c
@ -76,9 +76,9 @@ class IRC(LoggedClass):
|
|||||||
irc_client.ServerConnection.buffer_class = \
|
irc_client.ServerConnection.buffer_class = \
|
||||||
buffer.LenientDecodingLineBuffer
|
buffer.LenientDecodingLineBuffer
|
||||||
|
|
||||||
|
# Register handlers for events we're interested in
|
||||||
reactor = irc_client.Reactor()
|
reactor = irc_client.Reactor()
|
||||||
for event in ['welcome', 'join', 'quit', 'kick', 'whoreply',
|
for event in 'welcome join quit kick whoreply disconnect'.split():
|
||||||
'namreply', 'disconnect']:
|
|
||||||
reactor.add_global_handler(event, getattr(self, 'on_' + event))
|
reactor.add_global_handler(event, getattr(self, 'on_' + event))
|
||||||
|
|
||||||
# Note: Multiple nicks in same channel will trigger duplicate events
|
# Note: Multiple nicks in same channel will trigger duplicate events
|
||||||
@ -117,6 +117,12 @@ class IRC(LoggedClass):
|
|||||||
|
|
||||||
def on_join(self, connection, event):
|
def on_join(self, connection, event):
|
||||||
'''Called when someone new connects to our channel, including us.'''
|
'''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)
|
match = self.peer_regexp.match(event.source)
|
||||||
if match:
|
if match:
|
||||||
connection.who(match.group(1))
|
connection.who(match.group(1))
|
||||||
@ -134,16 +140,6 @@ class IRC(LoggedClass):
|
|||||||
if match:
|
if match:
|
||||||
self.peers.pop(match.group(1), None)
|
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):
|
def on_whoreply(self, connection, event):
|
||||||
'''Called when a response to our who requests arrives.
|
'''Called when a response to our who requests arrives.
|
||||||
|
|
||||||
@ -152,6 +148,7 @@ class IRC(LoggedClass):
|
|||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
nick = event.arguments[4]
|
nick = event.arguments[4]
|
||||||
|
if nick.startswith(self.prefix):
|
||||||
line = event.arguments[6].split()
|
line = event.arguments[6].split()
|
||||||
try:
|
try:
|
||||||
ip_addr = socket.gethostbyname(line[1])
|
ip_addr = socket.gethostbyname(line[1])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user