Don't implicitly create channels, explicitly create channels when we join one

This commit is contained in:
jesopo 2018-11-11 13:03:54 +00:00
parent e29cc1c52c
commit 6bb03c4519
2 changed files with 5 additions and 3 deletions

View file

@ -187,7 +187,7 @@ class Module(ModuleManager.BaseModule):
def join(self, event): def join(self, event):
account = None account = None
realname = None realname = None
channel = event["server"].channels.get(event["args"][0]) channel_name = event["args"][0]
if len(event["args"]) == 2: if len(event["args"]) == 2:
if not event["args"][1] == "*": if not event["args"][1] == "*":
@ -195,6 +195,7 @@ class Module(ModuleManager.BaseModule):
realname = event["args"][2] realname = event["args"][2]
if not event["server"].is_own_nickname(event["prefix"].nickname): if not event["server"].is_own_nickname(event["prefix"].nickname):
channel = event["server"].channels.get(channel_name)
user = event["server"].get_user(event["prefix"].nickname) user = event["server"].get_user(event["prefix"].nickname)
if not user.username and not user.hostname: if not user.username and not user.hostname:
user.username = event["prefix"].username user.username = event["prefix"].username
@ -213,6 +214,7 @@ class Module(ModuleManager.BaseModule):
user=user, server=event["server"], account=account, user=user, server=event["server"], account=account,
realname=realname) realname=realname)
else: else:
channel = event["server"].channels.add(channel_name)
if channel.name in event["server"].attempted_join: if channel.name in event["server"].attempted_join:
del event["server"].attempted_join[channel.name] del event["server"].attempted_join[channel.name]
self.events.on("self.join").call(channel=channel, self.events.on("self.join").call(channel=channel,

View file

@ -170,6 +170,8 @@ class Channels(object):
return self.contains(name) return self.contains(name)
def __len__(self) -> int: def __len__(self) -> int:
return len(self._channels) return len(self._channels)
def __getitem__(self, name: str):
return self.get(name)
def _get_id(self, channel_name: str) -> int: def _get_id(self, channel_name: str) -> int:
self._bot.database.channels.add(self._server.id, channel_name) self._bot.database.channels.add(self._server.id, channel_name)
@ -195,8 +197,6 @@ class Channels(object):
del self._channels[lower] del self._channels[lower]
def get(self, name: str): def get(self, name: str):
if not self.contains(name):
return self.add(name)
return self._channels[self._name_lower(name)] return self._channels[self._name_lower(name)]
def rename(self, old_name, new_name): def rename(self, old_name, new_name):