3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-11 20:52:42 +01:00

exttargets: add $and exttarget (#334)

This commit is contained in:
James Lu 2017-05-04 17:59:50 -07:00
parent dbeacf9249
commit 1358fedca6
2 changed files with 33 additions and 1 deletions

View File

@ -21,7 +21,7 @@ def account(irc, host, uid):
$account -> Returns True (a match) if the target is registered.
$account:accountname -> Returns True if the target's account name matches the one given, and the
target is connected to the local network..
target is connected to the local network.
$account:accountname:netname -> Returns True if both the target's account name and origin
network name match the ones given.
$account:*:netname -> Matches all logged in users on the given network.
@ -166,3 +166,27 @@ def network(irc, host, uid):
homenet = irc.name
return homenet == targetnet
# Note: "and" can't be a function name so we use this.
def exttarget_and(irc, host, uid):
"""
$and exttarget handler. This exttarget takes a series of exttargets (or hostmasks) joined with
a "+", and returns True if all sub exttargets match.
Examples:
$and:($ircop:*admin*+$network:ovd) -> Matches all opers on the network ovd.
$and:($account+$pylinkirc) -> Matches all users logged in to both services and PyLink.
$and:(*!*@localhost+$ircop) -> Matches all opers with the host `localhost`.
$and:(*!*@*.mibbit.com+!$ircop+!$account) -> Matches all mibbit users that aren't opered or logged in to services.
"""
targets = host.split(':', 1)[-1]
# For readability, this requires that the exttarget list be wrapped in brackets.
if not (targets.startswith('(') and targets.endswith(')')):
return False
targets = targets[1:-1]
targets = list(filter(None, targets.split('+')))
log.debug('exttargets_and: using raw subtargets list %r (original query=%r)', targets, host)
# Wrap every subtarget into irc.matchHost and return True if all subtargets return True.
return all(map(lambda sub_exttarget: irc.matchHost(sub_exttarget, uid), targets))
world.exttarget_handlers['and'] = exttarget_and

View File

@ -44,6 +44,14 @@ Extended targets or exttargets *replace* regular hostmasks with conditional matc
- `$pylinkacc:accountname` -> Returns True if the target's PyLink login matches the one given (case insensitive).
- `$network:netname` -> Returns True if the target user originates from the given network (this supports and looks up the home network of Relay users).
### The "$and" target
The `$and` target is slightly more complex. Examples:
- `$and:($ircop:*admin*+$network:ovd)` -> Matches all opers on the network ovd.
- `$and:($account+$pylinkirc)` -> Matches all users logged in to both services and PyLink.
- `$and:(*!*@localhost+$ircop)` -> Matches all opers with the host `localhost`.
- `$and:(*!*@*.mibbit.com+!$ircop+!$account)` -> Matches all mibbit users that aren't opered or logged in to services.
## Permissions
See the [Permissions Reference](permissions-reference.md#automode) for a list of permissions defined by Automode.