Example #1
0
 def whois(self, stanza, *args):
     """ 查询用户信息 """
     nick = ' '.join(args[0:])
     m = Logics.get_with_nick(nick)
     if not m:
         self._send_cmd_result(stanza, u"{0} 用户不存在".format(nick))
         return
     bodys = []
     isonline = bool(
         [status.status for status in m.status if status.status])
     status = u"在线" if isonline else u"离线"
     resource = " ".join(s.resource for s in m.status if s.resource)
     rp = Logics.get_today_rp(m.email)
     rp = rp if rp else u"尚未测试"
     say_times = 0 if not m.history else len(m.history)
     level = u"管理员" if m.email in ADMINS else u"成员"
     last_say = u"从未发言" if not m.last_say else m.last_say
     last_change = m.last_change if m.last_change else u"从未修改"
     change_times = Logics.get_info(m.email, "change_nick_times", 0).value
     mode = Logics.get_info(stanza.from_jid, 'mode').value
     is_rece = u"是" if mode != "quiet" else u"否"
     bodys.append(u"昵称: {0}     状态: {1}".format(m.nick, status))
     bodys.append(u"资源: {0}     权限: {1}".format(resource, level))
     bodys.append(u"今日人品: {0}".format(rp))
     bodys.append(u"发言次数: {0}".format(say_times))
     bodys.append(u"最后发言: {0}".format(last_say))
     bodys.append(u"加入时间: {0}".format(m.join_date))
     bodys.append(u"更改昵称次数: {0}".format(change_times))
     bodys.append(u"上次更改时间: {0}".format(last_change))
     bodys.append(u"是否接受消息: {0}".format(is_rece))
     self._send_cmd_result(stanza, "\n".join(bodys))
Example #2
0
 def send_message(self, stanza, to, body, log = False):
     """ 发送消息
         `stanza`   - 消息节
         `to`       - 接收人 接收人不在线发送离线消息
         `body`     - 消息主体
         `log`      - 记录历史消息
     """
     if to == USER:
         return
     if log:
         Logics.add_history(stanza.from_jid, to, body)
     if Logics.is_online(to):
         mode = Logics.get_info(to, 'mode').value
         if mode == 'talk' or not mode:
             if isinstance(to, (str, unicode)):
                 to = JID(to)
             self.logger.debug("send '{0}' to {1!r}".format(body, to))
             typ = stanza.stanza_type
             self._stream.send(self.make_message(to, typ, body))
     else:
         body = NOW() + ' ' + body
         self.logger.debug("store offline message'{0}' for {1!r}"
                                 .format(body, to))
         offline_message = Logics.get_info(to, 'offline_message', '').value
         off_msgs = offline_message.split(self.offline_split_symbol)
         if len(off_msgs) >= 10:
             offline_message = self.offline_split_symbol.join(off_msgs[-9:])
         offline_message += self.offline_split_symbol +  body
         Logics.set_info(to, 'offline_message', offline_message)
Example #3
0
 def whois(self, stanza, *args):
     """ 查询用户信息 """
     nick = ' '.join(args[0:])
     m = Logics.get_with_nick(nick)
     if not m:
         self._send_cmd_result(stanza, u"{0} 用户不存在".format(nick))
         return
     bodys = []
     isonline = bool([status.status for status in m.status
                     if status.status])
     status = u"在线" if isonline else u"离线"
     resource = " ".join(s.resource for s in m.status if s.resource)
     rp = Logics.get_today_rp(m.email)
     rp = rp if rp else u"尚未测试"
     say_times = 0 if not m.history else len(m.history)
     level = u"管理员" if m.email in ADMINS else u"成员"
     last_say = u"从未发言" if not m.last_say else m.last_say
     last_change = m.last_change if m.last_change else u"从未修改"
     change_times = Logics.get_info(m.email, "change_nick_times", 0).value
     mode = Logics.get_info(stanza.from_jid, 'mode').value
     is_rece = u"是" if mode != "quiet" else u"否"
     bodys.append(u"昵称: {0}     状态: {1}".format(m.nick, status))
     bodys.append(u"资源: {0}     权限: {1}".format(resource, level))
     bodys.append(u"今日人品: {0}".format(rp))
     bodys.append(u"发言次数: {0}".format(say_times))
     bodys.append(u"最后发言: {0}".format(last_say))
     bodys.append(u"加入时间: {0}".format(m.join_date))
     bodys.append(u"更改昵称次数: {0}".format(change_times))
     bodys.append(u"上次更改时间: {0}".format(last_change))
     bodys.append(u"是否接受消息: {0}".format(is_rece))
     self._send_cmd_result(stanza, "\n".join(bodys))
Example #4
0
 def send_message(self, stanza, to, body, log=False):
     """ 发送消息
         `stanza`   - 消息节
         `to`       - 接收人 接收人不在线发送离线消息
         `body`     - 消息主体
         `log`      - 记录历史消息
     """
     if to == USER:
         return
     if log:
         Logics.add_history(stanza.from_jid, to, body)
     if Logics.is_online(to):
         mode = Logics.get_info(to, 'mode').value
         if mode == 'talk' or not mode:
             if isinstance(to, (str, unicode)):
                 to = JID(to)
             self.logger.debug("send '{0}' to {1!r}".format(body, to))
             typ = stanza.stanza_type
             self._stream.send(self.make_message(to, typ, body))
     else:
         body = NOW() + ' ' + body
         self.logger.debug("store offline message'{0}' for {1!r}".format(
             body, to))
         offline_message = Logics.get_info(to, 'offline_message', '').value
         off_msgs = offline_message.split(self.offline_split_symbol)
         if len(off_msgs) >= 10:
             offline_message = self.offline_split_symbol.join(off_msgs[-9:])
         offline_message += self.offline_split_symbol + body
         Logics.set_info(to, 'offline_message', offline_message)
Example #5
0
    def send_all_msg(self, stanza, body):
        """ 给除了自己的所有成员发送消息 """
        nick = Logics.get_one(stanza.from_jid).nick
        if stanza.from_jid.bare().as_string() == USER:
            return
        if cityid(body.strip()):
            return self.send_command(stanza, '-_tq ' + body.strip())
        if body.strip() == 'help':
            return self.send_command(stanza, '-help')
        if body.strip() == 'ping':
            return self.send_command(stanza, '-_ping')
        if body.startswith("```"):
            back = partial(self.send_back_msg, stanza)
            self.handle_code(stanza, body, nick, back)

        mode = Logics.get_info(stanza.from_jid, 'mode').value
        if mode == 'quiet':
            body = u'你处于{0},请使用-cd命令切换到 {1} '\
                    u'后发言'.format(MODES[mode], MODES['talk'])
            return self.send_back_msg(stanza, body)

        if body.startswith(">>>"):
            self.cmd_handler.shell(stanza, body.lstrip(">").lstrip())

        members = Logics.get_members(stanza.from_jid)
        members = [m.email for m in members]

        if len(body) > 200:

            def long_back(body, content):
                nick, url = content.split(" ")
                body = u"{0}\n{1}".format(url, body.split("\n")[0][0:50])
                self.send_back_msg(stanza, u"内容过长,贴到:{0}".format(url))
                self.logger.info("{0} send message {1} to {2!r}".format(
                    stanza.from_jid, body, members))
                Logics.add_history(stanza.from_jid, 'all', body)
                [
                    self.send_message(stanza, m,
                                      "[{0}] {1}".format(nick, body))
                    for m in members
                ]

            back = partial(long_back, body)
            self.handle_code(stanza, "```\n" + body, nick, back)
            return

        Logics.add_history(stanza.from_jid, 'all', body)
        self.logger.info("{0} send message {1} to {2!r}".format(
            stanza.from_jid, body, members))
        if body.startswith('/me'):
            body = body.replace('/me', nick + ' ')
        else:
            if nick != "qxbot":
                body = "[{0}] {1}".format(nick, body)
        [self.send_message(stanza, m, body) for m in members]
Example #6
0
    def send_all_msg(self, stanza, body):
        """ 给除了自己的所有成员发送消息 """
        nick = Logics.get_one(stanza.from_jid).nick
        if stanza.from_jid.bare().as_string() == USER:
            return
        if cityid(body.strip()):
            return self.send_command(stanza, '-_tq ' + body.strip())
        if body.strip() == 'help':
            return self.send_command(stanza, '-help')
        if body.strip() == 'ping':
            return self.send_command(stanza, '-_ping')
        if body.startswith("```"):
            back = partial(self.send_back_msg, stanza)
            self.handle_code(stanza, body, nick, back)

        mode = Logics.get_info(stanza.from_jid, 'mode').value
        if mode == 'quiet':
            body = u'你处于{0},请使用-cd命令切换到 {1} '\
                    u'后发言'.format(MODES[mode], MODES['talk'])
            return self.send_back_msg(stanza, body)


        if body.startswith(">>>"):
            self.cmd_handler.shell(stanza, body.lstrip(">").lstrip())

        members = Logics.get_members(stanza.from_jid)
        members = [m.email for m in members]

        if len(body) > 200:
            def long_back(body, content):
                nick, url = content.split(" ")
                body = u"{0}\n{1}".format(url, body.split("\n")[0][0:50])
                self.send_back_msg(stanza, u"内容过长,贴到:{0}".format(url))
                self.logger.info("{0} send message {1} to {2!r}"
                                    .format(stanza.from_jid, body, members))
                Logics.add_history(stanza.from_jid, 'all', body)
                [self.send_message(stanza, m, "[{0}] {1}".format(nick, body))
                 for m in members]

            back = partial(long_back, body)
            self.handle_code(stanza, "```\n" + body, nick, back)
            return

        Logics.add_history(stanza.from_jid, 'all', body)
        self.logger.info("{0} send message {1} to {2!r}"
                            .format(stanza.from_jid, body, members))
        if body.startswith('/me'):
            body = body.replace('/me', nick + ' ')
        else:
            if nick != "qxbot":
                body = "[{0}] {1}".format(nick, body)
        [self.send_message(stanza, m, body) for m in members]
Example #7
0
 def send_offline_message(self, stanza):
     """ 发送离线消息 """
     show = stanza.show
     frm = stanza.from_jid
     offline_message = Logics.get_info(frm, 'offline_message', '').value
     if offline_message:
         off_msgs = offline_message.split(self.offline_split_symbol)
         offline_message = "\n".join(off_msgs)
         offline_message = "离线期间的消息:\n" + offline_message
         m = self.make_message(frm, 'chat', offline_message)
         self._stream.send(m)
         Logics.set_online(frm, show)
         Logics.set_info(frm, 'offline_message', '')
Example #8
0
 def send_offline_message(self, stanza):
     """ 发送离线消息 """
     show = stanza.show
     frm = stanza.from_jid
     offline_message = Logics.get_info(frm, 'offline_message', '').value
     if offline_message:
         off_msgs = offline_message.split(self.offline_split_symbol)
         offline_message = "\n".join(off_msgs)
         offline_message = "离线期间的消息:\n" + offline_message
         m = self.make_message(frm, 'chat', offline_message)
         self._stream.send(m)
         Logics.set_online(frm, show)
         Logics.set_info(frm, 'offline_message', '')
Example #9
0
    def send_offline_message(self, stanza):
        """ 发送离线消息 """
        show = stanza.show
        frm = stanza.from_jid
        offline_message = Logics.get_info(frm, 'offline_message', '').value
        if offline_message:
            temp_msgs = offline_message.split(self.offline_split_symbol)
            off_msgs = []

            for m in temp_msgs:
                ms = m.split(" ")
                date = " ".join(ms[:2])
                msg = " ".join(ms[2:])
                date = nicetime(date)
                off_msgs.append(date + " " + msg)

            offline_message = "\n".join(off_msgs)
            offline_message = "离线期间的消息:\n" + offline_message
            if len(off_msgs) == 10:
                offline_message += "\n(仅显示最近10条, 更多历史消息请使用 -old 查看)"
            m = self.make_message(frm, 'chat', offline_message)
            self._stream.send(m)
            Logics.set_online(frm, show)
            Logics.set_info(frm, 'offline_message', '')
Example #10
0
    def send_offline_message(self, stanza):
        """ 发送离线消息 """
        show = stanza.show
        frm = stanza.from_jid
        offline_message = Logics.get_info(frm, 'offline_message', '').value
        if offline_message:
            temp_msgs = offline_message.split(self.offline_split_symbol)
            off_msgs = []

            for m in temp_msgs:
                ms = m.split(" ")
                date = " ".join(ms[:2])
                msg = " ".join(ms[2:])
                date = nicetime(date)
                off_msgs.append(date + " " + msg)

            offline_message = "\n".join(off_msgs)
            offline_message = "离线期间的消息:\n" + offline_message
            if len(off_msgs) == 10:
                offline_message += "\n(仅显示最近10条, 更多历史消息请使用 -old 查看)"
            m = self.make_message(frm, 'chat', offline_message)
            self._stream.send(m)
            Logics.set_online(frm, show)
            Logics.set_info(frm, 'offline_message', '')