Esempio n. 1
0
 def create_default_kb(
     cls,
     actions: List[Union[str, Dict[str, Union[str, bool]]]],
     schema: List[int],
 ) -> ReplyKeyboardMarkup:
     kb = ReplyKeyboardMarkup()
     kb.row_width = max(schema)
     buttons = []
     for a in actions:
         if isinstance(a, str):
             a = {"text": a}
         data: Dict[str, Union[str, bool]] = {}
         for k, v in cls.aliases.items():
             if k in a:
                 a[v] = a[k]
                 del a[k]
         for k in a:
             if k in cls.available_properities["default"]:
                 data[k] = a[k]
             else:
                 break
         if "callback_data" in data:
             data["callback_data"] = data["callback_data"][1].new(
                 **data["callback_data"][0])
         buttons.append(KeyboardButton(**data))
     kb.keyboard = create_keyboard_layout(buttons, schema)
     kb.resize_keyboard = True
     return kb
Esempio n. 2
0
 def _create_kb(
         actions: List[Union[str, Dict[str, Union[str, bool, KeyboardButtonPollType]]]],
         schema: List[int],
         resize_keyboard: bool = True,
         selective: bool = False,
         one_time_keyboard: bool = False
 ) -> ReplyKeyboardMarkup:
     kb = ReplyKeyboardMarkup(
         resize_keyboard=resize_keyboard, selective=selective, one_time_keyboard=one_time_keyboard
     )
     kb.row_width = max(schema)
     btns = []
     # noinspection DuplicatedCode
     for a in actions:
         if isinstance(a, str):
             a = {'text': a}
         data: Dict[str, Union[str, bool, KeyboardButtonPollType]] = {}
         for k, v in DefaultConstructor.aliases.items():
             if k in a:
                 a[v] = a[k]
                 del a[k]
         for k in a:
             if k in DefaultConstructor.available_properities:
                 if len(data) < DefaultConstructor.properties_amount:
                     data[k] = a[k]
                 else:
                     break
         if len(data) != DefaultConstructor.properties_amount:
             raise ValueError('Недостаточно данных для создания кнопки')
         btns.append(KeyboardButton(**data))
     kb.keyboard = schema_generator.create_keyboard_layout(btns, schema)
     return kb
Esempio n. 3
0
def arrange_default_schema(buttons: List[KeyboardButton],
                           count: List[int]) -> ReplyKeyboardMarkup:
    kb = ReplyKeyboardMarkup(resize_keyboard=True)
    kb.row_width = max(count)
    if sum(count) != len(buttons):
        raise ValueError('Количество кнопок не совпадает со схемой')
    tmplist = []
    for a in count:
        tmplist.append([])
        for _ in range(a):
            tmplist[-1].append(buttons.pop(0))
    kb.keyboard = tmplist
    return kb
Esempio n. 4
0
 def markup(
     self,
     actions: List[Union[str, Dict[str, Union[str, bool, KeyboardButtonPollType]]]],
     schema: List[int],
     resize_keyboard: bool = None,
     one_time_keyboard: bool = None,
     selective: bool = None,
 ) -> ReplyKeyboardMarkup:
     markup = ReplyKeyboardMarkup(
         resize_keyboard=resize_keyboard,
         one_time_keyboard=one_time_keyboard,
         selective=selective,
     )
     markup.row_width = max(schema)
     buttons = list()
     for action in actions:
         self._replace_aliases(action)
         button_data = self._set_poll_property(self._check_properties(action))
         buttons.append(KeyboardButton(**button_data))
     markup.keyboard = self.create_keyboard_layout(buttons, schema)
     return markup