Commit 0abe11f7 authored by Elizabeth Myers's avatar Elizabeth Myers 💬
Browse files

Merge branch 'channeltrack-out-of-order-rpl-topic' into 'master'

channeltrack: handle processing topic before join

Closes #19

See merge request IRC/PyIRC!10
parents 5fec8ec7 69b4f499
......@@ -70,6 +70,16 @@ class Channel:
self.url = kwargs.get("url", None)
self.users = kwargs.get("users", IRCDefaultDict(case, set))
def update(self, **kwargs):
""" Update data for a channel. Uses the same kwargs as __init__."""
self.modes = kwargs.get("modes", self.modes)
self.topic = kwargs.get("topic", self.topic)
self.topictime = kwargs.get("topictime", self.topictime)
self.topicwho = kwargs.get("topicwho", self.topicwho)
self.timestamp = kwargs.get("timestamp", self.timestamp)
self.url = kwargs.get("url", self.url)
self.users = kwargs.get("users", self.users)
def __repr__(self):
keys = ("name", "modes", "topic", "topictime", "topicwho", "timestamp",
"url", "users")
......@@ -143,8 +153,9 @@ class ChannelTrack(BaseExtension):
channel = Channel(, name, **kwargs)
self.channels[name] = channel
self.call_event("channel", "channel_create", channel)
_logger.debug("Updating channel: %s", name)
return channel
......@@ -212,9 +223,11 @@ class ChannelTrack(BaseExtension):
"""Handle a user (possibly us) joining a channel."""
# JOIN event
basicrfc = self.base.basic_rfc
_logger.debug("Received user_join for nick %s, channel %s",, scope.scope)
if self.casecmp(, basicrfc.nick):
# We're joining
channel = self.add_channel(scope.scope)
self.call_event("channel", "channel_create", channel)
self.burst(caller, scope)
......@@ -267,27 +280,32 @@ class ChannelTrack(BaseExtension):
for channel in self.channels.values():
channel.users.pop(user, None)
@event("commands", Numerics.RPL_TOPIC)
@event("commands", "TOPIC")
@event("commands", Numerics.RPL_TOPIC, priority=-1000)
@event("commands", "TOPIC", priority=-1000)
def topic(self, _, line):
"""Update a channel's topic."""
# TODO server/local time deltas for more accurate timestamps
topic = line.params[-1]
topicwho = line.hostmask
topictime = int(time())
if line.command.lower() == "topic":
channel = self.get_channel(line.params[0])
if channel is None:
_logger.debug("Topic for unknown channel: %s", line.params[0])
# TODO server/local time deltas for more accurate timestamps
channel.topicwho = line.hostmask
channel.topictime = int(time())
channel = self.get_channel(line.params[1])
if channel is None:
_logger.debug("RPL_TOPIC for unknown channel: %s",
_logger.debug("RPL_TOPIC for unknown channel: %s.",
self.add_channel(line.params[1], topic=topic, topicwho=topicwho,
channel.topic = line.params[-1]
channel.topic = topic
channel.topicwho = topicwho
channel.topictime = topictime
@event("commands", Numerics.RPL_NOTOPIC)
def no_topic(self, _, line):
......@@ -303,14 +321,19 @@ class ChannelTrack(BaseExtension):
@event("commands", Numerics.RPL_TOPICWHOTIME)
def topic_who_time(self, _, line):
"""Update the channel's topic metadata."""
channel = self.get_channel(line.params[1])
topicwho = Hostmask.parse(line.params[2])
topictime = int(line.params[3])
channelname = line.params[1]
channel = self.get_channel(channelname)
if channel is None:
_logger.debug("Topic time for unknown channel: %s",
self.add_channel(channelname, topicwho=topicwho,
channel.topicwho = Hostmask.parse(line.params[2])
channel.topictime = int(line.params[3])
channel.topicwho = topicwho
channel.topictime = topictime
@event("commands", Numerics.RPL_CHANNELURL)
def url(self, _, line):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment