Commit graph

1039 commits

Author SHA1 Message Date
Eldinnie
87afd98e02
CommandHandler overhaul and PrefixHandler added (#1114)
* Commandhandler reworked

* Make CommandHandler strict

Only register valid botcommands, else raise ValueError

* Add PrefixHandler

* declare encoding on test_commandhandler

* Fix some tests dependend on CommandHandler

* CR changes

* small docfix.

* Test all possibilities for PrefixHandler
2018-05-22 21:44:20 +02:00
Jacob Bom
247577b2e2
Context based callbacks (#1100)
See https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transition-guide-to-Version-11.0 under Context based callbacks and Filters in handlers for a good guide on the changes in this commit.

* Change handlers so context is supported

* Attempt to make parameter "guessing" work on py < 3.5

* Document use_context in all handlers

* Add Context to docs

* Minor fixes to context handling

* Add tests for context stuff

* Allow the signature check to work on py<3.5 with methods

* Fix order of operations

* Address most issues raised in CR

* Make CommandHandler no longer support filter lists

* Fix indent

(pycharm can be an arse sometimes)

* Improve readability in conversationhandler

* Make context have Match instead of groups & groupdict

* Remove filter list support from messagehandler too

* Small fix to StringCommandHandler

* More small fixes to handlers

* Amend CHANGES

* Fix tests and fix bugs raised by tests

* Don't allow users to ignore errors without messing with the warning filters themselves

* Ignore our own deprecation warnings when testing

* Skipping deprecationwarning test on py2

* Forgot some changes

* Handler: Improved documentation and text of deprecation warnings

* HandlerContext: Keep only dispatcher and use properties; improved doc

* Complete fixing the documentation.

 - Fixes per Eldinnie's comments.
 - Fixes per warnings when running sphinx.

* Some small doc fixes (interlinks and optionals)

* Change add_error_handler to use HandlerContext too

* More context based changes

Context Based Handlers -> Context Based Callbacks

No longer use_context args on every single Handler

Instead set dispatcher/updater .use_context=True to use

Works with
- Handler callbacks
- Error handler callbacks
- Job callbacks

Change examples to context based callbacks so new users are not confused

Rename and move the context object from Handlers.HandlerContext to CallbackContext, since it doesn't only apply to handlers anymore.

Fix tests by adding a new fixture `cpd` which is a dispatcher with use_context=True

* Forgot about conversationhandler

* Forgot jobqueue

* Add tests for callbackcontext & for context based callback job

* Fix as per review :)
2018-05-21 15:00:47 +02:00
Trainer Jono
94abf16a7f Add t.me links for User, Chat and Message if available and update User.mention_* (#1092)
* Add User.link and update User.mention_*
* Add Chat.link
* Add Message.link
* Link returns None on default
* Add test link
2018-05-09 11:42:12 +02:00
Noam Meltzer
32afc007aa
Bump version to v10.1.0 2018-05-05 00:37:13 +03:00
Noam Meltzer
c758c19ef4
bot.py: Remove an inaccurate note from docstring 2018-05-05 00:22:23 +03:00
Eldinnie
3bef2fa752
Updating sphinx to py3 (#1096)
* Use python 3 on read the docs

This has multiple improvements on the inspection of classes. Mainly that method signatures propely display the arguments for the method.

* Add note to telegram.Bot about camelCase

Switching to py3 means that the camelCase method descriptors will no longer be displayed in the docs. Adding a note to Bot to clarify they exist.

* Add Alias links for all camelCase
2018-05-03 15:34:50 +02:00
Noam Meltzer
0a8abccc78
InputFile: Fix proper naming of file when reading from subprocess.PIPE (#1079) 2018-05-03 00:17:54 +03:00
Igor Strebezhev
5ff34fc0ba Fix send_sticker() timeout=20 (#1088)
Documentation was correct. Code wasn't.
2018-05-01 22:48:31 +03:00
Trainer Jono
78fee3c1dc Fixed docstring of {User,Chat}.send_* methods (#1081)
* Changed all "User.chat_id"s to "User.id"
* Chat.chat_id --> Chat.id
2018-04-25 23:21:11 +03:00
Noam Meltzer
38d6f4d9f2
Inputfile encode filenames (#1086)
* Unitest to recreate issue #1083

* InputFile: Encode unicode filenames

Fixes #1083
2018-04-25 23:13:00 +03:00
Noam Meltzer
1ec12343f0
Add urllib3 fix for socks5h support (#1085)
FIxes #1077
Changes semantics of socks proxy behaviour.
Until now - socks5:// was actually socs5h:// and we didn't really have socks5://
2018-04-25 21:23:48 +03:00
Paul Larsen
b5196f00b2 Add a caption_entity filter for filtering caption entities (#1068)
* Add a caption_entity filter for filtering caption entities

* remove unneeded list comprehensions
2018-04-20 13:24:40 +02:00
Pieter Schutz
6d453b7fa2 Bump to v10.0.2 2018-04-17 09:07:19 +02:00
Joel Williams
42497367c1 Correct documentation of Dispatcher.add_handler (#1071) 2018-04-17 07:42:09 +03:00
Jannes Höke
b77b329dd6 Handle utf8 decoding errors (#1076) 2018-04-17 07:40:02 +03:00
Wagner Macedo
5efd5e2586 CommandHandler faster check (#1074)
Fixes #1073
2018-04-17 07:37:29 +03:00
Daniel Reed
cbfb7df643 Explicitly make Bot.full_name return a unicode object, rather than implicitly a unicode object in Python 3 and a str object on Python 2. (#1063) 2018-04-16 10:37:41 +02:00
Or Bin
712baf0c07 Added video note filter (#1067) 2018-04-14 21:53:54 +02:00
Emilio Molinari
3ccf40e8cc Make chat_id a positional argument inside shortcut methods of Chat and User classes #1048 (#1050)
* Make chat_id a positional argument #1048

* Fixed tests
2018-03-17 00:10:11 +01:00
Jannik
38e3b91a87 Filters for Category and file types (#1046)
* Added extra Filters for File Type and Category

Added extra Filters for File Type and Category, based on the provided Mime-Type

* Added tests for the new Filters

Added Tests for the Category and File Types Filters.

* Fixed Tests

Fixed the Tests from the last commit

* Little Fix

* Revert of unwanted changes

* Update filters.py

* Changed the strings

* Changed file_type to mime_type

* Fixed Tests
2018-03-16 23:41:48 +01:00
Eldinnie
e182046376 Fix in telegram.Message (#1042)
* Fix in telegram.Message

The `_parse_(html|markdown)` methods now properly return `None` on an empty `Message.text` or an empty `Message.caption`

* As per CR
2018-03-16 21:42:39 +01:00
Joscha Götzer
1530ed20e5 New filter: regex (#1028) 2018-03-15 06:59:27 +02:00
Pieter Schutz
d9f77d6ee1 Bump to v10.0.1 2018-03-05 12:46:19 +01:00
Eldinnie
698a91427a
Fix conversationhandler timeout (#1032)
* Fix conversationhandler

As found by @nmlorg and described in #1031

closes #1031

* adding another test and definitely finish conversationhandler

It seems another problem was when the job executed the timeout, it wasn;t removed from `self.conversation_timeouts` which made it still fail because job would be present in the handler dict, although it was already disabled.
This should fix it properly.
2018-03-05 12:18:40 +01:00
Jannes Höke
5956aae235 Add missing docs utils (#912)
* add documentation for telegram.utils.promise and .request

* improve documentation for telegram.utils.promise and .request

* add missing 's' to new_chat_member(s) in all docstrings

* fix docs for `set_chat_photo`

[CI skip]
2018-03-05 12:17:56 +01:00
Noam Meltzer
0811f566a2 Bump version to v10.0.0
[ci skip]
2018-03-03 01:23:08 +02:00
Noam Meltzer
a6bf456645
Updater improvements (#1018)
- Refactor bootstrap phase to be resilient for network errors
 - Retry bootstrap phase indefinitely (by default) on network errors
 - Improved logs
 - Improved unitests for polling updater

fixes #605
2018-03-02 23:11:16 +02:00
Evgen
811369d1a0 Added conversation timeout in ConversationHandler (#895) 2018-03-01 11:34:47 +02:00
Paul Larsen
b67ea7a691 CommandHandler - ignore strings in entities and "/" followed by whitespace (#1020) 2018-03-01 10:11:16 +02:00
Noam Meltzer
f6332d45a8
Improved File.download (#1019)
- File.download_as_bytearray - new method to get a d/led file as bytearray
   This is much more convenient and straight forward than using a file
   object.

 - File.download(): Now returns a meaningful return value

 - File.download*(): New and/or better unitests
2018-03-01 10:10:04 +02:00
Eldinnie
b275031a16 Add Message caption html/markdown methods (#1013)
Closes #1010
2018-02-22 17:38:54 +02:00
Noam Meltzer
3762792cca
Remove deprecated code (#1012)
* JobQueue: Remove deprecated prevent_autostart & put()

* Bot, Updater: Remove deprecated network_delay

* Remove deprecated Message.new_chat_member

closes #795
2018-02-22 14:17:06 +02:00
Noam Meltzer
baec1bb554 flake8 revamp
- Use pre-commit v1.2.0 flake8
 - Make sure we're running flake8 on examples and tests
 - Fix what had to be fixed
2018-02-19 12:41:38 +02:00
Noam Meltzer
746ae0caf3
Get jobs by name (#1011) 2018-02-19 10:36:40 +02:00
Eldinnie
0bed087542 remove unnecessary to_dict() (#834)
We have some objects that have exactly the same to_dict() method, only specifying that `from_user` should be `from` in the `data`-dict. I refractored this logic to `TelegramObject` and removed those to_dicts() from the code.
2018-02-19 10:31:38 +02:00
Unknown
efea0361c5 Fix attribute order error 2018-02-18 18:12:08 +01:00
Noam Meltzer
91ae35e26c
updater.py: Better handling of timeouts during getUpdates (#1007)
TimedOut exception is an expected an normal event. To reduce noise and
make things more "fluent" we now:
 - Make sure that we don't sleep after the timeout but rather retry
immediately.
 - Log debug instead of error level.

Fixes #802
2018-02-18 17:50:38 +02:00
Jacob Bom
ebcc40ae92 More instance methods (#963)
* Bot.get_file now allows passing a file in addition to file_id

* Add .get_file() to Audio, Document, PhotoSize, Sticker, Video, VideoNote and Voice

* Add .send_*() methods to User and Chat
2018-02-18 17:49:52 +02:00
Jannik
c152d6583e Support v3.6 API (#1006)
* Added support for new field `telegram.Message.connected_message`

* Added support for new field `telegram.Message.connected_message`

* Added support for parse_mode in captions

* Added parse_mode parameter for captions in InlineQueryResult*

* Added supports_streaming parameter in telegram.Bot.send_video and telegram.InputMediaVideo
Fixed Docstrings for parse_mode in captions

* pypy3.5 unitests are now running with a new version due internal errors on travis.

closes #1005
2018-02-18 17:11:04 +02:00
Joscha Götzer
9338dc4697 Added utils.helpers.effective_message_type (#826) 2018-02-15 11:21:19 +02:00
Daniel Reed
063704c0b9 Explicitly check update.effective_chat in ConversationHandler.check_update (#959)
Fixes #927
2018-02-12 16:09:51 +02:00
Oleg
62e76f1fba bot.py: Add shortcut method reply_media_group (#994)
fixes #936
2018-02-12 15:51:18 +02:00
Joscha Götzer
f0dfdfb203 bot.py: Add shortcut methods reply_{markdown,html} (#827) 2018-02-12 15:39:46 +02:00
Eldinnie
d5c9212f2e Add two arguments to send_invoice (#986)
Telegram silently added `send_phone_number_to_provider` and `send_email_to_provider` to the send_invoice method.
2018-02-10 17:54:09 +02:00
Noam Meltzer
8690ba256e
webhookhandler: Fix exception thrown during error handling (#985)
BaseServer.handle_error() default behaviour is to print to stdout or
stderr (depends on the python version). In case that the file descriptor
is closed an additional exception will be raised, causing the webhook
thread to quit.

Fixes #970
2018-01-25 10:42:48 +02:00
Noam Meltzer
ddf3a1fcad
jobqueue: Thread safety fixes (#977)
- Fix JobQueue.jobs to obtain a lock on the internal queue object prior
   to iterating over it.

 - Rename JobQueue.queue to JobQueue._queue. This shouldn't be
   accessible by the user directly, but rather only with sanitized
   thread safe methods.

 - JobQueue.interval_seconds - access self.interval only once to avoid
   race conditions.

Fixes #968
2018-01-20 15:27:01 +02:00
Mischa Krüger
eb67c039f1 Updater: Issue INFO log upon received signal (#951)
Fixes #946
2018-01-09 17:54:07 +02:00
Jacob Bom
2ca7ff82ef Update headers to 2018 (#962)
Also add two missing headers.
[ci skip]
2018-01-04 17:16:06 +02:00
Noam Meltzer
a2c04313d3
Fix documentation & coding style of User.name & User.full_name (#956)
- Use string `format` instead of dict comprehension.
 - Better documentation to signify the semantics difference between
   `name` and `full_name`.

 - Use string `format` instead of dict comprehension.
 - Better documentation to signify the semantics difference between
   `name` and `full_name`.

* Removed the NOTE and mentinoed the "@" prefix.
2017-12-30 22:58:32 +02:00
graynk
d347c0d45e User.full_name convinience property (#949)
Fixes #943
2017-12-30 15:13:06 +02:00
Daniel Reed
5c8470e552 Store bot in PreCheckoutQuery (#953)
Fixes #937
2017-12-30 14:48:38 +02:00
Eldin
3d4e0500bf Bump to 9.0.0 + changelog 2017-12-08 23:08:42 +01:00
Eldinnie
042d4bb2a4
add support for 3.5 api (#920)
* add support for 3.5 api

* removed "unused" import by accident

* Hardcoded values

Appearantly TG decided to change the size of a send image (again)

* test_official

* Improve coverage

* Finishing up

* spelling error

* pytest fixed tot < than 3.3 for python 3.3 support

* flake8

* rollback requirements

* as per CR

* object for provider_data

Make it possible to send an object that will be json-serialized for send_invoice + tests

* shorten error message

* using string_types
2017-12-08 22:38:59 +01:00
Erjan Kalybek
a5c8e98ee7 Fix sendPhoto method description (#919) 2017-12-06 13:24:34 +01:00
Noam Meltzer
4b3315db6f Fix race condition in dispatcher start/stop (#887)
fixes #881
2017-10-21 14:40:24 +03:00
Jannes Höke
3ed05991ad log error trace if there is no error handler registered (#694) 2017-10-21 12:35:11 +03:00
Simon Schürrle
bb5357a815 Fix typo in the docstring (#878)
Changed `Filters.status_update.new_chat_member` to `Filters.status_update.new_chat_members`
Thanks to @ajbvn for pointing it out.

[ci skip]
2017-10-18 22:00:17 +03:00
Jacob Bom
8df35fd53b Fix for crashes on 8.1 (#873)
* Make Commandhandler not crash on single char messages

* Bump release and update CHANGES.rst for 8.1.1

* No error on single / and test
2017-10-15 16:59:10 +02:00
Noam Meltzer
23774383dc Bump version & update CHANGES.rst for 8.1.0 release 2017-10-15 00:04:35 +03:00
Eldinnie
28680ac1d5 edited_updates also for channel_posts (#832) 2017-10-14 23:48:06 +03:00
Jannes Höke
ec9b16ac7b Fix command not recognized if it is directly followed by a newline (#869)
fixes #868
2017-10-14 21:04:02 +03:00
Eldinnie
bfad2fa1f3 support 3.4 API (#865) 2017-10-14 21:03:02 +03:00
Noam Meltzer
8a8b1215c8 Fix documentation of Request object initialization (for advanced users) (#866)
fixes #676
2017-10-12 00:39:09 +03:00
Eldinnie
2aa456d637 remove Bot._message_wrapper (#822)
Moved tho code to the @message decorator instead

fixes #752
2017-10-11 23:38:00 +03:00
Eldinnie
d75e0f6014 Stabilize Coverage (#846)
* test_error added

* ignore unstables for coverage
2017-09-25 20:58:10 +02:00
Jeff
dbb3b16edc Add Job Class to docs (#845)
* fix job class missing from docs

* fix typo
2017-09-25 20:57:53 +02:00
Jeff
5614af1847 Docstring Fix for ext/filters.py (#830) 2017-09-15 23:56:16 +02:00
Marco Túlio Zuquim
e362a5b59d Small documentation fix in user.py (#829) 2017-09-15 23:55:35 +02:00
Yii Kuo Chong
e39b6abe61 Small documentation fix (#815)
Fixes #799
2017-09-07 22:55:06 +03:00
Pieter Schutz
6012fa65c1 Bump to version 8.0 2017-09-01 10:38:15 +02:00
Pieter Schutz
ef9dbacf7e Fix last issues for new release 2017-09-01 10:38:04 +02:00
Jannes Höke
1f5311b473 catch exceptions in error handlerfor errors that happen during polling (2) (#810)
* catch exceptions in error handlerfor errors that happen during polling

* add tests for error handlers that raise exceptions
2017-09-01 08:46:21 +02:00
Eldinnie
eae139d3e9 remove de_json() (#789)
* remove de_json()

* Remove or rename obsolete tests

* fixes according to rc
2017-09-01 08:45:22 +02:00
Eldinnie
160ffed5ad Remove Botan (#776) 2017-09-01 08:45:01 +02:00
Noam Meltzer
e018445513 Documentation update to PEP (#797) 2017-09-01 08:43:08 +02:00
Eldinnie
4601eedf0f Show status_updates in docs (#798)
* Show status_updates in docs

* Show status_updates in docs
2017-09-01 08:41:15 +02:00
Jeff
b6a0853896 Add Bot API 3.3 (#806)
* Bot API 3.3

* simpler helper methods (accept only custom names now)
attempt to fix circular import (not sure if its the correct way tho)
added helper methods into User object

* fix User objects in tests to contain is_bot required value

* fix User objects in tests to contain is_bot required value

* delete extra line that caused flake8 error

* fix swapped arguments
2017-09-01 08:40:05 +02:00
Noam Meltzer
16a49ec659 Remove DispatcherHandlerContinue + more unitests for dispatcher (#792)
The idea was nice, but it really complicated things for us and for the
user.
If a user wants to run more than one handler on an update, he can put
the handlers in different groups or he can have a single handler.
If a user wants to have multiple handlers in the same group which only
one of them should run on the update, he should use check_update().

Since we haven't released this code yet, there's no problem with
backward compatability.
2017-08-12 18:57:12 +03:00
Noam Meltzer
ee34d57521 Warn on small con_pool_size during custom initalization of Updater (#793)
fixes #787
2017-08-12 16:45:38 +03:00
Jacob Bom
5d7c6ad541 Switch to pytest + required fixes to code (#788)
Required fixes:
 - CallbackQuery is now comparable.
 - Message.effective_attachment, Message.photo,
   Message.new_chat_members, Message.new_chat_photo &
   Game.text_entitties semantic fixes - when they are not defined,
   return an empty list.
 - Docstring fix to Update class.
2017-08-12 00:58:41 +03:00
Noam Meltzer
915cd64140 Effective attachment (#766)
fixes #746
2017-08-08 00:25:19 +03:00
Eldinnie
56f7d18853 bot.py semantic fixes (#774)
offset for get_user_profile_photo can be zero.
edit_message_caption should raise ValueError in compliance with other methods. Also changed to snake_case
edit_message_reply_markup was even weirder
2017-08-08 00:13:32 +03:00
Eldinnie
b04869f36a docstring correction (#775)
[ci skip]
2017-08-08 00:11:44 +03:00
Eldinnie
70057a67c5 Regression fix for text_html & text_markdown (#777)
`text_html` & `text_markdown` reverted to the old semantics - URLs are not converted to hyperlinks.
To get the new behaviour there are matching `text_html_urled` & `text_markdown_urled` properties.
fixes #773
2017-08-08 00:10:48 +03:00
Eldinnie
8d4b484f7b Fix Game.to_dict() (#767)
`Game.to_dict()` fails if the `optional` parameter `test_entities` has it's default value `None`
This fixes that.
2017-08-05 00:02:51 +03:00
Jacob Bom
073bed3a01 Fix get_game_high_scores (#771) 2017-08-04 20:41:27 +03:00
Noam Meltzer
5ceb6f8f36 Docs fixes (#765)
* Clean warnings during build_sphinx

* fix documentation types
2017-08-02 05:56:07 +03:00
Jacob Bom
b3069348ca Add rich comparison to CallbackQuery (#764)
We currently have no tests for it. Noted for #756 and #757.
2017-08-01 23:07:12 +03:00
Eldinnie
d19ae5084a Add RESTRICTED as constant to ChatMember (#761) 2017-07-31 23:37:00 +03:00
Ihor Polyakov
6aacde189e Flow control ability in Dispatcher (#738)
fixes #666
2017-07-29 20:15:43 +03:00
Noam Meltzer
5d3f5575ab Sane defaults for tcp socket options on linux (#754)
Currently only for linux as most of our userbase is there.

fixes #535
2017-07-29 14:30:27 +03:00
Noam Meltzer
13ab6d43d3 CHANGES.rst: Added 7.0.1 release notes.
[ci skip]
2017-07-28 21:22:48 +03:00
Eldinnie
2ba7505eaf Fix TypeError exception in RegexHandler (#751)
fixes #750
2017-07-28 20:47:42 +03:00
Eldinnie
5ed06df840 callback query docstring (#749)
showed from instead of from_user and was missing the informational note about it.

[ci skip]
2017-07-28 17:41:25 +03:00
Noam Meltzer
796583323d Bump version to v7.0.0 2017-07-25 22:53:20 +03:00
Noam Meltzer
46d9240f36 Update vendored urllib3 gitmodule to the proper git revision
Refs #720
2017-07-25 22:37:58 +03:00
Ali Mirlou
e5b0795916 Typo fixed for docs (#747)
[ci skip]
2017-07-25 21:32:20 +03:00
Eldinnie
8d1d38cc4c send_* now accepts tg-objects (#742)
Fixes #731
2017-07-25 01:35:22 +03:00
Eldinnie
2d1028acb6 Add kwargs to data dict (#744)
Add kwargs to data dict for all bot-methods that are not decorated with `@message`

Fixes #733
2017-07-25 01:19:09 +03:00
Noam Meltzer
2aa31c6faa Remove urllib3 from reported packages for creating new github issues
[ci skip]
2017-07-25 00:22:03 +03:00