コード例 #1
0
ファイル: channel_msg.py プロジェクト: zrt/channel-helper-bot
def add_comment(bot, chat_id, message_id, msg_content):
    # Prepare Keyboard
    motd_keyboard = [[
        InlineKeyboardButton(
            helper_global.value("add_comment", "Add Comment"),
            url="http://telegram.me/%s?start=add_%d_%d" % (helper_global.value('bot_username', ''), chat_id, message_id)
        ),
        InlineKeyboardButton(
            helper_global.value("add_anonymous_comment", "Add Anonymous Comment"),
            url="http://telegram.me/%s?start=addanonymous_%d_%d" % (helper_global.value('bot_username', ''), chat_id, message_id)
        ),
        InlineKeyboardButton(
            helper_global.value("show_all_comments", "Show All"),
            url="http://telegram.me/%s?start=show_%s_%d" % (helper_global.value('bot_username', ''), chat_id, message_id)
        )
    ]]
    motd_markup = InlineKeyboardMarkup(motd_keyboard)

    config = helper_database.get_channel_config(chat_id)
    if config is None:
        return
    recent = config[3]
    records = helper_database.get_recent_records(chat_id, message_id, recent)

    comment_message = bot.send_message(
        chat_id=chat_id, 
        text=msg_content+'\n'+helper_global.records_to_str(records), 
        reply_to_message_id=message_id,
        reply_markup=motd_markup, 
        parse_mode=telegram.ParseMode.HTML
    ).result()
    helper_database.add_reflect(chat_id, message_id, comment_message.message_id)
コード例 #2
0
ファイル: channel_msg.py プロジェクト: artxia/backup
def add_comment(bot, chat_id, config, message_id, media_group_id=None):
    logger = Logger.logger
    logger.msg(
        {
            "channel_id": chat_id,
            "msg_id": message_id,
            "action": "normal comment"
        },
        tag="channel",
        log_level=80)
    channel_lang = config[1]
    recent = config[3]

    if helper_database.check_reflect(chat_id, message_id):
        return

    # Avoid duplicated comment for media group
    if media_group_id:
        last_media_group = helper_global.value(
            str(chat_id) + '_last_media_group', '0')
        # print(last_media_group)
        if last_media_group == media_group_id:
            return
        helper_global.assign(
            str(chat_id) + '_last_media_group', media_group_id)

    # Prepare Keyboard
    motd_keyboard = [[
        InlineKeyboardButton(
            helper_global.value("add_comment",
                                "Add Comment",
                                lang=channel_lang),
            url="http://telegram.me/%s?start=add_%d_%d" %
            (helper_global.value('bot_username', ''), chat_id, message_id)),
        InlineKeyboardButton(
            helper_global.value("show_all_comments",
                                "Show All",
                                lang=channel_lang),
            url="http://telegram.me/%s?start=show_%s_%d" %
            (helper_global.value('bot_username', ''), chat_id, message_id))
    ]]
    motd_markup = InlineKeyboardMarkup(motd_keyboard)

    records = helper_database.get_recent_records(chat_id, message_id, recent)

    comment_message = bot.send_photo(
        photo=open(sys.path[0] + "/default-comment.jpg", "rb"),
        caption=helper_global.records_to_str(records, channel_lang),
        chat_id=chat_id,
        reply_to_message_id=message_id,
        reply_markup=motd_markup,
        parse_mode=telegram.ParseMode.HTML).result()
    helper_database.add_reflect(chat_id, message_id,
                                comment_message.message_id)
コード例 #3
0
def add_inplace_comment(bot, chat_id, config, message_id, message, buttons):
    logger = Logger.logger
    logger.msg(
        {
            "channel_id": chat_id,
            "msg_id": message_id,
            "action": "inplace comment"
        },
        tag="channel",
        log_level=80)
    channel_lang = config[1]

    # Fallback media group message
    if message.media_group_id:
        return

    if message.forward_from or message.forward_from_chat:
        new_message = deforward(bot, message, channel_lang)
        message_id = new_message.message_id
        message = new_message

    # Prepare Keyboard
    if buttons and len(buttons) > 0:
        helper_database.add_button_options(chat_id, message_id, buttons)
        helper_database.clear_reaction(chat_id, message_id)

    motd_keyboard = [[
        InlineKeyboardButton(
            value, callback_data="like,%s,%s,%d" % (chat_id, message_id, idx))
        for idx, value in enumerate(buttons)
    ]] + ([[
        InlineKeyboardButton(
            helper_global.value(
                "add_comment", "Add Comment", lang=channel_lang),
            url="http://telegram.me/%s?start=add_%d_%d" %
            (helper_global.value('bot_username', ''), chat_id, message_id)),
        InlineKeyboardButton(
            helper_global.value(
                "show_all_comments", "Show All", lang=channel_lang),
            url="http://telegram.me/%s?start=show_%s_%d" %
            (helper_global.value('bot_username', ''), chat_id, message_id))
    ]])
    motd_markup = InlineKeyboardMarkup(motd_keyboard)

    try:
        bot.edit_message_reply_markup(chat_id=chat_id,
                                      message_id=message_id,
                                      reply_markup=motd_markup).result()
    except:
        return
    helper_database.add_reflect(
        chat_id, message_id,
        avoidNone(message.caption if message.caption else message.text))
