timoniq / telegrinder

Modern visionary telegram bot framework
MIT License
31 stars 5 forks source link

feat: implement CallbackDataMap rule #50

Closed luwqz1 closed 9 months ago

luwqz1 commented 9 months ago
from telegrinder.rules import CallbackDataMap

@bot.on.callback_query(CallbackDataMap({"count": int}))
async def cb_handler(cb: CallbackQuery, count: int):
    await cb.answer(str(count))

bot.run_forever()
timoniq commented 9 months ago

more examples that have to be considered

{"sub": {"a": int, "b": str.isupper}, "a": "Hello"}
{"a": [{"name": str, "sign": lambda x: x != "scorpio"}], "b": "static"}

JSON specifies dictionary and list-like complex objects so supporting list element declaration is mandatory but syntax to declare it is negotiable