Skip to content

Commit dafafd2

Browse files
Merge pull request eternnoir#1735 from coder2020official/class_params
⚙️ Added some frequent parameters to classes(see full list)
2 parents b841fc1 + e002484 commit dafafd2

2 files changed

Lines changed: 215 additions & 20 deletions

File tree

‎telebot/__init__.py‎

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ class TeleBot:
131131
132132
:param use_class_middlewares: Use class middlewares, defaults to False
133133
:type use_class_middlewares: :obj:`bool`, optional
134+
135+
:param disable_web_page_preview: Default value for disable_web_page_preview, defaults to None
136+
:type disable_web_page_preview: :obj:`bool`, optional
137+
138+
:param disable_notification: Default value for disable_notification, defaults to None
139+
:type disable_notification: :obj:`bool`, optional
140+
141+
:param protect_content: Default value for protect_content, defaults to None
142+
:type protect_content: :obj:`bool`, optional
143+
144+
:param allow_sending_without_reply: Default value for allow_sending_without_reply, defaults to None
145+
:type allow_sending_without_reply: :obj:`bool`, optional
134146
"""
135147

136148
def __init__(
@@ -139,18 +151,32 @@ def __init__(
139151
next_step_backend: Optional[HandlerBackend]=None, reply_backend: Optional[HandlerBackend]=None,
140152
exception_handler: Optional[ExceptionHandler]=None, last_update_id: Optional[int]=0,
141153
suppress_middleware_excepions: Optional[bool]=False, state_storage: Optional[StateStorageBase]=StateMemoryStorage(),
142-
use_class_middlewares: Optional[bool]=False
154+
use_class_middlewares: Optional[bool]=False,
155+
disable_web_page_preview: Optional[bool]=None,
156+
disable_notification: Optional[bool]=None,
157+
protect_content: Optional[bool]=None,
158+
allow_sending_without_reply: Optional[bool]=None
143159
):
160+
161+
# update-related
144162
self.token = token
145-
self.parse_mode = parse_mode
146-
self.update_listener = []
147-
self.skip_pending = skip_pending
163+
self.skip_pending = skip_pending # backward compatibility
164+
self.last_update_id = last_update_id
165+
166+
# propertys
148167
self.suppress_middleware_excepions = suppress_middleware_excepions
168+
self.parse_mode = parse_mode
169+
self.disable_web_page_preview = disable_web_page_preview
170+
self.disable_notification = disable_notification
171+
self.protect_content = protect_content
172+
self.allow_sending_without_reply = allow_sending_without_reply
149173

174+
# threading-related
150175
self.__stop_polling = threading.Event()
151-
self.last_update_id = last_update_id
152176
self.exc_info = None
153177

178+
# states & register_next_step_handler
179+
self.current_states = state_storage
154180
self.next_step_backend = next_step_backend
155181
if not self.next_step_backend:
156182
self.next_step_backend = MemoryHandlerBackend()
@@ -159,8 +185,9 @@ def __init__(
159185
if not self.reply_backend:
160186
self.reply_backend = MemoryHandlerBackend()
161187

188+
# handlers
162189
self.exception_handler = exception_handler
163-
190+
self.update_listener = []
164191
self.message_handlers = []
165192
self.edited_message_handlers = []
166193
self.channel_post_handlers = []
@@ -178,8 +205,7 @@ def __init__(
178205
self.custom_filters = {}
179206
self.state_handlers = []
180207

181-
self.current_states = state_storage
182-
208+
# middlewares
183209
self.use_class_middlewares = use_class_middlewares
184210
if apihelper.ENABLE_MIDDLEWARE and not use_class_middlewares:
185211
self.typed_middleware_handlers = {
@@ -205,6 +231,8 @@ def __init__(
205231
'You are using class based middlewares while having ENABLE_MIDDLEWARE set to True. This is not recommended.'
206232
)
207233
self.middlewares = [] if use_class_middlewares else None
234+
235+
# threads
208236
self.threaded = threaded
209237
if self.threaded:
210238
self.worker_pool = util.ThreadPool(self, num_threads=num_threads)
@@ -1444,6 +1472,10 @@ def send_message(
14441472
:rtype: :class:`telebot.types.Message`
14451473
"""
14461474
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
1475+
disable_web_page_preview = self.disable_web_page_preview if (disable_web_page_preview is None) else disable_web_page_preview
1476+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1477+
protect_content = self.protect_content if (protect_content is None) else protect_content
1478+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
14471479

