From 7dda8ebe58164c8b3caceeb503a22700b9489969 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 7 Jul 2016 11:11:31 -0700 Subject: [PATCH] exttargets: add $ircop matcher (#170) --- coremods/exttargets.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/coremods/exttargets.py b/coremods/exttargets.py index 4c6a4ae..59c4ddf 100644 --- a/coremods/exttargets.py +++ b/coremods/exttargets.py @@ -58,3 +58,23 @@ def account(irc, host, uid): # In other words: Return True if the user is logged in, the query matches either '*' or the # user's login, and the user is connected on the network requested. return slogin and (groups[1] in ('*', slogin)) and (homenet == groups[2]) + +@bind +def ircop(irc, host, uid): + """ + $ircop exttarget handler. The following forms are supported, with groups separated by a + literal colon. Oper types are matched case insensitively. + + $ircop -> Returns True (a match) if the target is opered. + $ircop:*admin* -> Returns True if the target's is opered and their opertype matches the glob + given. + """ + groups = host.split(':') + log.debug('(%s) exttargets.ircop: groups to match: %s', irc.name, groups) + + if len(groups) == 1: + # 1st scenario. + return irc.isOper(uid, allowAuthed=False) + else: + # 2nd scenario. Use matchHost (ircmatch) to match the opertype glob to the opertype. + return irc.matchHost(groups[1], irc.users[uid].opertype)