Exemplo n.º 1
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]
Exemplo n.º 2
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]
Exemplo n.º 3
0
    def _tq(self, stanza, *args):
        """指定城市获取天气"""
        body = ''.join([x for x in args])
        key = cityid(body.encode('utf-8'))
        url = 'http://www.weather.com.cn/data/cityinfo/' + key + ".html"
        def readback(resp):
            load = json.loads(resp.read())
            body = 'city:%s, Weather %s, %s ~ %s' %\
                    (load['weatherinfo']['city'],
                     load['weatherinfo']['weather'],
                     load['weatherinfo']['temp1'],
                     load['weatherinfo']['temp2'])
            self._send_cmd_result(stanza, body)
            self._message_bus.send_all_msg(stanza, body)

        self._http_stream.get(url, readback = readback)
Exemplo n.º 4
0
    def _tq(self, stanza, *args):
        """指定城市获取天气"""
        body = ''.join([x for x in args])
        key = cityid(body.encode('utf-8'))
        url = 'http://www.weather.com.cn/data/cityinfo/' + key + ".html"

        def readback(resp):
            load = json.loads(resp.read())
            body = 'city:%s, Weather %s, %s ~ %s' %\
                    (load['weatherinfo']['city'],
                     load['weatherinfo']['weather'],
                     load['weatherinfo']['temp1'],
                     load['weatherinfo']['temp2'])
            self._send_cmd_result(stanza, body)
            self._message_bus.send_all_msg(stanza, body)

        self._http_stream.get(url, readback=readback)