bot.keyboards Module

This module contains functions for generating often needed keyboards.

bot.keyboards.ALL = 'Alles'

Text indicating to select all. Use as text or callback data.

Type

str

bot.keyboards.BACK = 'Zurück'

Text indicating a ‘back’ action. Use as text or callback data.

Type

str

bot.keyboards.CHANNEL_KEYBOARD = <telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup object>

Keyboard leading to the info channel and the docs.

Type

telegram.InlineKeyboardMarkup

bot.keyboards.DESELECTED = '❌'

Emoji to use to mark deselected options.

Type

str

bot.keyboards.DOCS_KEYBOARD = <telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup object>

Keyboard leading to the docs.

Type

telegram.InlineKeyboardMarkup

bot.keyboards.DONE = 'Fertig'

Text indicating a ‘done’ action. Use as text or callback data.

Type

str

bot.keyboards.REGISTRATION_KEYBOARD = <telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup object>

Keyboard that triggers the registration process.

Type

telegram.InlineKeyboardMarkup

bot.keyboards.SELECTED = '✔️'

Emoji to use to mark selected options.

Type

str

bot.keyboards.build_instruments_keyboard(current_selection=None)

Builds a telegram.InlineKeyboardMarkup listing all instruments that are up for selection. The callback data for each button will equal its text. Also appends a button with the text DONE and data DONE at the very end of the keyboard.

Parameters

current_selection (Optional[Dict[Instrument, bool]]) – Optional. If passed, gives the current selection and the keyboard will reflect that selection state. If not present, all instruments will be deselected. A corresponding dictionary is returned e.g. by parse_instruments_keyboard().

Return type

InlineKeyboardMarkup

Returns

InlineKeyboardMarkup

bot.keyboards.build_questions_hints_keyboard(orchestra, question=False, hint=False, current_selection=None, multiple_choice=True, allowed_hints=None, exclude_members=None)

Builds a telegram.InlineKeyboardMarkup listing all questions that are up for selection for the given orchestra. The callback data for each button will equal its text. Also appends a button with the text DONE and data DONE at the very end of the keyboard.

Parameters
  • orchestra (Orchestra) – The orchestra to build the keyboard for.

  • question (bool) – Optional. Set to True, if the keyboard is build for question selection.

  • hint (bool) – Optional. Set to True, if the keyboard is build for hint selection.

  • current_selection (Optional[Dict[str, bool]]) – Optional. If passed, gives the current selection and the keyboard will reflect that selection state. If not present, all options will be deselected. A corresponding dictionary is returned e.g. by parse_questions_hints_keyboard().

  • multiple_choice (bool) – Optional. Whether the questions are supposed to be multiple choice or free text. Defaults to True.

  • allowed_hints (Optional[List[str]]) – Optional. Only relevant if question is True. If passed, in this case only question attributes which are questionable for at least one of the allowed hints will be listed in the keyboard.

  • exclude_members (Optional[Iterable[Member]]) – Optional. Members to exclude from serving as hint.

Note

Exactly one on hint and question must be True.

Return type

InlineKeyboardMarkup

Returns

InlineKeyboardMarkup

Raises

RuntimeError – If the orchestra currently has no questionable attributes.

bot.keyboards.parse_instruments_keyboard(keyboard)

Parses the given keyboard and returns ad dictionary, indicating for every instrument, whether it has been selected or not.

Parameters

keyboard (InlineKeyboardMarkup) – The telegram.InlineKeyboardMarkup from an update. Buttons must have the structure as provided by build_instruments_keyboard().

Return type

Dict[Instrument, bool]

bot.keyboards.parse_questions_hints_keyboard(keyboard)

Parses the given keyboard and returns ad dictionary, indicating for every option, whether it has been selected or not.

Parameters

keyboard (InlineKeyboardMarkup) – The telegram.InlineKeyboardMarkup from an update. Buttons must have the structure as provided by build_questions_hints_keyboard().

Return type

Dict[str, bool]