示例#1
0
 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
示例#2
0
文件: nick.py 项目: Slach/python-ircd
 def rename(self):
     from_full = str(self.user)
     self.user.rename(self.params.nick)
     targets = [self.actor] + Server.all()
     for channel in self.user.channels:
         targets += channel.users
     return M(ActorCollection(targets),
              'NICK', self.params.nick,
              prefix=from_full)
示例#3
0
 def join_message(self, channel):
     ret = [
         M(ActorCollection(channel.users),
           'JOIN', str(channel),
           prefix=self.user),
         RPL_NAMEREPLY(self.actor, channel),
         RPL_ENDOFNAMES(self.actor)
     ]
     if channel.topic is not None:
         ret.append(RPL_TOPIC(self.actor, channel))
     return ret
示例#4
0
 def from_user(self, message='leaving', *_):
     ret = []
     for channel in self.user.channels:
         channel.part(self.user)
         ret.append(
             M(ActorCollection(channel.users),
               'PART',
               str(channel),
               message,
               prefix=str(self.user)))
     self.user.delete()
     self.actor.disconnect()
     return ret + [M(self.actor, 'ERROR')]
示例#5
0
    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
示例#6
0
 def from_user(self, channel_name, topic=None, *_):
     # TODO: ERR_NOCHANMODES, ERR_CHANOPRIVSNEEDED
     if not Channel.exists(channel_name):
         return ERR_NOSUCHCHANNEL(channel_name, self.actor)
     channel = Channel.get(channel_name)
     if self.user not in channel.users:
         return ERR_NOTONCHANNEL(channel_name, self.actor)
     if topic is None:
         if channel.topic is None:
             return RPL_NOTOPIC(self.actor, channel)
         else:
             return RPL_TOPIC(self.actor, channel)
     elif topic == '':
         channel.topic = None
     else:
         channel.topic = topic
     # Forward message to others on the channel
     self.message.target = ActorCollection(channel.users)
     return self.message
示例#7
0
    def from_user(self, channels, msg='leaving', *_):
        channels = channels.split(',')

        ret = []

        for channel_name in channels:
            if not Channel.exists(channel_name):
                ret.append(ERR_NOSUCHCHANNEL(channel_name, self.actor))
                continue
            channel = Channel.get(channel_name)
            if self.user not in channel.users:
                ret.append(ERR_NOTONCHANNEL(channel_name, self.actor))
                continue
            ret.append(
                M(ActorCollection(channel.users),
                  'PART',
                  str(channel),
                  msg,
                  prefix=str(self.user)))
            self.user.part(channel)

        return ret