コード例 #4
0
def private_msg(bot, update):
    message = update.edited_message if update.edited_message else update.message
    # print(message)
    chat_id = message.chat_id

    args = helper_global.value(str(chat_id) + "_status", "0,0")
    params = args.split(",")
    channel_id = int(params[0])
    msg_id = int(params[1])
    if channel_id == 0:
        if msg_id == 1:
            check_channel_message(bot, message)
        return

    # Check comment message
    comment_exist = helper_database.check_reflect(channel_id, msg_id)
    if not comment_exist:
        config = helper_database.get_channel_config(channel_id)
        if config is None:
            return
        recent = config[3]
        records = helper_database.get_recent_records(channel_id, msg_id,
                                                     recent)

        comment_message = bot.send_message(
            chat_id=channel_id,
            text=helper_global.records_to_str(records),
            reply_to_message_id=msg_id,
            parse_mode=telegram.ParseMode.HTML).result()
        helper_database.add_reflect(channel_id, msg_id,
                                    comment_message.message_id)
        bot.edit_message_reply_markup(chat_id=channel_id,
                                      message_id=msg_id,
                                      reply_markup=None)

    result = add_record(channel_id, msg_id, message)

    # Update Dirty List
    lock.acquire()
    dirty_list = helper_global.value("dirty_list", [])
    if not (channel_id, msg_id) in dirty_list:
        dirty_list.append((channel_id, msg_id))
    helper_global.assign("dirty_list", dirty_list)
    lock.release()

    if result == 0:
        bot.send_message(chat_id=chat_id,
                         text=helper_global.value("comment_success",
                                                  "Success!"))
    elif result == 1:
        bot.send_message(chat_id=chat_id,
                         text=helper_global.value("comment_edit_success",
                                                  "Success!"))
コード例 #5
0
def add_comment(bot, chat_id, config, message_id, media_group_id=None):
    channel_lang = config[1]
    recent = config[3]

    # Avoid duplicated comment for media group
    if media_group_id:
        last_media_group = helper_global.value(
            str(chat_id) + '_last_media_group', '0')
        print(last_media_group)
        if last_media_group == media_group_id:
            return
        helper_global.assign(
            str(chat_id) + '_last_media_group', media_group_id)

    # Prepare Keyboard
    motd_keyboard = [[
        InlineKeyboardButton(
            helper_global.value("add_comment",
                                "Add Comment",
                                lang=channel_lang),
            url="http://telegram.me/%s?start=add_%d_%d" %
            (helper_global.value('bot_username', ''), chat_id, message_id)),
        InlineKeyboardButton(
            helper_global.value("show_all_comments",
                                "Show All",
                                lang=channel_lang),
            url="http://telegram.me/%s?start=show_%s_%d" %
            (helper_global.value('bot_username', ''), chat_id, message_id))
    ]]
    motd_markup = InlineKeyboardMarkup(motd_keyboard)

    records = helper_database.get_recent_records(chat_id, message_id, recent)

    comment_message = bot.send_message(
        chat_id=chat_id,
        text=helper_global.records_to_str(records, channel_lang),
        reply_to_message_id=message_id,
        reply_markup=motd_markup,
        parse_mode=telegram.ParseMode.HTML).result()
    helper_database.add_reflect(chat_id, message_id,
                                comment_message.message_id)
コード例 #6
0
def private_msg(bot, update):
    logger = Logger.logger
    message = update.edited_message if update.edited_message else update.message
    chat_id = message.chat_id
    args = helper_global.value(str(chat_id) + "_status", "0,0")
    logger.msg({
        "user_id": chat_id,
        "status": args
    },
               tag="private",
               log_level=90)

    params = args.split(",")
    channel_id = int(params[0])
    msg_id = int(params[1])
    if channel_id == 0:
        if msg_id == 1:
            check_channel_message(bot, message)
        return

    # Check comment message
    comment_exist = helper_database.check_reflect(channel_id, msg_id)
    config = helper_database.get_channel_config(channel_id)
    if config is None:
        return
    channel_lang = config[1]
    recent, username, admin_id, notify = config[3], config[4], config[
        5], config[6]
    logger.msg(
        {
            "user_id": chat_id,
            "channel_id": channel_id,
            "msg_id": msg_id,
            "action": "add comment"
        },
        tag="private",
        log_level=90)

    # For Auto Mode = 2
    if not comment_exist:
        logger.msg(
            {
                "user_id": chat_id,
                "channel_id": channel_id,
                "msg_id": msg_id,
                "action": "add comment area"
            },
            tag="private",
            log_level=80)
        comment_message = bot.send_message(
            chat_id=channel_id,
            text=helper_global.value("comment_refreshing",
                                     "Refreshing...",
                                     lang=channel_lang),
            reply_to_message_id=msg_id,
            parse_mode=telegram.ParseMode.HTML).result()
        helper_database.add_reflect(channel_id, msg_id,
                                    comment_message.message_id)
        #bot.edit_message_reply_markup(
        #    chat_id=channel_id,
        #    message_id=msg_id,
        #    reply_markup=None
        #)
        update_dirty_msg(channel_id, msg_id, update_mode=0)

    result = add_record(bot, channel_id, msg_id, message)

    # Update Dirty List
    update_dirty_msg(channel_id, msg_id)
    if notify == 1 and not int(chat_id) == int(admin_id):
        logger.msg(
            {
                "user_id": chat_id,
                "channel_id": channel_id,
                "msg_id": msg_id,
                "admin_id": admin_id,
                "action": "notify channel owner"
            },
            tag="private",
            log_level=80)
        reply_markup = [[
            InlineKeyboardButton(
                helper_global.value("add_comment",
                                    "Add Comment",
                                    lang=channel_lang),
                url="http://telegram.me/%s?start=add_%d_%d" %
                (helper_global.value('bot_username', ''), channel_id, msg_id)),
        ]]
        if username is not None:
            bot.send_message(
                chat_id=admin_id,
                text=helper_global.value("new_comment_message",
                                         "You have a new comment message.",
                                         lang=channel_lang) + "\n---\n" +
                message + "\n---\n" +
                helper_global.value("target_message", "", lang=channel_lang) +
                "https://t.me/%s/%d" % (username, msg_id),
                reply_markup=reply_markup)
        else:
            link_id = abs(channel_id) % 10000000000
            bot.send_message(
                chat_id=admin_id,
                text=helper_global.value("new_comment_message",
                                         "You have a new comment message.",
                                         lang=channel_lang) + "\n---\n" +
                message + "\n---\n" +
                helper_global.value("target_message", "", lang=channel_lang) +
                "https://t.me/c/%d/%d" % (link_id, msg_id),
                reply_markup=reply_markup)

    if result == 0:
        bot.send_message(chat_id=chat_id,
                         text=helper_global.value("comment_success",
                                                  "Success!",
                                                  lang=channel_lang))
    elif result == 1:
        bot.send_message(chat_id=chat_id,
                         text=helper_global.value("comment_edit_success",
                                                  "Success!",
                                                  lang=channel_lang))
コード例 #7
0
def private_msg(bot, update):
    message = update.edited_message if update.edited_message else update.message
    # print(message)
    chat_id = message.chat_id

    args = helper_global.value(str(chat_id) + "_status", "0,0")
    params = args.split(",")
    channel_id = int(params[0])
    msg_id = int(params[1])
    if channel_id == 0:
        if msg_id == 1:
            check_channel_message(bot, message)
        return

    # Check comment message
    comment_exist = helper_database.check_reflect(channel_id, msg_id)
    config = helper_database.get_channel_config(channel_id)
    if config is None:
        return
    channel_lang = config[1]
    recent, username, admin_id, notify = config[3], config[4], config[
        5], config[6]
    if not comment_exist:
        records = helper_database.get_recent_records(channel_id, msg_id,
                                                     recent)

        comment_message = bot.send_message(
            chat_id=channel_id,
            text=helper_global.records_to_str(records, channel_lang),
            reply_to_message_id=msg_id,
            parse_mode=telegram.ParseMode.HTML).result()
        helper_database.add_reflect(channel_id, msg_id,
                                    comment_message.message_id)
        bot.edit_message_reply_markup(chat_id=channel_id,
                                      message_id=msg_id,
                                      reply_markup=None)

    result = add_record(channel_id, msg_id, message)

    # Update Dirty List
    lock.acquire()
    dirty_list = helper_global.value("dirty_list", [])
    if not (channel_id, msg_id) in dirty_list:
        dirty_list.append((channel_id, msg_id))
        if notify == 1 and not int(chat_id) == int(admin_id):
            if username is not None:
                bot.send_message(
                    chat_id=admin_id,
                    text=helper_global.value("new_comment_message",
                                             "You have a new comment message.",
                                             lang=channel_lang) + "\n" +
                    helper_global.value(
                        "target_message", "", lang=channel_lang) +
                    "https://t.me/%s/%d" % (username, msg_id))
            else:
                bot.send_message(chat_id=admin_id,
                                 text=helper_global.value(
                                     "new_comment_message",
                                     "You have a new comment message.",
                                     lang=channel_lang))
    helper_global.assign("dirty_list", dirty_list)
    lock.release()

    if result == 0:
        bot.send_message(chat_id=chat_id,
                         text=helper_global.value("comment_success",
                                                  "Success!",
                                                  lang=channel_lang))
    elif result == 1:
        bot.send_message(chat_id=chat_id,
                         text=helper_global.value("comment_edit_success",
                                                  "Success!",
                                                  lang=channel_lang))