Skip to content

Commit 3863b4f

Browse files
saschalalalajh0ker
authored andcommitted
Rename shortcut functions to snake_case (python-telegram-bot#661)
* Rename shortcut functions to snake_case * More function renaming * Example function rewrite * Add myself to authors.rst * More function renaming * Rename mockbot test functions * Break comment line for flake max line length
1 parent 25912dc commit 3863b4f

File tree

11 files changed

+68
-66
lines changed

11 files changed

+68
-66
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The following wonderful people contributed directly or indirectly to this projec
5151
- `Pieter Schutz <https://github.com/eldinnie>`_
5252
- `Rahiel Kasim <https://github.com/rahiel>`_
5353
- `Joscha Götzer <https://github.com/Rostgnom>`_
54+
- `Sascha <https://github.com/saschalalala>`_
5455
- `Shelomentsev D <https://github.com/shelomentsevd>`_
5556
- `sooyhwang <https://github.com/sooyhwang>`_
5657
- `thodnev <https://github.com/thodnev>`_

examples/paymentbot.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def shipping_callback(bot, update):
7575
# check the payload, is this from your bot?
7676
if query.invoice_payload != 'Custom-Payload':
7777
# answer False pre_checkout_query
78-
bot.answerShippingQuery(shipping_query_id=query.id, ok=False,
79-
error_message="Something went wrong...")
78+
bot.answer_shipping_query(shipping_query_id=query.id, ok=False,
79+
error_message="Something went wrong...")
8080
return
8181
else:
8282
options = list()
@@ -85,8 +85,8 @@ def shipping_callback(bot, update):
8585
# an array of LabeledPrice objects
8686
price_list = [LabeledPrice('B1', 150), LabeledPrice('B2', 200)]
8787
options.append(ShippingOption('2', 'Shipping Option B', price_list))
88-
bot.answerShippingQuery(shipping_query_id=query.id, ok=True,
89-
shipping_options=options)
88+
bot.answer_shipping_query(shipping_query_id=query.id, ok=True,
89+
shipping_options=options)
9090

9191

9292
# after (optional) shipping, it's the pre-checkout
@@ -95,10 +95,10 @@ def precheckout_callback(bot, update):
9595
# check the payload, is this from your bot?
9696
if query.invoice_payload != 'Custom-Payload':
9797
# answer False pre_checkout_query
98-
bot.answerPreCheckoutQuery(pre_checkout_query_id=query.id, ok=False,
99-
error_message="Something went wrong...")
98+
bot.answer_pre_checkout_query(pre_checkout_query_id=query.id, ok=False,
99+
error_message="Something went wrong...")
100100
else:
101-
bot.answerPreCheckoutQuery(pre_checkout_query_id=query.id, ok=True)
101+
bot.answer_pre_checkout_query(pre_checkout_query_id=query.id, ok=True)
102102

103103

104104
# finally, after contacting to the payment provider...

telegram/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def info(func):
8585
@functools.wraps(func)
8686
def decorator(self, *args, **kwargs):
8787
if not self.bot:
88-
self.getMe()
88+
self.get_me()
8989

9090
result = func(self, *args, **kwargs)
9191
return result

telegram/chat.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,29 @@ def de_json(data, bot):
8989
return Chat(bot=bot, **data)
9090

9191
def send_action(self, *args, **kwargs):
92-
"""Shortcut for ``bot.sendChatAction(update.message.chat.id, *args, **kwargs)``"""
93-
return self.bot.sendChatAction(self.id, *args, **kwargs)
92+
"""Shortcut for ``bot.send_chat_action(update.message.chat.id, *args, **kwargs)``"""
93+
return self.bot.send_chat_action(self.id, *args, **kwargs)
9494

9595
def leave(self, *args, **kwargs):
96-
"""Shortcut for ``bot.leaveChat(update.message.chat.id, *args, **kwargs)``"""
97-
return self.bot.leaveChat(self.id, *args, **kwargs)
96+
"""Shortcut for ``bot.leave_chat(update.message.chat.id, *args, **kwargs)``"""
97+
return self.bot.leave_chat(self.id, *args, **kwargs)
9898

9999
def get_administrators(self, *args, **kwargs):
100-
"""Shortcut for ``bot.getChatAdministrators(update.message.chat.id, *args, **kwargs)``"""
101-
return self.bot.getChatAdministrators(self.id, *args, **kwargs)
100+
"""Shortcut for ``bot.get_chat_administrators(update.message.chat.id, *args, **kwargs)``"""
101+
return self.bot.get_chat_administrators(self.id, *args, **kwargs)
102102

103103
def get_members_count(self, *args, **kwargs):
104-
"""Shortcut for ``bot.getChatMembersCount(update.message.chat.id, *args, **kwargs)``"""
105-
return self.bot.getChatMembersCount(self.id, *args, **kwargs)
104+
"""Shortcut for ``bot.get_chat_members_count(update.message.chat.id, *args, **kwargs)``"""
105+
return self.bot.get_chat_members_count(self.id, *args, **kwargs)
106106

107107
def get_member(self, *args, **kwargs):
108-
"""Shortcut for ``bot.getChatMember(update.message.chat.id, *args, **kwargs)``"""
109-
return self.bot.getChatMember(self.id, *args, **kwargs)
108+
"""Shortcut for ``bot.get_chat_member(update.message.chat.id, *args, **kwargs)``"""
109+
return self.bot.get_chat_member(self.id, *args, **kwargs)
110110

111111
def kick_member(self, *args, **kwargs):
112-
"""Shortcut for ``bot.kickChatMember(update.message.chat.id, *args, **kwargs)``"""
113-
return self.bot.kickChatMember(self.id, *args, **kwargs)
112+
"""Shortcut for ``bot.kick_chat_member(update.message.chat.id, *args, **kwargs)``"""
113+
return self.bot.kick_chat_member(self.id, *args, **kwargs)
114114

115115
def unban_member(self, *args, **kwargs):
116-
"""Shortcut for ``bot.unbanChatMember(update.message.chat.id, *args, **kwargs)``"""
117-
return self.bot.unbanChatMember(self.id, *args, **kwargs)
116+
"""Shortcut for ``bot.unban_chat_member(update.message.chat.id, *args, **kwargs)``"""
117+
return self.bot.unban_chat_member(self.id, *args, **kwargs)

telegram/ext/updater.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _start_polling(self, poll_interval, timeout, read_latency, bootstrap_retries
264264

265265
while self.running:
266266
try:
267-
updates = self.bot.getUpdates(
267+
updates = self.bot.get_updates(
268268
self.last_update_id,
269269
timeout=timeout,
270270
read_latency=read_latency,
@@ -367,11 +367,11 @@ def _bootstrap(self, max_retries, clean, webhook_url, allowed_updates, cert=None
367367
try:
368368
if clean:
369369
# Disable webhook for cleaning
370-
self.bot.deleteWebhook()
370+
self.bot.delete_webhook()
371371
self._clean_updates()
372372
sleep(1)
373373

374-
self.bot.setWebhook(
374+
self.bot.set_webhook(
375375
url=webhook_url, certificate=cert, allowed_updates=allowed_updates)
376376
except (Unauthorized, InvalidToken):
377377
raise
@@ -390,9 +390,9 @@ def _bootstrap(self, max_retries, clean, webhook_url, allowed_updates, cert=None
390390

391391
def _clean_updates(self):
392392
self.logger.debug('Cleaning updates from Telegram server')
393-
updates = self.bot.getUpdates()
393+
updates = self.bot.get_updates()
394394
while updates:
395-
updates = self.bot.getUpdates(updates[-1].update_id + 1)
395+
updates = self.bot.get_updates(updates[-1].update_id + 1)
396396

397397
def stop(self):
398398
"""

telegram/inlinequery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ def to_dict(self):
9191
return data
9292

9393
def answer(self, *args, **kwargs):
94-
"""Shortcut for ``bot.answerInlineQuery(update.inline_query.id, *args, **kwargs)``"""
95-
return self.bot.answerInlineQuery(self.id, *args, **kwargs)
94+
"""Shortcut for ``bot.answer_inline_query(update.inline_query.id, *args, **kwargs)``"""
95+
return self.bot.answer_inline_query(self.id, *args, **kwargs)

telegram/message.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def _quote(self, kwargs):
328328

329329
def reply_text(self, *args, **kwargs):
330330
"""
331-
Shortcut for ``bot.sendMessage(update.message.chat_id, *args, **kwargs)``
331+
Shortcut for ``bot.send_message(update.message.chat_id, *args, **kwargs)``
332332
333333
Keyword Args:
334334
quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to
@@ -337,11 +337,11 @@ def reply_text(self, *args, **kwargs):
337337
"""
338338

339339
self._quote(kwargs)
340-
return self.bot.sendMessage(self.chat_id, *args, **kwargs)
340+
return self.bot.send_message(self.chat_id, *args, **kwargs)
341341

342342
def reply_photo(self, *args, **kwargs):
343343
"""
344-
Shortcut for ``bot.sendPhoto(update.message.chat_id, *args, **kwargs)``
344+
Shortcut for ``bot.send_photo(update.message.chat_id, *args, **kwargs)``
345345
346346
Keyword Args:
347347
quote (Optional[bool]): If set to ``True``, the photo is sent as an actual reply to
@@ -354,11 +354,11 @@ def reply_photo(self, *args, **kwargs):
354354
"""
355355

356356
self._quote(kwargs)
357-
return self.bot.sendPhoto(self.chat_id, *args, **kwargs)
357+
return self.bot.send_photo(self.chat_id, *args, **kwargs)
358358

359359
def reply_audio(self, *args, **kwargs):
360360
"""
361-
Shortcut for ``bot.sendAudio(update.message.chat_id, *args, **kwargs)``
361+
Shortcut for ``bot.send_audio(update.message.chat_id, *args, **kwargs)``
362362
363363
Keyword Args:
364364
quote (Optional[bool]): If set to ``True``, the audio is sent as an actual reply to
@@ -371,11 +371,11 @@ def reply_audio(self, *args, **kwargs):
371371
"""
372372

373373
self._quote(kwargs)
374-
return self.bot.sendAudio(self.chat_id, *args, **kwargs)
374+
return self.bot.send_audio(self.chat_id, *args, **kwargs)
375375

376376
def reply_document(self, *args, **kwargs):
377377
"""
378-
Shortcut for ``bot.sendDocument(update.message.chat_id, *args, **kwargs)``
378+
Shortcut for ``bot.send_document(update.message.chat_id, *args, **kwargs)``
379379
380380
Keyword Args:
381381
quote (Optional[bool]): If set to ``True``, the document is sent as an actual reply to
@@ -388,11 +388,11 @@ def reply_document(self, *args, **kwargs):
388388
"""
389389

390390
self._quote(kwargs)
391-
return self.bot.sendDocument(self.chat_id, *args, **kwargs)
391+
return self.bot.send_document(self.chat_id, *args, **kwargs)
392392

393393
def reply_sticker(self, *args, **kwargs):
394394
"""
395-
Shortcut for ``bot.sendSticker(update.message.chat_id, *args, **kwargs)``
395+
Shortcut for ``bot.send_sticker(update.message.chat_id, *args, **kwargs)``
396396
397397
Keyword Args:
398398
quote (Optional[bool]): If set to ``True``, the sticker is sent as an actual reply to
@@ -405,11 +405,11 @@ def reply_sticker(self, *args, **kwargs):
405405
"""
406406

407407
self._quote(kwargs)
408-
return self.bot.sendSticker(self.chat_id, *args, **kwargs)
408+
return self.bot.send_sticker(self.chat_id, *args, **kwargs)
409409

410410
def reply_video(self, *args, **kwargs):
411411
"""
412-
Shortcut for ``bot.sendVideo(update.message.chat_id, *args, **kwargs)``
412+
Shortcut for ``bot.send_video(update.message.chat_id, *args, **kwargs)``
413413
414414
Keyword Args:
415415
quote (Optional[bool]): If set to ``True``, the video is sent as an actual reply to
@@ -422,7 +422,7 @@ def reply_video(self, *args, **kwargs):
422422
"""
423423

424424
self._quote(kwargs)
425-
return self.bot.sendVideo(self.chat_id, *args, **kwargs)
425+
return self.bot.send_video(self.chat_id, *args, **kwargs)
426426

427427
def reply_video_note(self, *args, **kwargs):
428428
"""
@@ -443,7 +443,7 @@ def reply_video_note(self, *args, **kwargs):
443443

444444
def reply_voice(self, *args, **kwargs):
445445
"""
446-
Shortcut for ``bot.sendVoice(update.message.chat_id, *args, **kwargs)``
446+
Shortcut for ``bot.send_voice(update.message.chat_id, *args, **kwargs)``
447447
448448
Keyword Args:
449449
quote (Optional[bool]): If set to ``True``, the voice is sent as an actual reply to
@@ -456,11 +456,11 @@ def reply_voice(self, *args, **kwargs):
456456
"""
457457

458458
self._quote(kwargs)
459-
return self.bot.sendVoice(self.chat_id, *args, **kwargs)
459+
return self.bot.send_voice(self.chat_id, *args, **kwargs)
460460

461461
def reply_location(self, *args, **kwargs):
462462
"""
463-
Shortcut for ``bot.sendLocation(update.message.chat_id, *args, **kwargs)``
463+
Shortcut for ``bot.send_location(update.message.chat_id, *args, **kwargs)``
464464
465465
Keyword Args:
466466
quote (Optional[bool]): If set to ``True``, the location is sent as an actual reply to
@@ -473,11 +473,11 @@ def reply_location(self, *args, **kwargs):
473473
"""
474474

475475
self._quote(kwargs)
476-
return self.bot.sendLocation(self.chat_id, *args, **kwargs)
476+
return self.bot.send_location(self.chat_id, *args, **kwargs)
477477

478478
def reply_venue(self, *args, **kwargs):
479479
"""
480-
Shortcut for ``bot.sendVenue(update.message.chat_id, *args, **kwargs)``
480+
Shortcut for ``bot.send_venue(update.message.chat_id, *args, **kwargs)``
481481
482482
Keyword Args:
483483
quote (Optional[bool]): If set to ``True``, the venue is sent as an actual reply to
@@ -490,11 +490,11 @@ def reply_venue(self, *args, **kwargs):
490490
"""
491491

492492
self._quote(kwargs)
493-
return self.bot.sendVenue(self.chat_id, *args, **kwargs)
493+
return self.bot.send_venue(self.chat_id, *args, **kwargs)
494494

495495
def reply_contact(self, *args, **kwargs):
496496
"""
497-
Shortcut for ``bot.sendContact(update.message.chat_id, *args, **kwargs)``
497+
Shortcut for ``bot.send_contact(update.message.chat_id, *args, **kwargs)``
498498
499499
Keyword Args:
500500
quote (Optional[bool]): If set to ``True``, the contact is sent as an actual reply to
@@ -507,12 +507,12 @@ def reply_contact(self, *args, **kwargs):
507507
"""
508508

509509
self._quote(kwargs)
510-
return self.bot.sendContact(self.chat_id, *args, **kwargs)
510+
return self.bot.send_contact(self.chat_id, *args, **kwargs)
511511

512512
def forward(self, chat_id, disable_notification=False):
513513
"""Shortcut for
514514
515-
>>> bot.forwardMessage(chat_id=chat_id,
515+
>>> bot.forward_message(chat_id=chat_id,
516516
... from_chat_id=update.message.chat_id,
517517
... disable_notification=disable_notification,
518518
... message_id=update.message.message_id)
@@ -521,7 +521,7 @@ def forward(self, chat_id, disable_notification=False):
521521
:class:`telegram.Message`: On success, instance representing the message forwarded.
522522
523523
"""
524-
return self.bot.forwardMessage(
524+
return self.bot.forward_message(
525525
chat_id=chat_id,
526526
from_chat_id=self.chat_id,
527527
disable_notification=disable_notification,
@@ -531,7 +531,7 @@ def edit_text(self, *args, **kwargs):
531531
"""
532532
Shortcut for
533533
534-
>>> bot.editMessageText(chat_id=message.chat_id,
534+
>>> bot.edit_message_text(chat_id=message.chat_id,
535535
... message_id=message.message_id,
536536
... *args, **kwargs)
537537
@@ -548,7 +548,7 @@ def edit_caption(self, *args, **kwargs):
548548
"""
549549
Shortcut for
550550
551-
>>> bot.editMessageCaption(chat_id=message.chat_id,
551+
>>> bot.edit_message_caption(chat_id=message.chat_id,
552552
... message_id=message.message_id,
553553
... *args, **kwargs)
554554
@@ -564,7 +564,7 @@ def edit_reply_markup(self, *args, **kwargs):
564564
"""
565565
Shortcut for
566566
567-
>>> bot.editReplyMarkup(chat_id=message.chat_id,
567+
>>> bot.edit_message_reply_markup(chat_id=message.chat_id,
568568
... message_id=message.message_id,
569569
... *args, **kwargs)
570570

telegram/precheckoutquery.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def to_dict(self):
9595

9696
def answer(self, *args, **kwargs):
9797
"""
98-
Shortcut for ``bot.answerPreCheckoutQuery(update.pre_checkout_query.id, *args, **kwargs)``
98+
Shortcut for
99+
``bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)``
99100
"""
100-
return self.bot.answerPreCheckoutQuery(self.id, *args, **kwargs)
101+
return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)

telegram/shippingquery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ def to_dict(self):
7979
return data
8080

8181
def answer(self, *args, **kwargs):
82-
"""Shortcut for ``bot.answerShippingQuery(update.shipping_query.id, *args, **kwargs)``"""
83-
return self.bot.answerShippingQuery(self.id, *args, **kwargs)
82+
"""Shortcut for ``bot.answer_shipping_query(update.shipping_query.id, *args, **kwargs)``"""
83+
return self.bot.answer_shipping_query(self.id, *args, **kwargs)

telegram/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def de_json(data, bot):
9696

9797
def get_profile_photos(self, *args, **kwargs):
9898
"""
99-
Shortcut for ``bot.getUserProfilePhotos(update.message.from_user.id, *args, **kwargs)``
99+
Shortcut for ``bot.get_user_profile_photos(update.message.from_user.id, *args, **kwargs)``
100100
"""
101-
return self.bot.getUserProfilePhotos(self.id, *args, **kwargs)
101+
return self.bot.get_user_profile_photos(self.id, *args, **kwargs)
102102

103103
@staticmethod
104104
def de_list(data, bot):

0 commit comments

Comments
 (0)