Example #1
0
def add_record(channel_id, msg_id, message, anonymous):
    user = message.from_user
    username = user.username
    name = user.first_name
    if user.last_name:
        name += " " + user.last_name
    if anonymous:
        name = 'nobody'
    date = message.date.strftime("%Y-%m-%d %H:%M:%S")

    msg_type = "text"
    msg_content = ""
    media_id = ""
    if message.text:
        msg_type = "text"
        msg_content = message.text
    elif message.sticker:
        msg_type = 'sticker'
        media_id = message.sticker.file_id
        if message.sticker.emoji:
            msg_content = message.sticker.emoji
    elif message.photo:
        msg_type = 'photo'
        media_id = message.photo[-1].file_id
        if message.caption:
            msg_content = message.caption
    elif message.video:
        msg_type = 'video'
        media_id = message.video.file_id
        if message.caption:
            msg_content = message.caption
    elif message.document:
        msg_type = 'document'
        media_id = message.document.file_id
        if message.document.file_name:
            msg_content = message.document.file_name
    elif message.audio:
        msg_type = 'audio'
        media_id = message.audio.file_id
        if message.audio.title:
            msg_content = message.audio.title
    elif message.voice:
        msg_type = 'voice'
        media_id = message.voice.file_id

    helper_database.add_record(channel_id, msg_id, username, name, msg_type,
                               msg_content, media_id, date)
Example #2
0
def add_record(channel_id, msg_id, message):
    ori_msg_id = message.message_id
    user = message.from_user
    username = user.username
    user_id = user.id
    name = user.first_name
    if user.last_name:
        name += " " + user.last_name
    date = message.date.strftime("%Y-%m-%d %H:%M:%S")

    msg_type = "text"
    msg_content = ""
    media_id = ""
    if message.text:
        msg_type = "text"
        msg_content = message.text
    elif message.sticker:
        msg_type = 'sticker'
        media_id = message.sticker.file_id
        if message.sticker.emoji:
            msg_content = message.sticker.emoji
    elif message.photo:
        msg_type = 'photo'
        media_id = message.photo[-1].file_id
        if message.caption:
            msg_content = message.caption
    elif message.video:
        msg_type = 'video'
        media_id = message.video.file_id
        if message.caption:
            msg_content = message.caption
    elif message.document:
        msg_type = 'document'
        media_id = message.document.file_id
        if message.document.file_name:
            msg_content = message.document.file_name
    elif message.audio:
        msg_type = 'audio'
        media_id = message.audio.file_id
        if message.audio.title:
            msg_content = message.audio.title
    elif message.voice:
        msg_type = 'voice'
        media_id = message.voice.file_id

    msg_content = helper_global.parse_entity(msg_content, message.entities)

    return helper_database.add_record(channel_id, msg_id, username, name,
                                      msg_type, msg_content, media_id, date,
                                      user_id, ori_msg_id)
def add_record(bot, channel_id, msg_id, message):
    logger = Logger.logger
    ori_msg_id = message.message_id
    user = message.from_user
    username = user.username
    user_id = user.id
    name = user.first_name
    if user.last_name:
        name += " " + user.last_name
    date = message.date.strftime("%Y-%m-%d %H:%M:%S")

    msg_type = "text"
    msg_content = ""
    media_id = ""
    if message.text:
        msg_type = "text"
        msg_content = message.text
    elif message.sticker:
        msg_type = 'sticker'
        media_id = message.sticker.file_id
        if message.sticker.emoji:
            msg_content = message.sticker.emoji
    elif message.photo:
        msg_type = 'photo'
        media_id = message.photo[-1].file_id
        if message.caption:
            msg_content = message.caption
    elif message.video:
        msg_type = 'video'
        media_id = message.video.file_id
        if message.caption:
            msg_content = message.caption
    elif message.document:
        msg_type = 'document'
        media_id = message.document.file_id
        if message.document.file_name:
            msg_content = message.document.file_name
    elif message.audio:
        msg_type = 'audio'
        media_id = message.audio.file_id
        if message.audio.title:
            msg_content = message.audio.title
    elif message.voice:
        msg_type = 'voice'
        media_id = message.voice.file_id

    msg_content = helper_global.parse_entity(msg_content, message.entities)

    if message.reply_markup and message.reply_markup.inline_keyboard:
        keyboard = message.reply_markup.inline_keyboard
        if len(keyboard) > 0 and len(keyboard[0]) > 0:
            query = keyboard[0][0]
            if query.callback_data:
                args = query.callback_data.split(",")
                if len(args) == 4 and args[0] == "notify":
                    target_channel_id = int(args[1])
                    target_msg_id = int(args[2])
                    target_row_id = args[3]
                    record = helper_database.get_record_by_rowid(target_row_id)
                    if len(record) > 0 and target_channel_id == int(
                            record[0][0]) and target_msg_id == int(
                                record[0][1]):
                        target_name = record[0][3]
                        target_user_id = record[0][8]
                        config = helper_database.get_channel_config(channel_id)
                        if config is None:
                            return
                        channel_lang, channel_username = config[1], config[4]
                        msg_content = "<b>(➤%s) </b> " % target_name.replace(
                            '<', '&lt;').replace('>', '&gt;') + msg_content
                        if channel_username is not None:
                            logger.msg(
                                {
                                    "channel_id": channel_id,
                                    "msg_id": msg_id,
                                    "target_user": target_user_id,
                                    "action": "notify reply"
                                },
                                tag="private",
                                log_level=80)
                            bot.send_message(
                                chat_id=target_user_id,
                                text=helper_global.value(
                                    "new_reply_message",
                                    "You receive a reply message.",
                                    lang=channel_lang) + "\n" +
                                helper_global.value(
                                    "target_message", "", lang=channel_lang) +
                                "https://t.me/%s/%d" %
                                (channel_username, target_msg_id))
                        else:
                            link_id = abs(channel_id) % 10000000000
                            bot.send_message(
                                chat_id=target_user_id,
                                text=helper_global.value(
                                    "new_reply_message",
                                    "You receive a reply message.",
                                    lang=channel_lang) + "\n" +
                                helper_global.value(
                                    "target_message", "", lang=channel_lang) +
                                "https://t.me/c/%d/%d" %
                                (link_id, target_msg_id))

    return helper_database.add_record(channel_id, msg_id, username, name,
                                      msg_type, msg_content, media_id, date,
                                      user_id, ori_msg_id)