1.0.6: Add `callback`s to inline query answers

pull/1/head
Hikari 2022-04-23 04:41:51 +00:00
parent 74e6bbdad6
commit d3144fcebd
No known key found for this signature in database
GPG Key ID: 5FA52ACBB2AD964D
3 changed files with 37 additions and 4 deletions

View File

@ -114,7 +114,8 @@ class Events(InlineUnit):
thumb_width=128,
thumb_height=128,
reply_markup=self._generate_markup(
res.get("reply_markup", None)
res.get("reply_markup", None),
prepare_callbacks=True,
),
)
]
@ -299,7 +300,7 @@ class Events(InlineUnit):
return
await self._custom_map[query.data]["handler"](
query,
InlineCall(query, self, None),
*self._custom_map[query.data].get("args", []),
**self._custom_map[query.data].get("kwargs", {}),
)

View File

@ -30,6 +30,7 @@ class Utils(InlineUnit):
self,
form_uid: Union[str, list],
/,
prepare_callbacks: bool = False,
) -> Union[None, InlineKeyboardMarkup]:
"""Generate markup for form or list of `dict`s"""
if not form_uid:
@ -80,6 +81,35 @@ class Utils(InlineUnit):
callback_data=button["_callback_data"],
)
]
if prepare_callbacks:
self._custom_map[button["_callback_data"]] = {
"handler": button["callback"],
**(
{"always_allow": button["always_allow"]}
if button.get("always_allow", False)
else {}
),
**(
{"args": button["args"]}
if button.get("args", False)
else {}
),
**(
{"kwargs": button["kwargs"]}
if button.get("kwargs", False)
else {}
),
**(
{"force_me": True}
if button.get("force_me", False)
else {}
),
**(
{"disable_security": True}
if button.get("disable_security", False)
else {}
),
}
elif "input" in button:
line += [
InlineKeyboardButton(
@ -208,7 +238,9 @@ class Utils(InlineUnit):
parse_mode="HTML",
disable_web_page_preview=disable_web_page_preview,
reply_markup=self._generate_markup(
reply_markup if isinstance(reply_markup, list) else unit.get("buttons", [])
reply_markup
if isinstance(reply_markup, list)
else unit.get("buttons", [])
),
)
except MessageNotModified:

View File

@ -1 +1 @@
__version__ = (1, 1, 5)
__version__ = (1, 1, 6)