Support get_peer on participants and clarify some strings

This commit is contained in:
Lonami Exo 2019-01-07 16:13:37 +01:00
parent 00c8aa847d
commit d892a537a7
3 changed files with 13 additions and 10 deletions

View File

@ -724,6 +724,10 @@ def get_peer(peer):
elif isinstance(peer, types.ChannelFull): elif isinstance(peer, types.ChannelFull):
return types.PeerChannel(peer.id) return types.PeerChannel(peer.id)
if peer.SUBCLASS_OF_ID in (0x7d7c6f86, 0xd9c7fc18):
# ChatParticipant, ChannelParticipant
return types.PeerUser(peer.user_id)
peer = get_input_peer(peer, allow_self=False, check_hash=False) peer = get_input_peer(peer, allow_self=False, check_hash=False)
if isinstance(peer, types.InputPeerUser): if isinstance(peer, types.InputPeerUser):
return types.PeerUser(peer.user_id) return types.PeerUser(peer.user_id)

View File

@ -8,18 +8,17 @@ You should have the `telethon` library installed with `pip`.
Run `python3 -m pip install --upgrade telethon --user` if you don't Run `python3 -m pip install --upgrade telethon --user` if you don't
have it installed yet (this is the most portable way to install it). have it installed yet (this is the most portable way to install it).
Examples assume you have the following environment variables defined: The scripts will ask you for your API ID, hash, etc. through standard input.
You can also define the following environment variables to avoid doing so:
* `TG_API_ID`, this is your API ID from https://my.telegram.org. * `TG_API_ID`, this is your API ID from https://my.telegram.org.
* `TG_API_HASH`, this is your API hash from https://my.telegram.org. * `TG_API_HASH`, this is your API hash from https://my.telegram.org.
* `TG_TOKEN`, this is your bot token from [@BotFather] for bot examples. * `TG_TOKEN`, this is your bot token from [@BotFather] for bot examples.
* `TG_SESSION`, this is the name of the `*.session` file to use. * `TG_SESSION`, this is the name of the `*.session` file to use.
You can ignore any of these, and the scripts will prompt you to enter them.
## Downloading Examples ## Downloading Examples
You may download all and run any example with by typing in a terminal: You may download all and run any example by typing in a terminal:
```sh ```sh
git clone https://github.com/LonamiWebs/Telethon.git git clone https://github.com/LonamiWebs/Telethon.git
cd Telethon cd Telethon
@ -37,7 +36,7 @@ them as the base for your own code without worrying about copyright.
### [`print_updates.py`] ### [`print_updates.py`]
* Usable as a: **user and bot**. * Usable as: **user and bot**.
* Difficulty: **easy**. * Difficulty: **easy**.
Trivial example that just prints all the updates Telegram originally Trivial example that just prints all the updates Telegram originally
@ -46,7 +45,7 @@ some characters on screen.
### [`print_messages.py`] ### [`print_messages.py`]
* Usable as a: **user and bot**. * Usable as: **user and bot**.
* Difficulty: **easy**. * Difficulty: **easy**.
This example uses the different `@client.on` syntax to register event This example uses the different `@client.on` syntax to register event
@ -57,7 +56,7 @@ documentation of [`events.NewMessage`] since this is only a simple example.
### [`replier.py`] ### [`replier.py`]
* Usable as a: **user and bot**. * Usable as: **user and bot**.
* Difficulty: **easy**. * Difficulty: **easy**.
This example showcases a third way to add event handlers (using decorators This example showcases a third way to add event handlers (using decorators
@ -78,7 +77,7 @@ assumes some [`asyncio`] knowledge, but otherwise is easy to follow.
### [`interactive_telegram_client.py`] ### [`interactive_telegram_client.py`]
* Usable as a: **user and bot**. * Usable as: **user**.
* Difficulty: **medium**. * Difficulty: **medium**.
Interactive terminal client that you can use to list your dialogs, Interactive terminal client that you can use to list your dialogs,
@ -88,7 +87,7 @@ state in order for downloads to work later.
### [`gui.py`] ### [`gui.py`]
* Usable as a: **user and bot**. * Usable as: **user and bot**.
* Difficulty: **high**. * Difficulty: **high**.
This is a simple GUI written with [`tkinter`] which becomes more complicated This is a simple GUI written with [`tkinter`] which becomes more complicated

View File

@ -38,7 +38,7 @@ CHANNEL_PUBLIC_GROUP_NA,403,channel/supergroup not available
CHAT_ABOUT_NOT_MODIFIED,400,About text has not changed CHAT_ABOUT_NOT_MODIFIED,400,About text has not changed
CHAT_ABOUT_TOO_LONG,400,Chat about too long CHAT_ABOUT_TOO_LONG,400,Chat about too long
CHAT_ADMIN_INVITE_REQUIRED,403,You do not have the rights to do this CHAT_ADMIN_INVITE_REQUIRED,403,You do not have the rights to do this
CHAT_ADMIN_REQUIRED,400 403,"Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours)" CHAT_ADMIN_REQUIRED,400 403,"Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group"
CHAT_FORBIDDEN,,You cannot write in this chat CHAT_FORBIDDEN,,You cannot write in this chat
CHAT_ID_EMPTY,400,The provided chat ID is empty CHAT_ID_EMPTY,400,The provided chat ID is empty
CHAT_ID_INVALID,400,"Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead" CHAT_ID_INVALID,400,"Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead"

1 name codes description
38 CHAT_ABOUT_NOT_MODIFIED 400 About text has not changed
39 CHAT_ABOUT_TOO_LONG 400 Chat about too long
40 CHAT_ADMIN_INVITE_REQUIRED 403 You do not have the rights to do this
41 CHAT_ADMIN_REQUIRED 400 403 Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours) Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group
42 CHAT_FORBIDDEN You cannot write in this chat
43 CHAT_ID_EMPTY 400 The provided chat ID is empty
44 CHAT_ID_INVALID 400 Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead