示例#1
0
def make_creation_date_selection_keyboard() -> InlineKeyboardMarkup:
    months = {"1 month": 1, "2 months": 2, "3 months": 3, "6 months": 6}

    buttons = [[
        InlineKeyboardButton(
            text=text,
            callback_data=f"creationdate_{month}",
        ) for text, month in chunk.items()
    ] for chunk in dict_chunks(months, 2)]

    buttons[-1].append(
        InlineKeyboardButton(text="🔙 Go back", callback_data="main"))
    keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

    return keyboard
示例#2
0
    async def send(self, challenge) -> Message:
        scheme = os.getenv("WEB_SERVER_SCHEME")
        port = os.getenv("WEB_SERVER_PORT")
        alias = os.getenv("WEB_SERVER_ALIAS")

        host = f"{scheme}://{alias or os.getenv('WEB_SERVER_HOST')}"
        if port != 80 and not alias:
            host += f":{port}"

        buttons = [
            [
                InlineKeyboardButton(
                    text="Solve captcha",
                    url=f"{host}/recaptcha/{challenge.uuid}",
                ),
            ],
        ]

        keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

        return await SendMessage(
            chat_id=self.chat.id,
            text=
            f"🤖 {mention(self.user)}, please confirm you are *not a robot*",
            reply_markup=keyboard,
            parse_mode="Markdown",
        )
示例#3
0
    def _make_keyboard(challenge):
        buttons = [
            [
                InlineKeyboardButton(
                    text="I am a robot",
                    callback_data=f"captcha_simple_{challenge.uuid}_robot",
                ),
                InlineKeyboardButton(
                    text="I am a human",
                    callback_data=f"captcha_simple_{challenge.uuid}_human",
                ),
            ],
        ]
        random.shuffle(buttons)

        return InlineKeyboardMarkup(inline_keyboard=buttons)
示例#4
0
    async def send(self, challenge):
        emoji_challenge = await self.make_emoji_image()

        challenge.correct_emoji_answer = emoji_challenge.emoji_sequence.correct_emoji
        await challenge.commit()

        image_bytesio = BytesIO()
        emoji_challenge.image.save(image_bytesio, format="PNG")
        image_bytesio_value = image_bytesio.getvalue()

        buttons = [[
            InlineKeyboardButton(
                text=variant,
                callback_data=f"captcha_emoji_{challenge.uuid}_{variant}",
            ) for variant in emoji_challenge.emoji_sequence.other_emojis
        ]]
        keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

        return await SendPhoto(
            chat_id=self.chat.id,
            photo=BufferedInputFile(file=image_bytesio_value,
                                    filename="captcha.png"),
            caption=
            f"🤖 {mention(self.user)}, please select the *matching* emoji!",
            parse_mode="Markdown",
            reply_markup=keyboard,
        )
示例#5
0
def make_punishment_selection_keyboard(
        violation_type: str) -> InlineKeyboardMarkup:
    menu = {**punishments_selection_menu_display_name, "🔙 Go back": "main"}

    buttons = [[
        InlineKeyboardButton(text=k, callback_data=f"{violation_type}_{v}")
        for k, v in chunk.items()
    ] for chunk in dict_chunks(menu, 2)]
    keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

    return keyboard
示例#6
0
def make_captcha_type_selection_keyboard(
        violation_type: str) -> InlineKeyboardMarkup:
    buttons = [
        [
            InlineKeyboardButton(
                text="Simple",
                callback_data=f"{violation_type}_captcha_simple"),
            InlineKeyboardButton(
                text="Emoji", callback_data=f"{violation_type}_captcha_emoji"),
        ],
        [
            InlineKeyboardButton(
                text="ReCaptcha",
                callback_data=f"{violation_type}_captcha_recaptcha"),
            InlineKeyboardButton(text=go_back, callback_data=violation_type),
        ],
    ]
    keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

    return keyboard
示例#7
0
def make_violation_selection_keyboard(
    punishments: List[Punishment], ) -> InlineKeyboardMarkup:
    buttons = [[
        InlineKeyboardButton(
            text=
            f"{violations_display_name[punishment.name]} - {punishments_main_menu_display_name[punishment.type]}",
            callback_data=punishment.name,
        ) for punishment in chunk
    ] for chunk in chunks(punishments, 2)]
    keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

    return keyboard
示例#8
0
def make_mute_time_selection_keyboard(
        violation_type: str) -> InlineKeyboardMarkup:
    time = {
        "5 minutes": 5,
        "10 minutes": 10,
        "30 minutes": 30,
        "1 hour": 60,
        "2 hours": 120,
    }

    buttons = [[
        InlineKeyboardButton(
            text=text,
            callback_data=f"{violation_type}_mute_{minutes}",
        ) for text, minutes in chunk.items()
    ] for chunk in dict_chunks(time, 3)]

    buttons[-1].append(
        InlineKeyboardButton(text=go_back, callback_data=violation_type))
    keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)

    return keyboard
示例#9
0
async def start(message: types.Message):
    if message.chat.type in ["group", "supergroup"]:
        return

    me = await get_me()
    add_to_chat = InlineKeyboardButton(
        text="Add to chat", url=f"https://t.me/{me.username}?startgroup=start")
    keyboard = InlineKeyboardMarkup(inline_keyboard=[[add_to_chat]])

    await message.answer(
        "👋 *Hi there!* I can offer advanced protection for you Telegram chat. Add me to a chat or check out my source code: https://github.com/crinny/gatee",
        reply_markup=keyboard,
    )
示例#10
0
async def make_settings_menu_keyboard(
    chat_id: int,
) -> Optional[types.InlineKeyboardMarkup]:
    chat = await Chat.get_chat(chat_id)

    if chat is None:
        return

    settings: ChatSettings = chat.settings
    punishments = settings.sort_punishments_by_weight(
        ignore_none_punishments=False, sort_by_length=True
    )

    keyboard = make_violation_selection_keyboard(punishments)
    keyboard.inline_keyboard[-1].append(
        InlineKeyboardButton(
            text="📅 Creation date settings", callback_data="CreationDateSettings"
        )
    )

    return keyboard