mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 19:03:46 +03:00
Add support for messages to get_stats
This commit is contained in:
parent
4d3ff0e175
commit
f326769fa8
|
@ -1238,6 +1238,7 @@ class ChatMethods:
|
||||||
async def get_stats(
|
async def get_stats(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
entity: 'hints.EntityLike',
|
entity: 'hints.EntityLike',
|
||||||
|
message: 'typing.Union[int, types.Message]' = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Retrieves statistics from the given megagroup or broadcast channel.
|
Retrieves statistics from the given megagroup or broadcast channel.
|
||||||
|
@ -1250,6 +1251,10 @@ class ChatMethods:
|
||||||
entity (`entity`):
|
entity (`entity`):
|
||||||
The channel from which to get statistics.
|
The channel from which to get statistics.
|
||||||
|
|
||||||
|
message (`int` | ``Message``, optional):
|
||||||
|
The message ID from which to get statistics, if your goal is
|
||||||
|
to obtain the statistics of a single message.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
If the given entity is not a channel (broadcast or megagroup),
|
If the given entity is not a channel (broadcast or megagroup),
|
||||||
a `TypeError` is raised.
|
a `TypeError` is raised.
|
||||||
|
@ -1258,8 +1263,10 @@ class ChatMethods:
|
||||||
``telethon.errors.ChatAdminRequiredError`` will appear.
|
``telethon.errors.ChatAdminRequiredError`` will appear.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
Either :tl:`BroadcastStats` or :tl:`MegagroupStats`, depending on
|
If both ``entity`` and ``message`` were provided, returns
|
||||||
whether the input belonged to a broadcast channel or megagroup.
|
:tl:`MessageStats`. Otherwise, either :tl:`BroadcastStats` or
|
||||||
|
:tl:`MegagroupStats`, depending on whether the input belonged to a
|
||||||
|
broadcast channel or megagroup.
|
||||||
|
|
||||||
Example
|
Example
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
@ -1276,20 +1283,28 @@ class ChatMethods:
|
||||||
if helpers._entity_type(entity) != helpers._EntityType.CHANNEL:
|
if helpers._entity_type(entity) != helpers._EntityType.CHANNEL:
|
||||||
raise TypeError('You must pass a channel entity')
|
raise TypeError('You must pass a channel entity')
|
||||||
|
|
||||||
# Don't bother fetching the Channel entity (costs a request), instead
|
message = utils.get_message_id(message)
|
||||||
# try to guess and if it fails we know it's the other one (best case
|
if message is not None:
|
||||||
# no extra request, worst just one).
|
|
||||||
try:
|
|
||||||
req = functions.stats.GetBroadcastStatsRequest(entity)
|
|
||||||
return await self(req)
|
|
||||||
except errors.StatsMigrateError as e:
|
|
||||||
dc = e.dc
|
|
||||||
except errors.BroadcastRequiredError:
|
|
||||||
req = functions.stats.GetMegagroupStatsRequest(entity)
|
|
||||||
try:
|
try:
|
||||||
|
req = functions.stats.GetMessageStatsRequest(entity, message)
|
||||||
return await self(req)
|
return await self(req)
|
||||||
except errors.StatsMigrateError as e:
|
except errors.StatsMigrateError as e:
|
||||||
dc = e.dc
|
dc = e.dc
|
||||||
|
else:
|
||||||
|
# Don't bother fetching the Channel entity (costs a request), instead
|
||||||
|
# try to guess and if it fails we know it's the other one (best case
|
||||||
|
# no extra request, worst just one).
|
||||||
|
try:
|
||||||
|
req = functions.stats.GetBroadcastStatsRequest(entity)
|
||||||
|
return await self(req)
|
||||||
|
except errors.StatsMigrateError as e:
|
||||||
|
dc = e.dc
|
||||||
|
except errors.BroadcastRequiredError:
|
||||||
|
req = functions.stats.GetMegagroupStatsRequest(entity)
|
||||||
|
try:
|
||||||
|
return await self(req)
|
||||||
|
except errors.StatsMigrateError as e:
|
||||||
|
dc = e.dc
|
||||||
|
|
||||||
sender = await self._borrow_exported_sender(dc)
|
sender = await self._borrow_exported_sender(dc)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user