Пример #1
0
def add_like_buttons(bot, channel_lang, config, chat_id, message_id, message,
                     buttons):
    logger = Logger.logger
    logger.msg(
        {
            "channel_id": chat_id,
            "msg_id": message_id,
            "action": "add like buttons"
        },
        tag="channel",
        log_level=80)
    flag = 1
    ref = helper_database.get_reflect_by_msg_id(chat_id, message_id)
    if ref is not None:
        flag = 0
        message_id = ref[1]

    # Fallback media group message
    if message.media_group_id:
        add_comment(bot,
                    chat_id,
                    config,
                    message_id,
                    media_group_id=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
    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))
    ]] if flag == 1 else [[]])
    motd_markup = InlineKeyboardMarkup(motd_keyboard)

    bot.edit_message_reply_markup(chat_id=chat_id,
                                  message_id=message_id,
                                  reply_markup=motd_markup)
Пример #2
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))
Пример #3
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)