mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-09 11:04:08 +01:00
matchHost: extend negation via "!" to regular hostmasks as well as exttargets
This commit is contained in:
parent
d51c399351
commit
5d629f7331
27
classes.py
27
classes.py
@ -1162,14 +1162,24 @@ class Irc(utils.DeprecatedAttributesObject):
|
||||
# Try to convert target into a UID. If this fails, it's probably a hostname.
|
||||
target = self.nickToUid(target) or target
|
||||
|
||||
# Allow queries like !$exttarget to invert the given match.
|
||||
invert = glob.startswith('!')
|
||||
if invert:
|
||||
glob = glob.lstrip('!')
|
||||
|
||||
def match_host_core():
|
||||
"""
|
||||
Core processor for matchHost(), minus the inversion check.
|
||||
"""
|
||||
# Work with variables in the matchHost() scope, from
|
||||
# http://stackoverflow.com/a/8178808
|
||||
nonlocal glob
|
||||
|
||||
# Prepare a list of hosts to check against.
|
||||
if target in self.users:
|
||||
if glob.startswith(('$', '!$')):
|
||||
# !$exttarget inverts the given match.
|
||||
invert = glob.startswith('!$')
|
||||
|
||||
if glob.startswith('$'):
|
||||
# Exttargets start with $. Skip regular ban matching and find the matching ban handler.
|
||||
glob = glob.lstrip('$!')
|
||||
glob = glob.lstrip('$')
|
||||
exttargetname = glob.split(':', 1)[0]
|
||||
handler = world.exttarget_handlers.get(exttargetname)
|
||||
|
||||
@ -1178,8 +1188,6 @@ class Irc(utils.DeprecatedAttributesObject):
|
||||
result = handler(self, glob, target)
|
||||
log.debug('(%s) Got %s from exttarget %s in matchHost() glob $%s for target %s',
|
||||
self.name, result, exttargetname, glob, target)
|
||||
if invert: # Anti-exttarget was specified.
|
||||
result = not result
|
||||
return result
|
||||
else:
|
||||
log.debug('(%s) Unknown exttarget %s in matchHost() glob $%s', self.name,
|
||||
@ -1222,6 +1230,11 @@ class Irc(utils.DeprecatedAttributesObject):
|
||||
|
||||
return False
|
||||
|
||||
result = match_host_core()
|
||||
if invert:
|
||||
result = not result
|
||||
return result
|
||||
|
||||
class IrcUser():
|
||||
"""PyLink IRC user class."""
|
||||
def __init__(self, nick, ts, uid, server, ident='null', host='null',
|
||||
|
Loading…
Reference in New Issue
Block a user