Ejemplo n.º 1
0
def help_callback(update: Update, context: CallbackContext) -> None:
    """ Link to rules readme """
    message = cast(Message, update.effective_message)
    text = (
        f"You can find an explanation of @{html.escape(context.bot.username)}'s functionality "
        'wiki on <a href="https://github.com/python-telegram-bot/rules-bot/blob/master/README.md">'
        "GitHub</a>.")
    message.reply_text(
        text,
        quote=False,
        reply_to_message_id=get_reply_id(update),
    )
    try_to_delete(message)
Ejemplo n.º 2
0
def off_on_topic(update: Update, context: CallbackContext) -> None:
    message = cast(Message, update.effective_message)
    chat_username = cast(Chat, update.effective_chat).username
    group_one = cast(Match, context.match).group(1)
    if chat_username == ONTOPIC_USERNAME and group_one.lower() == 'off':
        reply = message.reply_to_message
        moved_notification = 'I moved this discussion to the [off-topic Group]({}).'
        if reply and reply.text:
            issued_reply = get_reply_id(update)

            if reply.from_user:
                if reply.from_user.username:
                    name = '@' + reply.from_user.username
                else:
                    name = reply.from_user.first_name
            else:
                name = 'Somebody'

            replied_message_text = reply.text_html
            replied_message_id = reply.message_id

            text = (
                f'{name} <a href="t.me/pythontelegrambotgroup/{replied_message_id}">wrote</a>:\n'
                f'{replied_message_text}\n\n'
                f'⬇️ ᴘʟᴇᴀsᴇ ᴄᴏɴᴛɪɴᴜᴇ ʜᴇʀᴇ ⬇️'
            )

            offtopic_msg = context.bot.send_message(OFFTOPIC_CHAT_ID, text)

            message.reply_text(
                moved_notification.format(
                    'https://telegram.me/pythontelegrambottalk/' + str(offtopic_msg.message_id)
                ),
                parse_mode=ParseMode.MARKDOWN,
                reply_to_message_id=issued_reply,
            )

        else:
            message.reply_text(
                'The off-topic group is [here](https://telegram.me/pythontelegrambottalk). '
                'Come join us!',
                parse_mode=ParseMode.MARKDOWN,
            )

    elif chat_username == OFFTOPIC_USERNAME and group_one.lower() == 'on':
        message.reply_text(
            'The on-topic group is [here](https://telegram.me/pythontelegrambotgroup). '
            'Come join us!',
            parse_mode=ParseMode.MARKDOWN,
        )
Ejemplo n.º 3
0
def wiki(update: Update, _: CallbackContext) -> None:
    """ Wiki link """
    message = cast(Message, update.effective_message)
    text = (
        "You can find our wiki on "
        "[GitHub](https://github.com/python-telegram-bot/python-telegram-bot/wiki)"
    )
    message.reply_text(
        text,
        parse_mode="Markdown",
        quote=False,
        reply_to_message_id=get_reply_id(update),
    )
    try_to_delete(message)
Ejemplo n.º 4
0
async def off_on_topic(update: Update,
                       context: ContextTypes.DEFAULT_TYPE) -> None:
    """Redirect users to the off-topic or on-topic group"""
    # Minimal effort LRU cache
    # We store the newest 64 messages that lead to redirection to minimize the chance that
    # editing a message falsely triggers the redirect again
    parsed_messages = cast(Dict, context.chat_data).setdefault(
        "redirect_messages", deque(maxlen=64))

    message = cast(Message, update.effective_message)
    if message.message_id in parsed_messages:
        return

    # Standalone on/off-topic commands don't make any sense
    # But we only delete them if they contain nothing but the command
    if not message.reply_to_message:
        entities = message.parse_entities()
        if len(entities) == 1:
            entity, text = entities.popitem()
            if entity.type == MessageEntity.BOT_COMMAND and text == message.text:
                context.application.create_task(try_to_delete(message),
                                                update=update)
        return

    chat_username = cast(Chat, update.effective_chat).username
    group_one = cast(Match, context.match).group(1)
    if chat_username == ONTOPIC_USERNAME and group_one.lower() == "off":
        reply = message.reply_to_message
        if reply.text:
            issued_reply = get_reply_id(update)

            if reply.from_user:
                if reply.from_user.username:
                    name = "@" + reply.from_user.username
                else:
                    name = reply.from_user.first_name
            else:
                # Probably never happens anyway ...
                name = "Somebody"

            replied_message_text = reply.text_html
            replied_message_id = reply.message_id

            text = (
                f'{name} <a href="t.me/{ONTOPIC_USERNAME}/{replied_message_id}">wrote</a>:\n'
                f"{replied_message_text}\n\n"
                f"⬇️ ᴘʟᴇᴀsᴇ ᴄᴏɴᴛɪɴᴜᴇ ʜᴇʀᴇ ⬇️")

            offtopic_msg = await context.bot.send_message(
                OFFTOPIC_CHAT_ID, text)

            await message.reply_text(
                text=
                ('I moved this discussion to the <a href="https://t.me/'
                 f'{OFFTOPIC_USERNAME}/{offtopic_msg.message_id}">off-topic group</a>.'
                 ),
                reply_to_message_id=issued_reply,
            )

        else:
            await message.reply_text(
                f'The off-topic group is <a href="https://t.me/{OFFTOPIC_USERNAME}">here</a>. '
                "Come join us!", )

    elif chat_username == OFFTOPIC_USERNAME and group_one.lower() == "on":
        await message.reply_text(
            f'The on-topic group is <a href="https://t.me/{ONTOPIC_USERNAME}">here</a>. '
            "Come join us!", )

    parsed_messages.append(message.message_id)
Ejemplo n.º 5
0
        # Store the message
        messages.append(hint.html_markup(None or match.group(0)))

        # Merge keyboards into one
        if entry_kb := hint.inline_keyboard:
            if keyboard is None:
                keyboard = deepcopy(entry_kb)
            else:
                keyboard.inline_keyboard.extend(entry_kb.inline_keyboard)

    effective_text = "\n➖\n".join(messages)
    await message.reply_text(
        effective_text,
        reply_markup=keyboard,
        reply_to_message_id=get_reply_id(update),
    )

    if reply_to and first_match == 0:
        await try_to_delete(message)


async def ban_sender_channels(update: Update,
                              _: ContextTypes.DEFAULT_TYPE) -> None:
    message = cast(Message, update.effective_message)
    await cast(Chat, update.effective_chat).ban_sender_chat(
        cast(Chat, message.sender_chat).id)
    await try_to_delete(message)


async def say_potato_job(context: ContextTypes.DEFAULT_TYPE) -> None: