diff --git a/src/context.py b/src/context.py index f11c09e..5ec7962 100644 --- a/src/context.py +++ b/src/context.py @@ -71,11 +71,13 @@ def _send(data, first, sep, client, send_type, name): extra, line = line[:length], line[length:] client.send("{0} {1} :{2}{3}".format(send_type, name, first, extra)) -def lower(nick, *, host=False): +def lower(nick, *, casemapping=None): if nick is None: return None - if isinstance(nick, IRCContext) or host: + if isinstance(nick, IRCContext): return nick.lower() + if casemapping is None: + casemapping = Features["CASEMAPPING"] mapping = { "[": "{", @@ -84,9 +86,9 @@ def lower(nick, *, host=False): "^": "~", } - if Features["CASEMAPPING"] == "strict-rfc1459": + if casemapping == "strict-rfc1459": mapping.pop("^") - elif Features["CASEMAPPING"] == "ascii": + elif casemapping == "ascii": mapping.clear() return nick.lower().translate(str.maketrans(mapping)) diff --git a/src/users.py b/src/users.py index d6bb71f..ba4fa68 100644 --- a/src/users.py +++ b/src/users.py @@ -279,7 +279,7 @@ class User(IRCContext): return self._compare(other, __class__, "nick", "ident", "host", "realname", "account") def lower(self): - temp = type(self)(self.client, lower(self.nick), lower(self.ident), lower(self.host, host=True), lower(self.realname), lower(self.account)) + temp = type(self)(self.client, lower(self.nick), lower(self.ident), lower(self.host, casemapping="ascii"), lower(self.realname), lower(self.account)) if temp is not self: # If everything is already lowercase, we'll get back the same instance temp.channels = self.channels temp.ref = self.ref or self @@ -573,7 +573,7 @@ class BotUser(User): # TODO: change all the 'if x is Bot' for 'if isinstance(x, temp = type(self)(self.client, lower(self.nick)) if temp is not self: temp.ident = lower(self.ident) - temp.host = lower(self.host, host=True) + temp.host = lower(self.host, casemapping="ascii") temp.realname = lower(self.realname) temp.account = lower(self.account) temp.modes = self.modes