mirror of
https://github.com/jlu5/PyLink.git
synced 2025-05-06 14:47:25 +02:00
exttargets: add $and exttarget (#334)
This commit is contained in:
parent
dbeacf9249
commit
1358fedca6
@ -21,7 +21,7 @@ def account(irc, host, uid):
|
|||||||
|
|
||||||
$account -> Returns True (a match) if the target is registered.
|
$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
|
$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
|
$account:accountname:netname -> Returns True if both the target's account name and origin
|
||||||
network name match the ones given.
|
network name match the ones given.
|
||||||
$account:*:netname -> Matches all logged in users on the given network.
|
$account:*:netname -> Matches all logged in users on the given network.
|
||||||
@ -166,3 +166,27 @@ def network(irc, host, uid):
|
|||||||
homenet = irc.name
|
homenet = irc.name
|
||||||
|
|
||||||
return homenet == targetnet
|
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
|
||||||
|
@ -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).
|
- `$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).
|
- `$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
|
## Permissions
|
||||||
|
|
||||||
See the [Permissions Reference](permissions-reference.md#automode) for a list of permissions defined by Automode.
|
See the [Permissions Reference](permissions-reference.md#automode) for a list of permissions defined by Automode.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user