Fix proper lowercasing, take 2
This commit is contained in:
parent
2cd410ace8
commit
fb7bf56579
@ -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))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user