Commit Graph

737 Commits

Author SHA1 Message Date
Lonami Exo
32b92b32a7 Update .send_file() documentation (for f0eb41b) 2018-01-23 12:13:03 +01:00
Lonami Exo
58d90e7e34 Fix .download_media() not accepting Document 2018-01-23 12:10:23 +01:00
Lonami Exo
81c95b5a60 Fix recursive .get_input_media() forgetting parameters 2018-01-23 12:04:35 +01:00
Lonami Exo
f0eb41b902 Accept message/media on .send_file, remove redundancy off README 2018-01-23 11:59:35 +01:00
Tulir Asokan
5f2f04c6c2 Add HTML parse mode (#554) 2018-01-22 10:06:11 +01:00
Lonami Exo
abe26625e6 Add missing ResolvedPeer, InputNotifyPeer, TopPeer cases 2018-01-21 11:04:46 +01:00
Lonami Exo
f1371c3999 Early return from Session.get_input_entity() if Input* given 2018-01-20 19:39:48 +01:00
Lonami Exo
86816a3bdf Add missing InputChannel case on .get_input_peer() 2018-01-20 19:29:05 +01:00
Lonami Exo
b716c4fe67 Several documentation enhancements and build warnings fixes
- Made the documentation even more friendly towards newbies.
- Eased the usage of methods like get history which now set
  a default empty message for message actions and vice versa.
- Fixed some docstring documentations too.
- Updated the old normal docs/ to link back and forth RTD.
- Fixed the version of the documentation, now auto-loaded.
2018-01-20 11:47:17 +01:00
Lonami Exo
4d4e81e609 Fix cyclic imports on Python 3.4 by moving Session one level up 2018-01-19 22:55:28 +01:00
Lonami Exo
519c113b58 Update to v0.16.2 2018-01-19 21:17:57 +01:00
Lonami Exo
e3c56b0d98 Reduce autocast overhead as much as possible
Rationale: if the user is doing things right, the penalty for
being friendly (i.e. autocasting to the right version, like
User -> InputPeerUser), should be as little as possible.

Removing the redundant type() call to access .SUBCLASS_OF_ID
and assuming the user provided a TLObject (through excepting
whenever the attribute is not available) is x2 and x4 times
faster respectively.

Of course, this is a micro-optimization, but I still consider
it's good to benefit users doing things right or avoiding
redundant calls.
2018-01-19 13:00:17 +01:00
Lonami Exo
33e50aaee1 Reuse .on_response/.__str__/.stringify, override iff necessary 2018-01-19 12:12:52 +01:00
Lonami Exo
f6d98a61cf Add stub .get_input_entity() to TelegramBareClient
.resolve() calls should now work even if the subclass isn't in use.
2018-01-19 11:52:44 +01:00
Lonami Exo
1c9fa76ede Add new method to .resolve() parameters instead on init
TLObject's __init__ used to call utils.get_input_* methods and
similar to auto-cast things like User into InputPeerUser as
required. Now there's a custom .resolve() method for this purpose
with several advantages:
- Old behaviour still works, autocasts work like usual.

- A request can be constructed and later modified, before the
  autocast only occured on the constructor but now while invoking.

- This allows us to not only use the utils module but also the
  client, so it's even possible to use usernames or phone numbers
  for things that require an InputPeer. This actually assumes
  the TelegramClient subclass is being used and not the bare version
  which would fail when calling .get_input_peer().
2018-01-19 11:47:45 +01:00
Lonami Exo
b546c02210 Return a custom class for sized InputFile instead extra attrs 2018-01-18 20:09:59 +01:00
Lonami Exo
0e4611a593 Properly implement InputPhoto/InputDocument caching
Since uploading a file is done on the TelegramClient, and the
InputFiles are only valid for a short period of time, it only
makes sense to cache the sent media instead (which should not
expire). The problem is the MD5 is only needed when uploading
the file.

The solution is to allow this method to check for the wanted
cache, and if available, return an instance of that, so to
preserve the flexibility of both options (always InputFile,
or the cached InputPhoto/InputDocument) instead reuploading.
2018-01-18 19:36:47 +01:00
Lonami Exo
7e707dbbd9 Fix using enum on sqlite instead its value 2018-01-18 19:35:46 +01:00
Lonami Exo
1a3feec481 Move upload/download file methods to the TelegramClient 2018-01-18 13:55:03 +01:00
Lonami Exo
55efb2b104 Use a different schema for file cache which actually persists
Caching the inputFile values would not persist accross several
days so the cache was nearly unnecessary. Saving the id/hash of
the actual inputMedia sent is a much better/persistent idea.
2018-01-18 09:52:39 +01:00
Lonami Exo
428abebed8 Fix sending albums failing on invalid cache 2018-01-17 13:29:08 +01:00
Lonami Exo
bfe9378054 Fix .send_file failing with strings (as they are iterable) 2018-01-17 13:28:56 +01:00
Lonami Exo
fde0d60f72 Update old interactive example (#546) 2018-01-16 18:36:50 +01:00
Lonami Exo
49f204c955 Fix .get_input_media using None caption and missing venue type 2018-01-16 14:04:12 +01:00
Lonami Exo
36e2101910 Allow sending multiple files as album (closes #455) 2018-01-15 18:15:30 +01:00
Lonami Exo
494c90af69 Fix uploaded files cache may have expired 2018-01-15 12:36:46 +01:00
Lonami Exo
00859d52c3 Ask for the phone on start only if required 2018-01-15 09:48:37 +01:00
Lonami Exo
8be7e76b74 Use the idling state instead checking if read thread is present
This caused some multithreading bugs, for instance, when there was
no read thread and the main thread was idling, and there were some
update workers. Several threads would try to read from the socket
at the same time (since there's no lock for reading), causing
reads to be corrupted and receiving "invalid packet lengths"
from the network. Closes #538.
2018-01-14 21:20:22 +01:00
Lonami Exo
c5e969d585 Add more useful logging on invalid packet length received 2018-01-13 19:26:45 +01:00
Lonami Exo
0d429f55c5 Fix asking for phone on .start() 2018-01-13 12:00:53 +01:00
Lonami Exo
77301378f8 Make .start() more friendly by asking phone if not given
Ping #530
2018-01-13 11:55:12 +01:00
Lonami Exo
1fd20ace2c Update to v0.16.1 2018-01-11 22:18:58 +01:00
Lonami Exo
77ef659cbf Clearer error when invoking without calling .connect() (#532) 2018-01-11 15:42:27 +01:00
Joscha Götzer
80f81fe69a Added .start() convenience method to quickly connect/authorize (#528) 2018-01-11 12:43:46 +01:00
Lonami Exo
eaef392a9b Add and except missing FLOOD_TEST_PHONE_WAIT_X error 2018-01-10 17:34:34 +01:00
Lonami Exo
8038971753 Add clear_mentions parameter to .send_read_acknowledge() 2018-01-10 12:50:49 +01:00
Lonami Exo
045f7f5643 Assert hash is not None when migrating from JSON sessions 2018-01-10 10:46:43 +01:00
Lonami Exo
01820c9943 Associate phone code hash with phone (so phone can change) 2018-01-08 14:18:36 +01:00
Lonami Exo
c12af5e412 Remove references to the wiki 2018-01-08 14:04:04 +01:00
Nikola Vlahović
0c3216cb36 Fix channel check issue on send_read_acknowledge (#526) 2018-01-08 12:46:47 +01:00
Lonami Exo
46b088d44c Also handle ECONNREFUSED on .connect() (report on #392) 2018-01-08 12:26:32 +01:00
Lonami Exo
3c686fecdf Avoid more cyclic imports on the session file 2018-01-08 12:14:03 +01:00
Lonami Exo
f4182376f1 Move utils.calc_msg_key into auth_key (cyclic imports py3.4) 2018-01-08 12:07:14 +01:00
Lonami Exo
59a1a6aef2 Stop working with bytes on the markdown parser 2018-01-07 16:19:41 +01:00
Lonami Exo
34fe150096 Save only one auth_key on the database again 2018-01-07 00:38:30 +01:00
Lonami Exo
d81dd055e6 Remove temporary connections and use a lock again
These seem to be the reason for missing some updates (#237)
2018-01-06 23:45:22 +01:00
Lonami Exo
7745b8e7ee Use without rowid only if supported (closes #523) 2018-01-06 19:35:24 +01:00
Lonami Exo
f357d00911 Assert user/channel ID is non-zero too for #392 2018-01-06 15:54:27 +01:00
Lonami Exo
6f690945f1 Add a few security checks when unpacking messages from server
Also delete MtProto 1.0 leftovers.
2018-01-06 02:03:23 +01:00
Lonami Exo
3eafe18d0b Implement MtProto 2.0 (closes #484, thanks @delivrance!)
Huge shoutout to @delivrance's pyrogram, specially this commit:
pyrogram/pyrogram/commit/42f9a2d6994baaf9ecad590d1ff4d175a8c56454
2018-01-06 01:55:11 +01:00
Lonami Exo
4871a6fb96 Accept 'me' and 'self' usernames to get self user entity 2018-01-05 19:51:44 +01:00
Lonami Exo
ec4ca5dbfc More consistent with asyncio branch (style/small fixes)
Like passing an extra (invalid) dt parameter when serializing
a datetime, and handling more errors in the TcpClient class.
2018-01-05 18:31:48 +01:00
Lonami Exo
c4e26c95f5 Always cache files smaller than 10MB, now in the database
This removes the need for a .clear_cache() method as now files
are identified by their MD5 (which needs to be calculated
always) and their file size (to make collisions even more
unlikely) instead using the file path (which can now change).
2018-01-05 15:33:25 +01:00
Lonami Exo
a489b4b18b Clean up some more twirks on RTD and update docstrings 2018-01-05 13:30:21 +01:00
Lonami Exo
6cb5931e7a Call .disconnect() on client.__del__ for convenience 2018-01-04 23:37:47 +01:00
Lonami Exo
b45b63d71d Assert ._first_request is True with None auth_key (#517) 2018-01-04 21:07:29 +01:00
Lonami Exo
4fba27dee9 Accept InputFile/InputFileBig on .upload_file for 2c437c51
Now an input file thumbnail can also be specified, instead
needing to reupload the file every time.
2018-01-04 15:33:48 +01:00
Csaba Henk
2c437c51bb client: add thumbnail support for send_file() 2018-01-04 12:17:47 +01:00
Csaba Henk
78871b697e client: return the message in send_file, too 2018-01-04 12:17:47 +01:00
Lonami Exo
33d6afa0bd Add missing L74 hash parameter to .get_message_history() 2018-01-03 19:18:24 +01:00
Lonami Exo
cbf6306599 Fix early cast to input from 932ed9e causing error on Peer 2017-12-29 22:07:16 +01:00
Lonami Exo
d2121c76cb Fetch and persist each auth_key per DC 2017-12-29 19:41:12 +01:00
Lonami Exo
0570c55120 Remove hardcoded database version from session sql statement 2017-12-29 00:43:52 +01:00
Lonami Exo
47b53ce89f Except only UnicodeDecodeError to check migration (fix #511) 2017-12-28 17:06:14 +01:00
Lonami Exo
4a139b0ae4 Fix session table may be empty if no DC switch 2017-12-28 14:58:42 +01:00
Lonami Exo
50d413b1c9 Fix slicing dialogs was turning UserList into list 2017-12-28 14:55:02 +01:00
Lonami Exo
55b67b65a1 Remove optional add_mark parameter from .get_peer_id
It was always True after all, and it made no sense for it to
be False.
2017-12-28 13:31:43 +01:00
Lonami Exo
7ed3be8e6f Fix .get_dialogs() failing due to IDs being marked
Also removed utils.find_user_or_chat to prevent this from
happening again. Using a dict {marked_id: entity} is better.
2017-12-28 13:21:35 +01:00
Lonami Exo
c23c0a557a Update to v0.16 2017-12-28 12:43:50 +01:00
Lonami Exo
3537e9bcc9 Support more types to represent a date 2017-12-28 12:32:16 +01:00
Lonami Exo
75a342e24b Fix .download_media() not handling Photo (closes #473) 2017-12-28 12:11:31 +01:00
Lonami Exo
bfff1567af Fix up some mismatching raise/except types since 6ec6967 2017-12-28 11:55:05 +01:00
Lonami Exo
459022bdab Return a UserList with a .total attribute for get dialogs/history 2017-12-28 11:49:35 +01:00
Lonami Exo
0755bda220 Stop returning tuples off .get_message_history()
Now the information is saved in the modified Message instances,
which makes it easier to use (message.sender, message.to...)
2017-12-28 02:01:22 +01:00
Lonami Exo
52a4ef82f4 Merge branch 'master' of github.com:LonamiWebs/Telethon 2017-12-28 01:17:30 +01:00
Lonami Exo
b35fc075e0 Merge branch 'sqlite-session' 2017-12-28 01:15:12 +01:00
Lonami Exo
2a10f31511 Always wrap init connection for first call
Ping @delivrance.
See https://core.telegram.org/api/invoking#saving-client-info.
2017-12-28 01:13:24 +01:00
Lonami Exo
ab07f0220a Save dc_id instead layer and salt in the session file
Server salts change every 30 minutes after all, so keeping them
in the long-term storage session file doesn't make much sense.

Saving the layer doesn't make sense either, as it was only used
to know whether to init connection or not, but it should be done
always.
2017-12-28 01:06:27 +01:00
Dmitry D. Chernov
6ec6967ff9 Make exception types correspond to Python docs 2017-12-28 09:48:02 +10:00
Lonami Exo
1a746e1464 Fix .download_profile_photo() for some channels (closes #500) 2017-12-28 09:48:02 +10:00
Lonami Exo
166d5a4012 Fix .get_dialogs() being inconsistent with the return type 2017-12-28 09:48:01 +10:00
Dmitry D. Chernov
b252468ca2 TelegramBareClient: Add set_proxy() method
This allows to change proxy without recreation of the client instance.
2017-12-28 09:48:01 +10:00
Lonami Exo
b1b3610c1f Add missing self to .set_proxy (fa64a5f) 2017-12-28 00:09:29 +01:00
Lonami Exo
bdd63b91a2 Fix .download_profile_photo() for some channels (closes #500) 2017-12-27 23:54:31 +01:00
Lonami Exo
292e4fc29f Fix .get_dialogs() being inconsistent with the return type 2017-12-27 23:46:06 +01:00
Dmitry D. Chernov
fa64a5f7b8 TelegramBareClient: Add set_proxy() method
This allows to change proxy without recreation of the client instance.
2017-12-28 07:50:49 +10:00
Dmitry D. Chernov
a5b1457eee TelegramBareClient: Fix lost #region 2017-12-28 07:33:25 +10:00
Lonami Exo
f3d47769df Fix .send_read_acknowledge() for channels (#501) 2017-12-27 15:26:23 +01:00
Lonami Exo
21e5f0b547 Fix GetUsersRequest has a limit of 200 2017-12-27 15:08:29 +01:00
Birger Jarl
73edb0f4ff Avoid using None dates on file download (#462) 2017-12-27 14:52:33 +01:00
Lonami Exo
f29ee41f6c Don't use rowid for the entities table 2017-12-27 13:27:54 +01:00
Lonami Exo
932ed9ea9d Cast to input peer early on get input entity and close cursor 2017-12-27 13:06:03 +01:00
Lonami Exo
843e777eba Simplify .process_entities() flow 2017-12-27 12:58:50 +01:00
Lonami Exo
f8745155ac Stop joining read thread on disconnect, as it may be None 2017-12-27 12:37:07 +01:00
Lonami Exo
f96d88d3b5 Modify .get_entity to support fetching many entities at once 2017-12-27 12:36:38 +01:00
Lonami Exo
3512028d0f Fix .get_input_entity excepting wrong type 2017-12-27 12:36:14 +01:00
Lonami Exo
b6b47d175c Fix username.lower() on instances with username field but None 2017-12-27 12:16:49 +01:00
Lonami Exo
5c17097d8d Clean up .get_entity and remove force_fetch 2017-12-27 11:56:05 +01:00
Lonami Exo
86429e7291 Lowercase usernames before adding them to the database 2017-12-27 11:54:08 +01:00
Lonami Exo
aef96f1b68 Remove custom EntityDatabase and use sqlite3 instead
There are still a few things to change, like cleaning up the
code and actually caching the entities as a whole (currently,
although the username/phone/name can be used to fetch their
input version which is an improvement, their full version
needs to be re-fetched. Maybe it's a good thing though?)
2017-12-27 00:50:09 +01:00