Add irc_lower() and irc_equals() to IRCServer.Server so that no where else

in the code has to know about the server having a casemapping
This commit is contained in:
jesopo 2019-01-24 17:12:50 +00:00
parent 5bfa0d2b50
commit 301dd7378a
8 changed files with 20 additions and 21 deletions

View file

@ -23,8 +23,7 @@ class Module(ModuleManager.BaseModule):
@utils.hook("self.join")
def on_join(self, event):
channels = event["server"].get_setting("autojoin", [])
channel_name = utils.irc.lower(event["server"].case_mapping,
event["channel"].name)
channel_name = event["server"].irc_lower(event["channel"].name)
if not channel_name in channels:
channels.append(channel_name)
event["server"].set_setting("autojoin", channels)

View file

@ -36,8 +36,7 @@ class Module(ModuleManager.BaseModule):
if not event["user"].last_karma or (time.time()-event["user"
].last_karma) >= KARMA_DELAY_SECONDS:
target = match.group(1).strip()
if utils.irc.lower(event["server"].case_mapping, target
) == event["user"].name:
if event["server"].irc_lower(target) == event["user"].name:
if verbose:
self.events.on("send.stderr").call(
module_name="Karma", target=event["channel"],

View file

@ -618,8 +618,7 @@ class Module(ModuleManager.BaseModule):
# we need a registered nickname for this channel
@utils.hook("raw.received.477", default_event=True)
def handle_477(self, event):
channel_name = utils.irc.lower(event["server"].case_mapping,
event["args"][1])
channel_name = event["server"].irc_lower(event["args"][1])
if channel_name in event["server"].channels:
key = event["server"].attempted_join[channel_name]
self.timers.add("rejoin", 5, channel_name=channe_name, key=key,

View file

@ -45,8 +45,7 @@ class Buffer(object):
) -> typing.Optional[BufferLine]:
from_self = kwargs.get("from_self", True)
for_user = kwargs.get("for_user", "")
for_user = utils.irc.lower(self.server.case_mapping, for_user
) if for_user else None
for_user = self.server.irc_lower(for_user) if for_user else None
not_pattern = kwargs.get("not_pattern", None)
for line in self.lines:
if line.from_self and not from_self:
@ -54,8 +53,8 @@ class Buffer(object):
elif re.search(pattern, line.message):
if not_pattern and re.search(not_pattern, line.message):
continue
if for_user and not utils.irc.lower(self.server.case_mapping,
line.sender) == for_user:
if for_user and not self.server.irc_lower(line.sender
) == for_user:
continue
return line
return None

View file

@ -6,7 +6,7 @@ class Channel(IRCObject.Object):
name = ""
def __init__(self, name: str, id, server: "IRCServer.Server",
bot: "IRCBot.Bot"):
self.name = utils.irc.lower(server.case_mapping, name)
self.name = server.irc_lower(name)
self.id = id
self.server = server
self.bot = bot

View file

@ -30,7 +30,7 @@ class Channels(object):
return self._bot.database.channels.get_id(self._server.id, channel_name)
def _name_lower(self, channel_name: str) -> str:
return utils.irc.lower(self._server.case_mapping, channel_name)
return self._server.irc_lower(channel_name)
def contains(self, name: str) -> bool:
lower = self._name_lower(name)

View file

@ -173,12 +173,11 @@ class Server(IRCObject.Object):
def set_own_nickname(self, nickname: str):
self.nickname = nickname
self.nickname_lower = utils.irc.lower(self.case_mapping, nickname)
self.nickname_lower = self.irc_lower(nickname)
def is_own_nickname(self, nickname: str) -> bool:
if self.nickname == None:
return False
return utils.irc.equals(self.case_mapping, nickname,
typing.cast(str, self.nickname))
return self.irc_equals(nickname, typing.cast(str, self.nickname))
def add_own_mode(self, mode: str, arg: str=None):
self.own_modes[mode] = arg
@ -191,7 +190,7 @@ class Server(IRCObject.Object):
self.add_own_mode(mode, arg)
def has_user(self, nickname: str) -> bool:
return utils.irc.lower(self.case_mapping, nickname) in self.users
return self.irc_lower(nickname) in self.users
def get_user(self, nickname: str, create: bool=True
) -> typing.Optional[IRCUser.User]:
if not self.has_user(nickname) and create:
@ -200,7 +199,7 @@ class Server(IRCObject.Object):
self.events.on("new.user").call(user=new_user, server=self)
self.users[new_user.nickname_lower] = new_user
self.new_users.add(new_user)
return self.users.get(utils.irc.lower(self.case_mapping, nickname),
return self.users.get(self.irc_lower(nickname),
None)
def get_user_id(self, nickname: str) -> int:
self.bot.database.users.add(self.id, nickname)
@ -221,9 +220,14 @@ class Server(IRCObject.Object):
return None
def change_user_nickname(self, old_nickname: str, new_nickname: str):
user = self.users.pop(utils.irc.lower(self.case_mapping, old_nickname))
user = self.users.pop(self.irc_lower(old_nickname))
user._id = self.get_user_id(new_nickname)
self.users[utils.irc.lower(self.case_mapping, new_nickname)] = user
self.users[self.irc_lower(new_nickname)] = user
def irc_lower(self, s: str) -> bool:
return utils.irc.lower(self.case_mapping, s)
def irc_equal(self, s1: str, s2: str) -> bool:
return utils.irc.equals(self.case_mapping, s1, s2)
def parse_data(self, line: str):
if not line:

View file

@ -38,8 +38,7 @@ class User(IRCObject.Object):
def set_nickname(self, nickname: str):
self.nickname = nickname
self.nickname_lower = utils.irc.lower(self.server.case_mapping,
nickname)
self.nickname_lower = self.server.irc_lower(nickname)
self.name = self.nickname_lower
def join_channel(self, channel: "IRCChannel.Channel"):
self.channels.add(channel)