Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@classmethod
def register(cls, cfg: Config, db: DB, dp: Dispatcher, loc_man: LocalizationManager, **kwargs):
members = cls.__dict__.items()
for name, f in members:
if not hasattr(f, 'handler_stuff'):
continue
handler_stuff = f.handler_stuff
@dp.message_handler(*handler_stuff['custom_filters'],
commands=handler_stuff['commands'],
state=handler_stuff['state'],
regexp=handler_stuff['regexp'],
content_types=handler_stuff['content_types'],
run_task=handler_stuff['run_task'],
**handler_stuff['kwargs'])
@bot_error_guard
async def handler(message: Message, state: FSMContext, name=name): # name=name important!!
logger.info({
'from': (message.from_user.id, message.from_user.first_name, message.from_user.username),
'text': message.text
})
async with state.proxy() as data:
loc = await loc_man.get_from_db(message.from_user.id, db)
handler_class = cls(cfg, db, loc, data, **kwargs)
handler_method = getattr(handler_class, name)
return await handler_method(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment