def test_from_button(self):
        reply_keyboard_markup = ReplyKeyboardMarkup.from_button(
            KeyboardButton(text='button1')).keyboard
        assert len(reply_keyboard_markup) == 1
        assert len(reply_keyboard_markup[0]) == 1

        reply_keyboard_markup = ReplyKeyboardMarkup.from_button('button1').keyboard
        assert len(reply_keyboard_markup) == 1
        assert len(reply_keyboard_markup[0]) == 1
Пример #2
0
def on_start(update: Update, context: CallbackContext):
    reply_markup = ReplyKeyboardMarkup.from_button('Подкинуть монетку',
                                                   resize_keyboard=True)

    update.effective_message.reply_html(
        'Тыкни на "Подкинуть монетку" :)',
        reply_markup=reply_markup,
    )
Пример #3
0
def reply_help(update: Update, context: CallbackContext):
    reply_markup = ReplyKeyboardMarkup.from_button(text_of.BTN_TO_SELECT_BOOKS,
                                                   resize_keyboard=True)

    update.effective_message.reply_html(
        text_of.WELCOME,
        reply_markup=reply_markup,
    )
Пример #4
0
def phone_number(update: Update, context: CallbackContext) -> str:
    """
    Parses the reply for the privacy settings.

    Args:
        update: The update.
        context: The context as provided by the :class:`telegram.ext.Dispatcher`.

    Returns:
        :attr:`PHONE_NUMBER`: If the processing of the phone number is not yet finished.
        :attr:`MENU`: Else
    """
    orchestra = context.bot_data[ORCHESTRA_KEY]
    member = get_member(update, context)
    message = update.effective_message

    if update.message:
        number = update.message.contact.phone_number
        if number.startswith('49'):
            number = f'+{number}'
        member.phone_number = number
        orchestra.update_member(member)

        msg = message.reply_text('Danke!', reply_markup=ReplyKeyboardRemove())
        msg.delete()
        message.reply_text(
            text=TEXTS[MENU].format(member.to_str()), reply_markup=selection_keyboard(context)
        )

        return MENU

    update.callback_query.answer()
    data = update.callback_query.data

    if data == DELETE:
        member.phone_number = None
        orchestra.update_member(member)
        message.edit_text(
            text=TEXTS[MENU].format(member.to_str()), reply_markup=selection_keyboard(context)
        )

        return MENU

    if data == BACK:
        message.edit_text(
            text=TEXTS[MENU].format(member.to_str()), reply_markup=selection_keyboard(context)
        )

        return MENU

    delete_keyboard(context)
    text = 'Bitte nutze den Knopf unten, um mir Deine Nummer als Kontakt zu senden.'
    markup = ReplyKeyboardMarkup.from_button(
        KeyboardButton('Kontakt senden', request_contact=True)
    )
    message.reply_text(text=text, reply_markup=markup)

    return PHONE_NUMBER
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Send a message with a button that opens a the web app."""
    await update.message.reply_text(
        "Please press the button below to choose a color via the WebApp.",
        reply_markup=ReplyKeyboardMarkup.from_button(
            KeyboardButton(
                text="Open the color picker!",
                web_app=WebAppInfo(
                    url="https://python-telegram-bot.org/static/webappbot"),
            )),
    )
Пример #6
0
 def notifiche(self, notifiche_attive):
     na = (str(notifiche_attive[0][0]) == 'si')
     stato_notifiche = 'sono attive' if na else 'non sono attive'
     self.message.reply_text(
         'Le notifiche *{}*. {}'.format(stato_notifiche, ANNULLA),
         parse_mode='Markdown',
         reply_markup=ReplyKeyboardMarkup.from_button(
             'Disattiva' if na else 'Attiva',
             resize_keyboard=True, one_time_keyboard=True
         ),
         quote=False
     )
Пример #7
0
def next_turn(context):
    try:
        game = context.bot_data['game']
        explainer, guesser = game.next_turn()
        context.bot_data['explainer'] = explainer[0]
        broadcast(
            context, "Сейчас объясняет @{}, отгадывает @{}".format(
                explainer[1], guesser[1]))
        context.bot.send_message(
            chat_id=explainer[0],
            text=
            "Твоя очередь объяснять, отгадывает @{}. Нажми кнопку по готовности."
            .format(guesser[1]),
            reply_markup=ReplyKeyboardMarkup.from_button(
                START_BUTTON_TEXT,
                resize_keyboard=True,
                one_time_keyboard=True),
        )
    except StopIteration:
        finish_game(context)
Пример #8
0
def get_contact_view():
    button = KeyboardButton("Отправить номер", request_contact=True, one_time_keyboard=True)
    reply_markup = ReplyKeyboardMarkup.from_button(button, resize_keyboard=True)
    return {
        'reply_markup': reply_markup,
        'text': 'Для авторизации в боте отправьте номер телефона'}
Пример #9
0
from telegram import (Update, ReplyKeyboardMarkup, InlineKeyboardMarkup,
                      InlineKeyboardButton, Bot, Message, CallbackQuery)
from telegram.ext import MessageHandler, CommandHandler, CallbackContext, Filters
from telegram.ext.filters import MergedFilter

# pip install python-telegram-bot-pagination
from telegram_bot_pagination import InlineKeyboardPaginator

from config import (HELP_TEXT, ADMIN_USERNAME, TEXT_BUTTON_MORE,
                    MAX_MESSAGE_LENGTH, DIR, DIR_LOG, COMMANDS_PER_PAGE,
                    DATE_FORMAT, DATE_TIME_FORMAT)
from bot.regexp_patterns import PATTERN_HELP_COMMON, PATTERN_HELP_ADMIN, fill_string_pattern

BOT: Bot = None

REPLY_KEYBOARD_MARKUP = ReplyKeyboardMarkup.from_button(TEXT_BUTTON_MORE,
                                                        resize_keyboard=True)

FILTER_BY_ADMIN = Filters.user(username=ADMIN_USERNAME)

COMMON_COMMANDS: List[str] = []
ADMIN_COMMANDS: List[str] = []

START_TIME = DT.datetime.now()


def split_list(items: List, columns: int = 5) -> List[List]:
    result = []

    for i in range(0, len(items), columns):
        result.append([key for key in items[i:i + columns]])