14481480
return types.Message.de_json(
14491481
apihelper.send_message(
@@ -1482,6 +1514,9 @@ def forward_message(
14821514
:return: On success, the sent Message is returned.
14831515
:rtype: :class:`telebot.types.Message`
14841516
"""
1517+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1518+
protect_content = self.protect_content if (protect_content is None) else protect_content
1519+
14851520
return types.Message.de_json(
14861521
apihelper.forward_message(self.token, chat_id, from_chat_id, message_id, disable_notification, timeout, protect_content))
14871522

@@ -1544,6 +1579,11 @@ def copy_message(
15441579
:return: On success, the sent Message is returned.
15451580
:rtype: :class:`telebot.types.Message`
15461581
"""
1582+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1583+
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
1584+
protect_content = self.protect_content if (protect_content is None) else protect_content
1585+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
1586+
15471587
return types.MessageID.de_json(
15481588
apihelper.copy_message(self.token, chat_id, from_chat_id, message_id, caption, parse_mode, caption_entities,
15491589
disable_notification, reply_to_message_id, allow_sending_without_reply, reply_markup,
@@ -1621,6 +1661,10 @@ def send_dice(
16211661
:return: On success, the sent Message is returned.
16221662
:rtype: :class:`telebot.types.Message`
16231663
"""
1664+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1665+
protect_content = self.protect_content if (protect_content is None) else protect_content
1666+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
1667+
16241668
return types.Message.de_json(
16251669
apihelper.send_dice(
16261670
self.token, chat_id, emoji, disable_notification, reply_to_message_id,
@@ -1684,6 +1728,9 @@ def send_photo(
16841728
:rtype: :class:`telebot.types.Message`
16851729
"""
16861730
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
1731+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1732+
protect_content = self.protect_content if (protect_content is None) else protect_content
1733+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
16871734

16881735
return types.Message.de_json(
16891736
apihelper.send_photo(
@@ -1769,6 +1816,9 @@ def send_audio(
17691816
:rtype: :class:`telebot.types.Message`
17701817
"""
17711818
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
1819+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1820+
protect_content = self.protect_content if (protect_content is None) else protect_content
1821+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
17721822

17731823
return types.Message.de_json(
17741824
apihelper.send_audio(
@@ -1837,6 +1887,9 @@ def send_voice(
18371887
:return: On success, the sent Message is returned.
18381888
"""
18391889
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
1890+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1891+
protect_content = self.protect_content if (protect_content is None) else protect_content
1892+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
18401893

18411894
return types.Message.de_json(
18421895
apihelper.send_voice(
@@ -1917,6 +1970,10 @@ def send_document(
19171970
:rtype: :class:`telebot.types.Message`
19181971
"""
19191972
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
1973+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
1974+
protect_content = self.protect_content if (protect_content is None) else protect_content
1975+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
1976+
19201977
if data and not(document):
19211978
# function typo miss compatibility
19221979
document = data
@@ -1981,9 +2038,14 @@ def send_sticker(
19812038
:return: On success, the sent Message is returned.
19822039
:rtype: :class:`telebot.types.Message`
19832040
"""
2041+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2042+
protect_content = self.protect_content if (protect_content is None) else protect_content
2043+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2044+
19842045
if data and not(sticker):
19852046
# function typo miss compatibility
19862047
sticker = data
2048+
19872049
return types.Message.de_json(
19882050
apihelper.send_data(
19892051
self.token, chat_id, sticker, 'sticker',
@@ -2071,6 +2133,10 @@ def send_video(
20712133
:rtype: :class:`telebot.types.Message`
20722134
"""
20732135
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
2136+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2137+
protect_content = self.protect_content if (protect_content is None) else protect_content
2138+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2139+
20742140
if data and not(video):
20752141
# function typo miss compatibility
20762142
video = data
@@ -2157,6 +2223,9 @@ def send_animation(
21572223
:rtype: :class:`telebot.types.Message`
21582224
"""
21592225
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
2226+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2227+
protect_content = self.protect_content if (protect_content is None) else protect_content
2228+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
21602229

21612230
return types.Message.de_json(
21622231
apihelper.send_animation(
@@ -2224,6 +2293,10 @@ def send_video_note(
22242293
:return: On success, the sent Message is returned.
22252294
:rtype: :class:`telebot.types.Message`
22262295
"""
2296+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2297+
protect_content = self.protect_content if (protect_content is None) else protect_content
2298+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2299+
22272300
return types.Message.de_json(
22282301
apihelper.send_video_note(
22292302
self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
@@ -2270,6 +2343,10 @@ def send_media_group(
22702343
:return: On success, an array of Messages that were sent is returned.
22712344
:rtype: List[types.Message]
22722345
"""
2346+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2347+
protect_content = self.protect_content if (protect_content is None) else protect_content
2348+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2349+
22732350
result = apihelper.send_media_group(
22742351
self.token, chat_id, media, disable_notification, reply_to_message_id, timeout,
22752352
allow_sending_without_reply, protect_content)
@@ -2338,6 +2415,10 @@ def send_location(
23382415
:return: On success, the sent Message is returned.
23392416
:rtype: :class:`telebot.types.Message`
23402417
"""
2418+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2419+
protect_content = self.protect_content if (protect_content is None) else protect_content
2420+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2421+
23412422
return types.Message.de_json(
23422423
apihelper.send_location(
23432424
self.token, chat_id, latitude, longitude, live_period,
@@ -2509,6 +2590,10 @@ def send_venue(
25092590
:return: On success, the sent Message is returned.
25102591
:rtype: :class:`telebot.types.Message`
25112592
"""
2593+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2594+
protect_content = self.protect_content if (protect_content is None) else protect_content
2595+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2596+
25122597
return types.Message.de_json(
25132598
apihelper.send_venue(
25142599
self.token, chat_id, latitude, longitude, title, address, foursquare_id, foursquare_type,
@@ -2571,6 +2656,10 @@ def send_contact(
25712656
:return: On success, the sent Message is returned.
25722657
:rtype: :class:`telebot.types.Message`
25732658
"""
2659+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
2660+
protect_content = self.protect_content if (protect_content is None) else protect_content
2661+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
2662+
25742663
return types.Message.de_json(
25752664
apihelper.send_contact(
25762665
self.token, chat_id, phone_number, first_name, last_name, vcard,
@@ -3322,6 +3411,8 @@ def pin_chat_message(
33223411
:return: True on success.
33233412
:rtype: :obj:`bool`
33243413
"""
3414+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
3415+
33253416
return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification)
33263417

33273418
def unpin_chat_message(self, chat_id: Union[int, str], message_id: Optional[int]=None) -> bool:
@@ -3403,6 +3494,7 @@ def edit_message_text(
34033494
:rtype: :obj:`types.Message` or :obj:`bool`
34043495
"""
34053496
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
3497+
disable_web_page_preview = self.disable_web_page_preview if (disable_web_page_preview is None) else disable_web_page_preview
34063498

34073499
result = apihelper.edit_message_text(self.token, text, chat_id, message_id, inline_message_id, parse_mode,
34083500
entities, disable_web_page_preview, reply_markup)
@@ -3515,6 +3607,10 @@ def send_game(
35153607
:return: On success, the sent Message is returned.
35163608
:rtype: :obj:`types.Message`
35173609
"""
3610+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
3611+
protect_content = self.protect_content if (protect_content is None) else protect_content
3612+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
3613+
35183614
result = apihelper.send_game(
35193615
self.token, chat_id, game_short_name, disable_notification,
35203616
reply_to_message_id, reply_markup, timeout,
@@ -3717,6 +3813,10 @@ def send_invoice(
37173813
:return: On success, the sent Message is returned.
37183814
:rtype: :obj:`types.Message`
37193815
"""
3816+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
3817+
protect_content = self.protect_content if (protect_content is None) else protect_content
3818+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
3819+
37203820
result = apihelper.send_invoice(
37213821
self.token, chat_id, title, description, invoice_payload, provider_token,
37223822
currency, prices, start_parameter, photo_url, photo_size, photo_width,
@@ -3918,6 +4018,10 @@ def send_poll(
39184018
:return: On success, the sent Message is returned.
39194019
:rtype: :obj:`types.Message`
39204020
"""
4021+
disable_notification = self.disable_notification if (disable_notification is None) else disable_notification
4022+
protect_content = self.protect_content if (protect_content is None) else protect_content
4023+
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
4024+
39214025
if isinstance(question, types.Poll):
39224026
raise RuntimeError("The send_poll signature was changed, please see send_poll function details.")
39234027

0 commit comments

Comments
 (0)