def _handle_RPL_TOPICWHOTIME(self, message): # Topic author (NONSTANDARD). Sent after RPL_TOPIC. # Unfortunately, there's no way to know whether to expect this. # TODO this doesn't handle the "requesting" part # TODO what if me != me? me, channel_name, author, timestamp = message.args topic = self._pending_topics.setdefault(channel_name, IRCTopic('')) topic.author = Peer.from_prefix(author) topic.timestamp = datetime.utcfromtimestamp(int(timestamp))
def _handle_JOIN(self, message): channel_name, = message.args joiner = Peer.from_prefix(message.prefix) # TODO should there be a self.me? how... if joiner.name == self.nick: # We just joined a channel #assert channel_name not in self.joined_channels # TODO key? do we care? # TODO what about channel configuration and anon non-joined # channels? how do these all relate... channel = IRCChannel(self, channel_name) self.joined_channels[channel.name] = channel else: # Someone else just joined the channel self.joined_channels[channel_name].add_user(joiner)
def _handle_PRIVMSG(self, message): # PRIVMSG target :text target_name, text = message.args source = Peer.from_prefix(message.prefix) if target_name[0] in self.channel_types: target = self.get_channel(target_name) cls = PublicMessage else: # TODO this is /us/, so, surely ought to be known target = Peer(target_name, None, None) cls = PrivateMessage return cls(source, target, text, client=self, raw=message)
def test_echo(loop): manager = PluginManager() manager.scan_package('dywypi.plugins') manager.load('echo') assert 'echo' in manager.loaded_plugins # TODO this would be much easier if i could just pump messages into # somewhere and get them out of somewhere else. even have an IRC proto on # both ends! wow that sounds like a great idea too. client = DummyClient(loop) client.nick = 'dywypi' ev = Message( Peer.from_prefix('nobody!ident@host'), Peer('dywypi', None, None), 'dywypi: echo foo', client=client, ) loop.run_until_complete(asyncio.gather(*manager.fire(ev), loop=loop)) assert client.accumulated_messages == [('nobody', 'foo')]
def source(self): return Peer.from_prefix(self.raw_message.prefix)