def option_key(bot, update, key, values, lang, chat_id, origin_message_id, args):
    config = helper_database.get_channel_config(args[1])
    if config is None or len(config) == 0:
        return
    key2idx = {
        "lang": 1,
        "mode": 2,
        "recent": 3,
        "notify": 6,
        "button": 7
    }
    # Prepare Keyboard
    width = helper_const.LANG_WIDTH
    motd_keyboard = [[
        InlineKeyboardButton(
            values[idx * width + delta] + (" (*)" if str(values[idx * width + delta]) == str(config[key2idx[key]]) else ""),
            callback_data="option|%s,%s,%s,%s" % (lang, args[1], key, values[idx * width + delta])
        ) for delta in range(width)
    ] for idx in range(len(values) // width)] + [[
        InlineKeyboardButton(
            values[idx] + (" (*)" if str(values[idx]) == str(config[key2idx[key]]) else ""),
            callback_data="option|%s,%s,%s,%s" % (lang, args[1], key, values[idx])
        ) 
    for idx in range(width * (len(values) // width), len(values))]] + [[
        InlineKeyboardButton(
            helper_global.value("option_back", "", lang=lang),
            callback_data="option|%s,%s" % (lang, args[1])
        )
    ]]

    motd_markup = InlineKeyboardMarkup(motd_keyboard)

    text = helper_global.value("option_choose_%s_value" % key, "", lang=lang)
    if key == "button":
        text = text % (", ".join(helper_database.get_default_button_options(args[1])))
    bot.answer_callback_query(
        callback_query_id=update.callback_query.id
    )
    bot.edit_message_text(
        chat_id=chat_id, 
        message_id=origin_message_id,
        text=text,
        reply_markup=motd_markup
    )
Ejemplo n.º 2
0
def channel_post_msg(bot, update):
    logger = Logger.logger
    message = update.channel_post
    if message is None:
        return
    chat_id = message.chat_id
    message_id = message.message_id
    config = helper_database.get_channel_config(chat_id)
    if config is None:
        return
    lang, mode, recent, button_mode = config[1], config[2], config[3], config[
        7]

    # Manual Mode
    if message.reply_to_message is not None and message.text.startswith(
            "/comment"):
        logger.msg(
            {
                "channel_id": chat_id,
                "msg_id": message_id,
                "mode": mode,
                "button": button_mode,
                "action": "/comment"
            },
            tag="channel",
            log_level=90)
        message_id = message.reply_to_message.message_id
        bot.delete_message(chat_id=chat_id, message_id=message.message_id)
        if not helper_database.check_reflect(
                chat_id,
                message_id) and message.reply_to_message.reply_markup is None:
            add_compact_comment(bot, chat_id, config, message_id,
                                message.reply_to_message)
        if not button_mode == 0:
            buttons = message.text.split()[1:]
            if button_mode == 1 and len(buttons) == 0:
                buttons = helper_database.get_default_button_options(chat_id)
            add_like_buttons(bot, lang, config, chat_id, message_id, message,
                             buttons)

    # Force Comment for Special Cases
    elif message.reply_to_message is not None and message.text == "/forcecomment":
        logger.msg(
            {
                "channel_id": chat_id,
                "msg_id": message_id,
                "mode": mode,
                "button": button_mode,
                "action": "/forcecomment"
            },
            tag="channel",
            log_level=90)
        message_id = message.reply_to_message.message_id
        bot.delete_message(chat_id=chat_id, message_id=message.message_id)
        helper_database.delete_reflect(chat_id, message_id)
        add_compact_comment(bot, chat_id, config, message_id,
                            message.reply_to_message)

    # Set default buttons
    elif message.text is not None and message.text.startswith(
            "/defaultbuttons"):
        logger.msg(
            {
                "channel_id": chat_id,
                "msg_id": message_id,
                "mode": mode,
                "button": button_mode,
                "action": "/defaultbuttons"
            },
            tag="channel",
            log_level=90)
        buttons = message.text.split()[1:]
        bot.delete_message(chat_id=chat_id, message_id=message.message_id)
        helper_database.add_button_options(chat_id, 0, buttons)

    # Auto Comment Mode
    elif mode == 1:
        logger.msg(
            {
                "channel_id": chat_id,
                "msg_id": message_id,
                "mode": mode,
                "button": button_mode,
                "action": "new channel post"
            },
            tag="channel",
            log_level=90)
        add_comment(bot,
                    chat_id,
                    config,
                    message_id,
                    media_group_id=message.media_group_id)
        if button_mode == 1:
            add_like_buttons(
                bot, lang, config, chat_id, message_id, message,
                helper_database.get_default_button_options(chat_id))
    elif mode == 2:
        logger.msg(
            {
                "channel_id": chat_id,
                "msg_id": message_id,
                "mode": mode,
                "button": button_mode,
                "action": "new channel post"
            },
            tag="channel",
            log_level=90)
        if button_mode == 1:
            add_like_buttons(
                bot, lang, config, chat_id, message_id, message,
                helper_database.get_default_button_options(chat_id))
        else:
            add_compact_comment(bot, chat_id, config, message_id, message)