From 47d38c7d185856fd81fddf94883009bbaf749e3c Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 20 Sep 2019 14:52:41 +0100 Subject: [PATCH] refactor all checks for channel_type to server.is_channel() --- modules/config.py | 2 +- modules/line_handler/core.py | 2 +- modules/line_handler/message.py | 5 ++--- src/IRCChannels.py | 4 ++-- src/IRCServer.py | 5 ++++- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/config.py b/modules/config.py index 27161cca..ce325724 100644 --- a/modules/config.py +++ b/modules/config.py @@ -53,7 +53,7 @@ class Module(ModuleManager.BaseModule): else: #we're in a channel return channel, "channelset", None - if context_desc_lower[0] in server.channel_types: + elif server.is_channel(context_desc): return context_desc, "channelset", context_desc elif server.irc_lower(context_desc) == user.nickname_lower: return user, "set", None diff --git a/modules/line_handler/core.py b/modules/line_handler/core.py index 81c364ce..aac9e327 100644 --- a/modules/line_handler/core.py +++ b/modules/line_handler/core.py @@ -77,7 +77,7 @@ def _own_modes(server, modes): def mode(events, event): user = event["server"].get_user(event["line"].source.nickname) target = event["line"].args[0] - is_channel = target[0] in event["server"].channel_types + is_channel = event["server"].is_channel(target) if is_channel: channel = event["server"].channels.get(target) modes = event["line"].args[1] diff --git a/modules/line_handler/message.py b/modules/line_handler/message.py index d44ed81e..e644d08e 100644 --- a/modules/line_handler/message.py +++ b/modules/line_handler/message.py @@ -41,10 +41,9 @@ def message(events, event): # voiced-or-above users target = target_str.lstrip("".join(event["server"].statusmsg)) - is_channel = False + is_channel = event["server"].is_channel(target) - if target[0] in event["server"].channel_types: - is_channel = True + if is_channel: if not target in event["server"].channels: return target_obj = event["server"].channels.get(target) diff --git a/src/IRCChannels.py b/src/IRCChannels.py index ebcc8077..331706fa 100644 --- a/src/IRCChannels.py +++ b/src/IRCChannels.py @@ -34,8 +34,8 @@ class Channels(object): return self._server.irc_lower(channel_name) def contains(self, name: str) -> bool: - lower = self._name_lower(name) - return name[0] in self._server.channel_types and lower in self._channels + return (self._server.is_channel(name) and + self._name_lower(name) in self._channels) def add(self, name: str) -> IRCChannel.Channel: id = self.get_id(name) diff --git a/src/IRCServer.py b/src/IRCServer.py index 752e2f67..e2480dc3 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -186,10 +186,13 @@ class Server(IRCObject.Object): for channel in user.channels: channel.remove_user(user) + def is_channel(self, name: str) -> bool: + return name[0] in self.channel_types + def get_target(self, name: str ) -> typing.Optional[ typing.Union[IRCChannel.Channel, IRCUser.User]]: - if name[0] in self.channel_types: + if self.is_channel(name): if name in self.channels: return self.channels.get(name) else: