Exemplo n.º 1
0
    def old(self, stanza, *args):
        """显示聊天历史, 后面可跟昵称查看某人的历史, 或跟时间查看多长时间以内的历史:1h, 2h, 1d"""
        last = " ".join(args)
        m = Logics.get_with_nick(last)
        unit_map = {"h": 3600, "m": 60, "d": 86400}
        header_map = {"h": u"小时", "m": u"分钟", "d": u"天"}
        two_hours_ago = datetime.fromtimestamp(time.time() - 7200)
        header = u"两小时以内的历史消息:"
        kwargs = {"starttime": two_hours_ago}
        if last:
            if m:
                kwargs["jid"] = m.email
                header = u"{0} 发送的历史消息:".format(m.nick)
            else:
                if last[0:-1].isdigit():
                    num, unit = int(last[0:-1]), last[-1].lower()
                    starttime = time.time() - (num * unit_map.get(unit, 3600))
                    starttime = datetime.fromtimestamp(starttime)
                    kwargs["starttime"] = starttime
                    header = u"{0} {1} 之内的历史消息:"\
                            .format(num, header_map.get(unit, u"小时"))

        histories = Logics.get_history(**kwargs)
        bodys = [header]
        for history in histories:
            bodys.append(u"{0} [{1}] {2}".format(
                nicetime(history.get("pubdate")),
                history.get("from_member", {}).get("nick"),
                history.get("content")))

        self._send_cmd_result(stanza, "\n".join(bodys))
Exemplo n.º 2
0
    def old(self, stanza, *args):
        """显示聊天历史, 后面可跟昵称查看某人的历史, 或跟时间查看多长时间以内的历史:1h, 2h, 1d"""
        last = " ".join(args)
        m = Logics.get_with_nick(last)
        unit_map = {"h":3600, "m":60, "d":86400}
        header_map = {"h":u"小时", "m":u"分钟", "d":u"天"}
        two_hours_ago = datetime.fromtimestamp(time.time() - 7200)
        header = u"两小时以内的历史消息:"
        kwargs = {"starttime":two_hours_ago}
        if last:
            if m:
                kwargs["jid"] = m.email
                header = u"{0} 发送的历史消息:".format(m.nick)
            else:
                if last[0:-1].isdigit():
                    num, unit = int(last[0:-1]), last[-1].lower()
                    starttime = time.time() - (num * unit_map.get(unit, 3600))
                    starttime = datetime.fromtimestamp(starttime)
                    kwargs["starttime"] = starttime
                    header = u"{0} {1} 之内的历史消息:"\
                            .format(num, header_map.get(unit, u"小时"))

        histories = Logics.get_history(**kwargs)
        bodys = [header]
        for history in histories:
            bodys.append(u"{0} [{1}] {2}".format(nicetime(history.get("pubdate")),
                                                 history.get("from_member", {}).get("nick"),
                                                 history.get("content")))

        self._send_cmd_result(stanza, "\n".join(bodys))
Exemplo n.º 3
0
    def whois(self, stanza, *args):
        """ 查询用户信息 """
        nick = ' '.join(args[0:])
        m = Logics.get_with_nick(nick, status = True, infos = True,
                                 history = True)
        if not m:
            self._send_cmd_result(stanza, u"{0} 用户不存在".format(nick))
            return
        bodys = []
        sts = [status.statustext for status in m.status if status.statustext]
        status_text = u""
        if "away" in sts:
            status_text = u"「离开」"

        if "dnd" in sts:
            status_text = u"「忙碌」"

        isonline = bool([status.status for status in m.status
                        if status.status])
        status = u"在线"+status_text 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 != None 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(nicetime(last_say)))
        bodys.append(u"加入时间: {0}".format(nicetime(m.join_date)))
        bodys.append(u"更改昵称次数: {0}".format(change_times))
        bodys.append(u"上次更改时间: {0}".format(nicetime(last_change)))
        bodys.append(u"是否接受消息: {0}".format(is_rece))
        honor = Logics.get_honor_str(m)
        if honor:
            bodys.append(u"成就:")
            bodys.append(honor)
        self._send_cmd_result(stanza, "\n".join(bodys))
Exemplo n.º 4
0
    def whois(self, stanza, *args):
        """ 查询用户信息 """
        nick = ' '.join(args[0:])
        m = Logics.get_with_nick(nick, status=True, infos=True, history=True)
        if not m:
            self._send_cmd_result(stanza, u"{0} 用户不存在".format(nick))
            return
        bodys = []
        sts = [status.statustext for status in m.status if status.statustext]
        status_text = u""
        if "away" in sts:
            status_text = u"「离开」"

        if "dnd" in sts:
            status_text = u"「忙碌」"

        isonline = bool(
            [status.status for status in m.status if status.status])
        status = u"在线" + status_text 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 != None 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(nicetime(last_say)))
        bodys.append(u"加入时间: {0}".format(nicetime(m.join_date)))
        bodys.append(u"更改昵称次数: {0}".format(change_times))
        bodys.append(u"上次更改时间: {0}".format(nicetime(last_change)))
        bodys.append(u"是否接受消息: {0}".format(is_rece))
        honor = Logics.get_honor_str(m)
        if honor:
            bodys.append(u"成就:")
            bodys.append(honor)
        self._send_cmd_result(stanza, "\n".join(bodys))
Exemplo n.º 5
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', '')
Exemplo n.º 6
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', '')