mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-25 00:34:19 +03:00
Update some URLs
Some were out of date, some were examples pointing to a personal link, which were replaced with generic examples.
This commit is contained in:
parent
3d32e16235
commit
7ffb87170b
|
@ -47,7 +47,7 @@ use these if possible.
|
||||||
message = await client.send_message(
|
message = await client.send_message(
|
||||||
'me',
|
'me',
|
||||||
'This message has **bold**, `code`, __italics__ and '
|
'This message has **bold**, `code`, __italics__ and '
|
||||||
'a [nice website](https://lonamiwebs.github.io)!',
|
'a [nice website](https://example.com)!',
|
||||||
link_preview=False
|
link_preview=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -360,6 +360,6 @@ Where can I read more?
|
||||||
======================
|
======================
|
||||||
|
|
||||||
`Check out my blog post
|
`Check out my blog post
|
||||||
<https://lonamiwebs.github.io/blog/asyncio/>`_ about `asyncio`, which
|
<https://lonami.dev/blog/asyncio/>`_ about `asyncio`, which
|
||||||
has some more examples and pictures to help you understand what happens
|
has some more examples and pictures to help you understand what happens
|
||||||
when the loop runs.
|
when the loop runs.
|
||||||
|
|
|
@ -112,9 +112,9 @@ you're able to just do this:
|
||||||
dialogs = await client.get_dialogs()
|
dialogs = await client.get_dialogs()
|
||||||
|
|
||||||
# All of these work and do the same.
|
# All of these work and do the same.
|
||||||
lonami = await client.get_entity('lonami')
|
username = await client.get_entity('username')
|
||||||
lonami = await client.get_entity('t.me/lonami')
|
username = await client.get_entity('t.me/username')
|
||||||
lonami = await client.get_entity('https://telegram.dog/lonami')
|
username = await client.get_entity('https://telegram.dog/username')
|
||||||
|
|
||||||
# Other kind of entities.
|
# Other kind of entities.
|
||||||
channel = await client.get_entity('telegram.me/joinchat/AAAAAEkk2WdoDrB4-Q8-gg')
|
channel = await client.get_entity('telegram.me/joinchat/AAAAAEkk2WdoDrB4-Q8-gg')
|
||||||
|
@ -142,7 +142,7 @@ you're able to just do this:
|
||||||
All methods in the :ref:`telethon-client` call `.get_input_entity()
|
All methods in the :ref:`telethon-client` call `.get_input_entity()
|
||||||
<telethon.client.users.UserMethods.get_input_entity>` prior
|
<telethon.client.users.UserMethods.get_input_entity>` prior
|
||||||
to sending the request to save you from the hassle of doing so manually.
|
to sending the request to save you from the hassle of doing so manually.
|
||||||
That way, convenience calls such as `client.send_message('lonami', 'hi!')
|
That way, convenience calls such as `client.send_message('username', 'hi!')
|
||||||
<telethon.client.messages.MessageMethods.send_message>`
|
<telethon.client.messages.MessageMethods.send_message>`
|
||||||
become possible.
|
become possible.
|
||||||
|
|
||||||
|
|
|
@ -8,82 +8,70 @@ does a result have? Well, the easiest thing to do is printing it:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
user = await client.get_entity('Lonami')
|
entity = await client.get_entity('username')
|
||||||
print(user)
|
print(entity)
|
||||||
|
|
||||||
That will show a huge **string** similar to the following:
|
That will show a huge **string** similar to the following:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
User(id=10885151, is_self=False, contact=False, mutual_contact=False, deleted=False, bot=False, bot_chat_history=False, bot_nochats=False, verified=False, restricted=False, min=False, bot_inline_geo=False, access_hash=123456789012345678, first_name='Lonami', last_name=None, username='Lonami', phone=None, photo=UserProfilePhoto(photo_id=123456789012345678, photo_small=FileLocation(dc_id=4, volume_id=1234567890, local_id=1234567890, secret=123456789012345678), photo_big=FileLocation(dc_id=4, volume_id=1234567890, local_id=1234567890, secret=123456789012345678)), status=UserStatusOffline(was_online=datetime.datetime(2018, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc)), bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None, lang_code=None)
|
Channel(id=1066197625, title='Telegram Usernames', photo=ChatPhotoEmpty(), date=datetime.datetime(2016, 12, 16, 15, 15, 43, tzinfo=datetime.timezone.utc), version=0, creator=False, left=True, broadcast=True, verified=True, megagroup=False, restricted=False, signatures=False, min=False, scam=False, has_link=False, has_geo=False, slowmode_enabled=False, access_hash=-6309373984955162244, username='username', restriction_reason=[], admin_rights=None, banned_rights=None, default_banned_rights=None, participants_count=None)
|
||||||
|
|
||||||
That's a lot of text. But as you can see, all the properties are there.
|
That's a lot of text. But as you can see, all the properties are there.
|
||||||
So if you want the username you **don't use regex** or anything like
|
So if you want the title you **don't use regex** or anything like
|
||||||
splitting ``str(user)`` to get what you want. You just access the
|
splitting ``str(entity)`` to get what you want. You just access the
|
||||||
attribute you need:
|
attribute you need:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
username = user.username
|
title = entity.title
|
||||||
|
|
||||||
Can we get better than the shown string, though? Yes!
|
Can we get better than the shown string, though? Yes!
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
print(user.stringify())
|
print(entity.stringify())
|
||||||
|
|
||||||
Will show a much better:
|
Will show a much better:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
User(
|
Channel(
|
||||||
id=10885151,
|
id=1066197625,
|
||||||
is_self=False,
|
title='Telegram Usernames',
|
||||||
contact=False,
|
photo=ChatPhotoEmpty(
|
||||||
mutual_contact=False,
|
),
|
||||||
deleted=False,
|
date=datetime.datetime(2016, 12, 16, 15, 15, 43, tzinfo=datetime.timezone.utc),
|
||||||
bot=False,
|
version=0,
|
||||||
bot_chat_history=False,
|
creator=False,
|
||||||
bot_nochats=False,
|
left=True,
|
||||||
verified=False,
|
broadcast=True,
|
||||||
|
verified=True,
|
||||||
|
megagroup=False,
|
||||||
restricted=False,
|
restricted=False,
|
||||||
|
signatures=False,
|
||||||
min=False,
|
min=False,
|
||||||
bot_inline_geo=False,
|
scam=False,
|
||||||
access_hash=123456789012345678,
|
has_link=False,
|
||||||
first_name='Lonami',
|
has_geo=False,
|
||||||
last_name=None,
|
slowmode_enabled=False,
|
||||||
username='Lonami',
|
access_hash=-6309373984955162244,
|
||||||
phone=None,
|
username='username',
|
||||||
photo=UserProfilePhoto(
|
restriction_reason=[
|
||||||
photo_id=123456789012345678,
|
],
|
||||||
photo_small=FileLocation(
|
admin_rights=None,
|
||||||
dc_id=4,
|
banned_rights=None,
|
||||||
volume_id=123456789,
|
default_banned_rights=None,
|
||||||
local_id=123456789,
|
participants_count=None
|
||||||
secret=-123456789012345678
|
|
||||||
),
|
|
||||||
photo_big=FileLocation(
|
|
||||||
dc_id=4,
|
|
||||||
volume_id=123456789,
|
|
||||||
local_id=123456789,
|
|
||||||
secret=123456789012345678
|
|
||||||
)
|
|
||||||
),
|
|
||||||
status=UserStatusOffline(
|
|
||||||
was_online=datetime.datetime(2018, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc)
|
|
||||||
),
|
|
||||||
bot_info_version=None,
|
|
||||||
restriction_reason=None,
|
|
||||||
bot_inline_placeholder=None,
|
|
||||||
lang_code=None
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
Now it's easy to see how we could get, for example,
|
Now it's easy to see how we could get, for example,
|
||||||
the ``was_online`` time. It's inside ``status``:
|
the ``year`` value. It's inside ``date``:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
online_at = user.status.was_online
|
channel_year = entity.date.year
|
||||||
|
|
||||||
You don't need to print everything to see what all the possible values
|
You don't need to print everything to see what all the possible values
|
||||||
can be. You can just search in http://tl.telethon.dev/.
|
can be. You can just search in http://tl.telethon.dev/.
|
||||||
|
@ -96,5 +84,5 @@ to check the type of something. For example:
|
||||||
|
|
||||||
from telethon import types
|
from telethon import types
|
||||||
|
|
||||||
if isinstance(user.status, types.UserStatusOffline):
|
if isinstance(entity.photo, types.ChatPhotoEmpty):
|
||||||
print(user.status.was_online)
|
print('Channel has no photo')
|
||||||
|
|
|
@ -25,7 +25,7 @@ telethon_examples/
|
||||||
==================
|
==================
|
||||||
|
|
||||||
`telethon_examples <https://github.com/LonamiWebs/Telethon/tree/master/telethon_examples>`_ /
|
`telethon_examples <https://github.com/LonamiWebs/Telethon/tree/master/telethon_examples>`_ /
|
||||||
`LonamiWebs' site <https://lonamiwebs.github.io>`_
|
`Lonami's site <https://lonami.dev>`_
|
||||||
|
|
||||||
This documentation is not the only place where you can find useful code
|
This documentation is not the only place where you can find useful code
|
||||||
snippets using the library. The main repository also has a folder with
|
snippets using the library. The main repository also has a folder with
|
||||||
|
|
|
@ -1995,7 +1995,7 @@ Internal changes
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
- ``libssl`` is no longer an optional dependency. Use ``cryptg`` instead,
|
- ``libssl`` is no longer an optional dependency. Use ``cryptg`` instead,
|
||||||
which you can find on https://github.com/Lonami/cryptg.
|
which you can find on https://pypi.org/project/cryptg/.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -569,10 +569,10 @@ class DialogMethods:
|
||||||
# <you> Your name didn't have any letters! Try again
|
# <you> Your name didn't have any letters! Try again
|
||||||
conv.send_message("Your name didn't have any letters! Try again")
|
conv.send_message("Your name didn't have any letters! Try again")
|
||||||
|
|
||||||
# <usr> Lonami
|
# <usr> Human
|
||||||
name = conv.get_response().raw_text
|
name = conv.get_response().raw_text
|
||||||
|
|
||||||
# <you> Thanks Lonami!
|
# <you> Thanks Human!
|
||||||
conv.send_message('Thanks {}!'.format(name))
|
conv.send_message('Thanks {}!'.format(name))
|
||||||
"""
|
"""
|
||||||
return custom.Conversation(
|
return custom.Conversation(
|
||||||
|
|
|
@ -634,7 +634,7 @@ class MessageMethods:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Markdown is the default
|
# Markdown is the default
|
||||||
await client.send_message('lonami', 'Thanks for the **Telethon** library!')
|
await client.send_message('me', 'Hello **world**!')
|
||||||
|
|
||||||
# Default to another parse mode
|
# Default to another parse mode
|
||||||
client.parse_mode = 'html'
|
client.parse_mode = 'html'
|
||||||
|
@ -668,7 +668,7 @@ class MessageMethods:
|
||||||
# Matrix of inline buttons
|
# Matrix of inline buttons
|
||||||
await client.send_message(chat, 'Pick one from this grid', buttons=[
|
await client.send_message(chat, 'Pick one from this grid', buttons=[
|
||||||
[Button.inline('Left'), Button.inline('Right')],
|
[Button.inline('Left'), Button.inline('Right')],
|
||||||
[Button.url('Check this site!', 'https://lonamiwebs.github.io')]
|
[Button.url('Check this site!', 'https://example.com')]
|
||||||
])
|
])
|
||||||
|
|
||||||
# Reply keyboard
|
# Reply keyboard
|
||||||
|
|
Loading…
Reference in New Issue
Block a user