예제 #1
0
파일: command.py 프로젝트: Jack1007/clubot
 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))
예제 #2
0
파일: command.py 프로젝트: Jack1007/clubot
    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(history.pubdate,
                                                 history.member.nick,
                                                 history.content))

        self._send_cmd_result(stanza, "\n".join(bodys))
예제 #3
0
파일: command.py 프로젝트: huahu/clubot
    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(history.pubdate,
                                                 history.member.nick,
                                                 history.content))

        self._send_cmd_result(stanza, "\n".join(bodys))
예제 #4
0
파일: command.py 프로젝트: huahu/clubot
 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))
예제 #5
0
파일: command.py 프로젝트: Jack1007/clubot
 def rm(self, stanza, *args):
     """剔除用户"""
     #XXX 没有效果
     emails = [Logics.get_with_nick(n).email for n in args]
     if len(emails) < 1: return self.help(stanza, 'rm')
     for e in emails:
         jid = JID(e)
         Logics.drop(jid)
         self._message_bus.send_unsubscribe(jid)
예제 #6
0
파일: command.py 프로젝트: huahu/clubot
 def rm(self, stanza, *args):
     """剔除用户"""
     #XXX 没有效果
     emails = [Logics.get_with_nick(n).email for n in args]
     if len(emails) < 1: return self.help(stanza, 'rm')
     for e in emails:
         jid = JID(e)
         Logics.drop(jid)
         self._message_bus.send_unsubscribe(jid)
예제 #7
0
파일: command.py 프로젝트: Jack1007/clubot
 def mt(self, stanza, *args):
     """单独给某用户发消息"""
     if len(args) <= 1: return self.help(stanza, 'msgto')
     nick = args[0]
     receiver = Logics.get_with_nick(nick = nick).email
     if receiver == stanza.from_jid.bare().as_string():
         self._send_cmd_result(stanza, "请不要自言自语")
         return
     body = ' '.join(args[1:])
     if not receiver:
         self._send_cmd_result(stanza, "%s 用户不存在" % nick)
     else:
         self._message_bus.send_private_msg(stanza, receiver, body)
예제 #8
0
파일: command.py 프로젝트: huahu/clubot
 def mt(self, stanza, *args):
     """单独给某用户发消息"""
     if len(args) <= 1: return self.help(stanza, 'msgto')
     nick = args[0]
     receiver = Logics.get_with_nick(nick=nick).email
     if receiver == stanza.from_jid.bare().as_string():
         self._send_cmd_result(stanza, "请不要自言自语")
         return
     body = ' '.join(args[1:])
     if not receiver:
         self._send_cmd_result(stanza, "%s 用户不存在" % nick)
     else:
         self._message_bus.send_private_msg(stanza, receiver, body)