mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-29 01:09:48 +03:00
KeyboardButtonUserProfile
- Allow sending User Profile Button - Return User entity on clicking button
This commit is contained in:
parent
8dc6c192bc
commit
50b2f0ed56
|
@ -1,6 +1,8 @@
|
||||||
|
import typing
|
||||||
|
|
||||||
from .messagebutton import MessageButton
|
from .messagebutton import MessageButton
|
||||||
from ... import _tl
|
from ... import _tl
|
||||||
from ..._misc import utils
|
from ..._misc import utils, hints
|
||||||
|
|
||||||
|
|
||||||
class Button:
|
class Button:
|
||||||
|
@ -54,6 +56,7 @@ class Button:
|
||||||
_tl.KeyboardButtonCallback,
|
_tl.KeyboardButtonCallback,
|
||||||
_tl.KeyboardButtonGame,
|
_tl.KeyboardButtonGame,
|
||||||
_tl.KeyboardButtonSwitchInline,
|
_tl.KeyboardButtonSwitchInline,
|
||||||
|
_tl.KeyboardButtonUserProfile,
|
||||||
_tl.KeyboardButtonUrl,
|
_tl.KeyboardButtonUrl,
|
||||||
_tl.InputKeyboardButtonUrlAuth
|
_tl.InputKeyboardButtonUrlAuth
|
||||||
))
|
))
|
||||||
|
@ -166,6 +169,29 @@ class Button:
|
||||||
fwd_text=fwd_text
|
fwd_text=fwd_text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def mention(text, input_entity):
|
||||||
|
"""
|
||||||
|
Creates a new inline button linked to the profile of user.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_entity:
|
||||||
|
Input entity of :tl:User to use for profile button.
|
||||||
|
By default, this is the logged in user (itself), although
|
||||||
|
you may pass a different input peer.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
For now, you cannot use ID or username for this argument.
|
||||||
|
If you want to use different user, you must manually use
|
||||||
|
`client.get_input_entity() <telethon.client.users.UserMethods.get_input_entity>`.
|
||||||
|
"""
|
||||||
|
return _tl.InputKeyboardButtonUserProfile(
|
||||||
|
text,
|
||||||
|
utils.get_input_user(input_entity or _tl.InputUserSelf())
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def text(cls, text, *, resize=None, single_use=None, selective=None):
|
def text(cls, text, *, resize=None, single_use=None, selective=None):
|
||||||
"""
|
"""
|
||||||
|
@ -387,4 +413,4 @@ def build_reply_markup(
|
||||||
return _tl.ReplyInlineMarkup(rows)
|
return _tl.ReplyInlineMarkup(rows)
|
||||||
# elif is_normal:
|
# elif is_normal:
|
||||||
return _tl.ReplyKeyboardMarkup(
|
return _tl.ReplyKeyboardMarkup(
|
||||||
rows, resize=resize, single_use=single_use, selective=selective)
|
rows, resize=resize, single_use=single_use, selective=selective)
|
|
@ -71,6 +71,10 @@ class MessageButton:
|
||||||
If it's an inline :tl:`KeyboardButtonCallback` with text and data,
|
If it's an inline :tl:`KeyboardButtonCallback` with text and data,
|
||||||
it will be "clicked" and the :tl:`BotCallbackAnswer` returned.
|
it will be "clicked" and the :tl:`BotCallbackAnswer` returned.
|
||||||
|
|
||||||
|
If it's an inline :tl:`KeyboardButtonUserProfile` button, the
|
||||||
|
`client.get_entity` will be called and the resulting :tl:User will be
|
||||||
|
returned.
|
||||||
|
|
||||||
If it's an inline :tl:`KeyboardButtonSwitchInline` button, the
|
If it's an inline :tl:`KeyboardButtonSwitchInline` button, the
|
||||||
:tl:`StartBot` will be invoked and the resulting updates
|
:tl:`StartBot` will be invoked and the resulting updates
|
||||||
returned.
|
returned.
|
||||||
|
@ -107,6 +111,8 @@ class MessageButton:
|
||||||
return await self._client(req)
|
return await self._client(req)
|
||||||
except BotResponseTimeoutError:
|
except BotResponseTimeoutError:
|
||||||
return None
|
return None
|
||||||
|
elif isinstance(self.button, _tl.KeyboardButtonUserProfile):
|
||||||
|
return await self._client.get_entity(self.button.user_id)
|
||||||
elif isinstance(self.button, _tl.KeyboardButtonSwitchInline):
|
elif isinstance(self.button, _tl.KeyboardButtonSwitchInline):
|
||||||
return await self._client(_tl.fn.messages.StartBot(
|
return await self._client(_tl.fn.messages.StartBot(
|
||||||
bot=self._bot, peer=self._chat, start_param=self.button.query
|
bot=self._bot, peer=self._chat, start_param=self.button.query
|
||||||
|
@ -143,4 +149,4 @@ class MessageButton:
|
||||||
long, lat = share_geo
|
long, lat = share_geo
|
||||||
share_geo = _tl.InputMediaGeoPoint(_tl.InputGeoPoint(lat=lat, long=long))
|
share_geo = _tl.InputMediaGeoPoint(_tl.InputGeoPoint(lat=lat, long=long))
|
||||||
|
|
||||||
return await self._client.send_file(self._chat, share_geo)
|
return await self._client.send_file(self._chat, share_geo)
|
Loading…
Reference in New Issue
Block a user