Esempio n. 1
0
def send_msg(m):
    # wxpy还不支持未命名的群聊消息
    # 先忽略腾讯新闻之类发的信息
    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
    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)
def send_msg(m):
    # wxpy还不支持未命名的群聊消息
    # 先忽略腾讯新闻之类发的信息
    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
    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 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
Esempio n. 3
0
def send_msg(m):
    # wxpy还不支持未命名的群聊消息
    # 先忽略腾讯新闻之类发的信息
    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
    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(here, '../static/img/uploads',
                             '{}{}'.format(msg.id, ext)))
            msg.file_ext = ext
            db.session.commit()
        Notification.add(receiver_id, msg.id)
Esempio n. 4
0
def send_notify():
    count = Notification.count_by_receiver_id(bot.self.puid)
    with sse_api.app_context():
        sse.publish({'count': count}, type='notification')
Esempio n. 5
0
def readall():
    uid = current_bot.self.puid
    Notification.clean_by_receiver_id(uid)
    return {}
Esempio n. 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')
Esempio n. 7
0
def readall():
    uid = current_bot.self.puid
    Notification.clean_by_receiver_id(uid)
    return {}