From b4e83e7b1a13f101f5908611e7150a1a261fa709 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 11 Aug 2016 12:46:05 -0700 Subject: [PATCH] clientbot: basic prefix mode detection (halfop, admin, owner) --- protocols/clientbot.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/protocols/clientbot.py b/protocols/clientbot.py index 73e0635..7447567 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -6,6 +6,8 @@ from pylinkirc import utils, conf from pylinkirc.log import log from pylinkirc.classes import Protocol, IrcUser, IrcServer +COMMON_PREFIXMODES = [('h', 'halfop'), ('a', 'admin'), ('q', 'owner'), ('y', 'owner')] + class ClientbotWrapperProtocol(Protocol): def __init__(self, irc): super().__init__(irc) @@ -49,9 +51,6 @@ class ClientbotWrapperProtocol(Protocol): ts = self.irc.start_ts f = self.irc.send - # TODO: fetch channel/user/prefix modes from RPL_ISUPPORT. - #self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'} - # Enumerate our own server self.irc.sid = self.sidgen.next_sid() @@ -328,9 +327,17 @@ class ClientbotWrapperProtocol(Protocol): log.debug('(%s) handle_005: casemapping set to %s', self.irc.name, self.casemapping) if 'PREFIX' in self.caps: - self.irc.prefixmodes = self.parsePrefixes(self.caps['PREFIX']) + self.irc.prefixmodes = prefixmodes = self.parsePrefixes(self.caps['PREFIX']) log.debug('(%s) handle_005: prefix modes set to %s', self.irc.name, self.irc.prefixmodes) + # Autodetect common prefix mode names. + for char, modename in COMMON_PREFIXMODES: + # Don't overwrite existing named mode definitions. + if char in self.irc.prefixmodes and modename not in self.irc.cmodes: + self.irc.cmodes[modename] = char + log.debug('(%s) handle_005: autodetecting mode %s (%s) as %s', self.irc.name, + char, self.irc.prefixmodes[char], modename) + self.irc.connected.set() def handle_376(self, source, command, args):