def from_user(self, receivers=None, text=None, *_): if receivers is None: return ERR_NORECIPIENT(self.command, self.actor) if text is None: return ERR_NOTEXTTOSEND(self.actor) resp = [] # TODO: check for ERR_TOOMANYTARGETS for receiver in receivers.split(','): if Channel.exists(receiver): users = [user for user in Channel.get(receiver).users if user is not self.user] resp.append(M( ActorCollection(users), self.command, str(receiver), text, prefix=str(self.user))) elif User.exists(receiver): resp.append(M( Actor.by_user(User.get(receiver)), self.command, str(receiver), text, prefix=str(self.user))) # TODO: Implement wildcards # TODO: check for ERR_WILDTOPLEVEL, RPL_AWAY, ERR_NOTOPLEVEL else: resp.append(ERR_NOSUCHNICK(receiver, self.actor)) return resp
def __init__(self, children): self.children = set() for child in children: if isinstance(child, Actor): self.children.add(child) elif isinstance(child, User): self.children.add(Actor.by_user(child)) elif isinstance(child, Server): self.children.add(Actor.by_server(child)) elif isinstance(child, ActorCollection): self.children += child.children else: raise Error('Don\'t know what to do with %s' + child.__class__)
def from_user(self, receivers=None, text=None, *_): if receivers is None: return ERR_NORECIPIENT(self.command, self.actor) if text is None: return ERR_NOTEXTTOSEND(self.actor) resp = [] # TODO: check for ERR_TOOMANYTARGETS for receiver in receivers.split(','): if Channel.exists(receiver): channel_log = '%s/%s.log' % (config.get( 'server', 'channel_log_dir'), receiver.replace('#', '')) # if not PrivmsgCommand.channel_log_files.get(channel_log): # PrivmsgCommand.channel_log_files[channel_log] = open(channel_log,'a') # PrivmsgCommand.channel_log_files[channel_log].write("%s::%s::%s::%s\n" % ( # time.time(), time.strftime('%Y-%m-%d %H:%I:%S'), self.user.nickname, text # )) # PrivmsgCommand.channel_log_files[channel_log].flush() with open(channel_log, 'a') as f: f.write("%s::%s::%s::%s\n" % (time.time(), time.strftime('%Y-%m-%d %H:%I:%S'), self.user.nickname, text)) f.flush() users = [ user for user in Channel.get(receiver).users if user is not self.user ] resp.append( M(ActorCollection(users), self.command, str(receiver), text, prefix=str(self.user))) elif User.exists(receiver): resp.append( M(Actor.by_user(User.get(receiver)), self.command, str(receiver), text, prefix=str(self.user))) # TODO: Implement wildcards # TODO: check for ERR_WILDTOPLEVEL, RPL_AWAY, ERR_NOTOPLEVEL else: resp.append(ERR_NOSUCHNICK(receiver, self.actor)) return resp
def from_user(self, receivers=None, text=None, *_): if receivers is None: return ERR_NORECIPIENT(self.command, self.actor) if text is None: return ERR_NOTEXTTOSEND(self.actor) resp = [] # TODO: check for ERR_TOOMANYTARGETS for receiver in receivers.split(','): if Channel.exists(receiver): channel_log = '%s/%s.log' % ( config.get('server', 'channel_log_dir'), receiver.replace('#','')) # if not PrivmsgCommand.channel_log_files.get(channel_log): # PrivmsgCommand.channel_log_files[channel_log] = open(channel_log,'a') # PrivmsgCommand.channel_log_files[channel_log].write("%s::%s::%s::%s\n" % ( # time.time(), time.strftime('%Y-%m-%d %H:%I:%S'), self.user.nickname, text # )) # PrivmsgCommand.channel_log_files[channel_log].flush() with open(channel_log,'a') as f: f.write("%s::%s::%s::%s\n" % ( time.time(), time.strftime('%Y-%m-%d %H:%I:%S'), self.user.nickname, text )) f.flush() users = [user for user in Channel.get(receiver).users if user is not self.user] resp.append(M( ActorCollection(users), self.command, str(receiver), text, prefix=str(self.user) )) elif User.exists(receiver): resp.append(M( Actor.by_user(User.get(receiver)), self.command, str(receiver), text, prefix=str(self.user) )) # TODO: Implement wildcards # TODO: check for ERR_WILDTOPLEVEL, RPL_AWAY, ERR_NOTOPLEVEL else: resp.append(ERR_NOSUCHNICK(receiver, self.actor)) return resp