示例#1
0
def publish(uuid, **kw):
     from app import app
     with app.app_context():
         params = {'uuid': uuid, 'extra': kw.pop('extra', None),
                   'type': kw.pop('type', None)}
         params.update(kw)
         sse.publish(params, type='login')
示例#2
0
def publish(uuid, **kw):
    from app import app
    with app.app_context():
        params = {'uuid': uuid, 'extra': kw.pop('extra', None),
                  'type': kw.pop('type', None)}
        params.update(kw)
        sse.publish(params, type='login')
示例#3
0
def login():
    user = get_logged_in_user(current_bot)
    from wechat.tasks import async_retrieve_data, listener
    async_retrieve_data.delay()
    listener.delay()
    sse.publish({'type': 'logged_in', 'user': user}, type='login')
    return {'msg': ''}
示例#4
0
    def send_msg(m):
        # wxpy还不支持未命名的群聊消息
        # 先忽略腾讯新闻之类发的信息
        logger.info("收到消息,接收者:{}".format(m.receiver.name))
        if m.receiver.name is None or m.sender is None:
            return
        msg_type = TYPE_TO_ID_MAP.get(m.type, 0)
        if isinstance(m.sender, Group):
            sender_id = m.member.puid
            group_id = m.chat.puid
            logger.info(
                "The message is @" if m.is_at else "The message is not @")
        elif isinstance(m.sender, _MP):
            sender_id = m.sender.puid
            group_id = 0
            msg_type = TYPE_TO_ID_MAP.get('MP')
        else:
            sender_id = m.sender.puid
            group_id = 0

        receiver_id = m.receiver.puid
        from views.api import json_api as app
        with app.app_context():
            msg = Message.create(sender_id=sender_id,
                                 receiver_id=receiver_id,
                                 content=m.text,
                                 url=m.url,
                                 type=msg_type,
                                 receive_time=m.receive_time,
                                 group_id=group_id)
            if m.type in (PICTURE, RECORDING, ATTACHMENT, VIDEO):
                _, ext = os.path.splitext(m.file_name)
                m.get_file(
                    os.path.join(UPLOAD_PATH, '{}{}'.format(msg.id, ext)))
                msg.file_ext = ext
                db.session.commit()
            Notification.add(receiver_id, msg.id)
            # 我消息
            if msg.group_id == 0 and msg.msg_type != TYPE_TO_ID_MAP.get('MP'):
                MyNotification.add(receiver_id, msg.id)
            sse.publish(Notification.get_all(), type='notification')
            # 公众号消息分发
            if isinstance(m.sender, _MP):
                for mp_id, ids in settings.mp_forward:
                    if m.sender.puid == mp_id:
                        groups = map(lambda x: bot.groups().search(puid=x)[0],
                                     ids)
                        sync_message_in_groups(m, groups)
                        return
示例#5
0
def send_notify():
    count = Notification.count_by_receiver_id(bot.self.puid)
    with sse_api.app_context():
        sse.publish({'count': count}, type='notification')
示例#6
0
def send_notify():
    count = Notification.count_by_receiver_id(bot.self.puid)
    with sse_api.app_context():
        sse.publish({'count': count}, type='notification')
示例#7
0
def login():
    user = get_logged_in_user(current_bot)
    from wechat.tasks import async_retrieve_data
    async_retrieve_data.delay()
    sse.publish({'type': 'logged_in', 'user': user}, type='login')
    return {'msg': ''}