'mode_prefixes' -> prefix_modes and prefix_symbols

This commit is contained in:
jesopo 2018-10-03 16:44:00 +01:00
parent 6c1ac52fde
commit 98207be7b1
3 changed files with 18 additions and 17 deletions

View file

@ -70,12 +70,13 @@ class Module(ModuleManager.BaseModule):
match = re.search(RE_PREFIXES, isupport_line)
if match:
event["server"].mode_prefixes.clear()
event["server"].prefix_symbols.clear()
event["server"].prefix_modes.clear()
modes = match.group(1)
prefixes = match.group(2)
for i, prefix in enumerate(prefixes):
if i < len(modes):
event["server"].mode_prefixes[prefix] = modes[i]
symbols = match.group(2)
for symbol, mode in zip(symbols, modes):
event["server"].prefix_symbols[symbol] = mode
event["server"].prefix_modes[mode] = symbol
match = re.search(RE_CHANMODES, isupport_line)
if match:
event["server"].channel_modes = list(match.group(4))
@ -145,8 +146,8 @@ class Module(ModuleManager.BaseModule):
for nickname in nicknames:
modes = set([])
while nickname[0] in event["server"].mode_prefixes:
modes.add(event["server"].mode_prefixes[nickname[0]])
while nickname[0] in event["server"].prefix_symbols:
modes.add(event["server"].prefix_symbols[nickname[0]])
nickname = nickname[1:]
if "userhost-in-names" in event["server"].capabilities:
@ -336,8 +337,7 @@ class Module(ModuleManager.BaseModule):
for mode in chunk[1:]:
if mode in event["server"].channel_modes:
channel.change_mode(remove, mode)
elif mode in event["server"].mode_prefixes.values(
) and len(args):
elif mode in event["server"].prefix_modes and len(args):
channel.change_mode(remove, mode, args.pop(0))
else:
args.pop(0)

View file

@ -36,8 +36,7 @@ class Channel(IRCObject.Object):
def remove_user(self, user):
self.users.remove(user)
for mode in list(self.modes.keys()):
if mode in self.server.mode_prefixes.values(
) and user in self.modes[mode]:
if mode in self.server.prefix_modes and user in self.modes[mode]:
self.modes[mode].discard(user)
if not len(self.modes[mode]):
del self.modes[mode]
@ -48,7 +47,7 @@ class Channel(IRCObject.Object):
if not mode in self.modes:
self.modes[mode] = set([])
if arg:
if mode in self.server.mode_prefixes.values():
if mode in self.server.prefix_modes:
user = self.server.get_user(arg)
if user:
self.modes[mode].add(user)
@ -58,7 +57,7 @@ class Channel(IRCObject.Object):
if not arg:
del self.modes[mode]
else:
if mode in self.server.mode_prefixes.values():
if mode in self.server.prefix_modes:
user = self.server.get_user(arg)
if user:
self.modes[mode].discard(user)
@ -123,7 +122,7 @@ class Channel(IRCObject.Object):
self.server.send_part(self.name, reason)
def mode_or_above(self, user, mode):
mode_orders = list(self.server.mode_prefixes.values())
mode_orders = list(self.server.prefix_modes)
mode_index = mode_orders.index(mode)
for mode in mode_orders[:mode_index+1]:
if user in self.modes.get(mode, []):

View file

@ -40,8 +40,10 @@ class Server(IRCObject.Object):
self.channels = {}
self.own_modes = {}
self.mode_prefixes = collections.OrderedDict(
{"@": "o", "+": "v"})
self.prefix_symbols = collections.OrderedDict(
(("@", "o"), ("+", "v")))
self.prefix_modes = collections.OrderedDict(
(("o", "@"), ("v", "+")))
self.channel_modes = []
self.channel_types = ["#"]
self.case_mapping = "rfc1459"
@ -260,8 +262,8 @@ class Server(IRCObject.Object):
if len(encoded) > 450:
encoded = encoded[:450]
self.buffered_lines.append(encoded + b"\r\n")
self.bot.log.debug(">%s | %s", [str(self), encoded.decode("utf8")])
def _send(self):
if not len(self.write_buffer):
self.write_buffer = self.buffered_lines.pop(0)