def join(self, sock, source, name): user = self.users[sock] if name not in self.channels: channel = self.channels[name] = Channel(name) else: channel = self.channels[name] if user in channel.users: return user.channels.append(name) channel.users.append(user) self._notify(channel.users, Message("JOIN", name, prefix=user.prefix)) if channel.topic: self.fire(reply(sock, RPL_TOPIC(channel.topic))) else: self.fire(reply(sock, RPL_NOTOPIC(channel.name))) self.fire( reply( sock, RPL_NAMEREPLY(channel.name, [x.prefix for x in channel.users]))) self.fire(reply(sock, RPL_ENDOFNAMES(channel.name)))
def topic(self, sock, source, name, topic=None, **kwargs): user = models.User.objects.filter(sock=sock).first() channel = models.Channel.objects.filter(name=name).first() if channel is None: return ERR_NOSUCHCHANNEL(name) _topic, _topic_setter, _topic_timestamp = channel.topic if topic is None and not _topic: if kwargs.get("joined", False): return return RPL_NOTOPIC(channel.name) if topic is None: return (RPL_TOPIC(channel.name, _topic), RPL_TOPICWHO(channel.name, _topic_setter, _topic_timestamp)) if not user.oper and u"t" in channel.modes and user not in channel.operators: return ERR_CHANOPRIVSNEEDED(channel.name) channel.topic = (topic, user.prefix) self.notify(channel.users[:], TOPIC(channel.name, topic, prefix=user.prefix))
def topic(self, sock, source, name, topic=None): user = models.User.objects.filter(sock=sock).first() channel = models.Channel.objects.filter(name=name).first() if channel is None: return ERR_NOSUCHCHANNEL(name) if topic is None and not channel.topic: return RPL_NOTOPIC(channel.name) if topic is None: return RPL_TOPIC(channel.name, channel.topic) if not user.oper and u"t" in channel.modes and user not in channel.operators: return ERR_CHANOPRIVSNEEDED(channel.name) channel.topic = topic channel.save() self.notify(channel.users[:], TOPIC(channel.name, topic, prefix=user.prefix))