Added usage example of errors_handler
Optimized generation of default/inline keyboard Customizing webhook path has become more flexible Updated aiogram version to 2.7 (BotAPI 4.7)
This commit is contained in:
15
keyboards/default/consts.py
Normal file
15
keyboards/default/consts.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from typing import List
|
||||
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
|
||||
|
||||
from . import utils
|
||||
|
||||
|
||||
class DefaultConstructor:
|
||||
@staticmethod
|
||||
def _create_kb(actions: List[str], schema: List[int]) -> ReplyKeyboardMarkup:
|
||||
btns = []
|
||||
for a in actions:
|
||||
btns.append(KeyboardButton(a))
|
||||
kb = utils.misc.arrange_default_schema(btns, schema)
|
||||
return kb
|
||||
1
keyboards/default/utils/__init__.py
Normal file
1
keyboards/default/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import misc
|
||||
17
keyboards/default/utils/misc.py
Normal file
17
keyboards/default/utils/misc.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from typing import List
|
||||
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
|
||||
|
||||
|
||||
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
|
||||
@@ -5,13 +5,13 @@ from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
def arrange_inline_schema(buttons: List[InlineKeyboardButton], count: List[int]) -> InlineKeyboardMarkup:
|
||||
kb = InlineKeyboardMarkup()
|
||||
btns = buttons
|
||||
kb.row_width = max(count)
|
||||
if sum(count) != len(buttons):
|
||||
raise ValueError('Количество кнопок не совпадает со схемой')
|
||||
tmplist = [[InlineKeyboardButton('') for _ in range(count[i])] for i in range(len(count))]
|
||||
for a in range(len(tmplist)):
|
||||
for b in range(len(tmplist[a])):
|
||||
tmplist[a][b] = btns.pop(0)
|
||||
tmplist = []
|
||||
for a in count:
|
||||
tmplist.append([])
|
||||
for _ in range(a):
|
||||
tmplist[-1].append(buttons.pop(0))
|
||||
kb.inline_keyboard = tmplist
|
||||
return kb
|
||||
|
||||
Reference in New Issue
Block a user