1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Fix documentation

This commit is contained in:
coder2020official
2022-03-07 14:24:28 +05:00
parent 854f6a9506
commit c8fb83c97c
8 changed files with 113 additions and 128 deletions

View File

@@ -28,14 +28,6 @@ Asynchronous storage for states
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
asyncio_helper file
-------------------
.. automodule:: telebot.asyncio_helper
:members:
:undoc-members:
:show-inheritance:
Asyncio handler backends Asyncio handler backends
------------------------ ------------------------

View File

@@ -25,7 +25,7 @@ Pypi: `Pypi <https://pypi.org/project/pyTelegramBotAPI/>`__
Source: `Github repository <https://github.com/eternnoir/pyTelegramBotAPI>`__ Source: `Github repository <https://github.com/eternnoir/pyTelegramBotAPI>`__
Some features: Some features:
------------- --------------
Easy to learn and use. Easy to learn and use.
Easy to understand. Easy to understand.

View File

@@ -3,8 +3,6 @@ Installation Guide
================== ==================
:toctree
Using PIP Using PIP
---------- ----------
.. code-block:: bash .. code-block:: bash

View File

@@ -33,11 +33,3 @@ handler_backends file
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
apihelper
------------------------
.. automodule:: telebot.apihelper
:members:
:undoc-members:
:show-inheritance:

View File

@@ -343,7 +343,7 @@ class TeleBot:
:param offset: Integer. Identifier of the first update to be returned. :param offset: Integer. Identifier of the first update to be returned.
:param limit: Integer. Limits the number of updates to be retrieved. :param limit: Integer. Limits the number of updates to be retrieved.
:param timeout: Integer. Request connection timeout :param timeout: Integer. Request connection timeout
:param long_polling_timeout. Timeout in seconds for long polling. :param long_polling_timeout: Timeout in seconds for long polling.
:return: array of Updates :return: array of Updates
""" """
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates, long_polling_timeout) json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates, long_polling_timeout)
@@ -876,7 +876,7 @@ class TeleBot:
""" """
Use this method to get a list of administrators in a chat. Use this method to get a list of administrators in a chat.
On success, returns an Array of ChatMember objects that contains On success, returns an Array of ChatMember objects that contains
information about all chat administrators except other bots. information about all chat administrators except other bots.
Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators
@@ -932,8 +932,7 @@ class TeleBot:
Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset
:param chat_id: Unique identifier for the target chat or username of the target supergroup :param chat_id: Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
(in the format @supergroupusername)
:return: API reply. :return: API reply.
""" """
result = apihelper.delete_chat_sticker_set(self.token, chat_id) result = apihelper.delete_chat_sticker_set(self.token, chat_id)
@@ -1199,7 +1198,7 @@ class TeleBot:
:param duration: Duration of sent audio in seconds :param duration: Duration of sent audio in seconds
:param reply_to_message_id: :param reply_to_message_id:
:param reply_markup: :param reply_markup:
:param parse_mode :param parse_mode:
:param disable_notification: :param disable_notification:
:param timeout: :param timeout:
:param caption_entities: :param caption_entities:
@@ -1663,7 +1662,7 @@ class TeleBot:
:return: API reply. :type: boolean :return: API reply. :type: boolean
""" """
return apihelper.send_chat_action(self.token, chat_id, action, timeout) return apihelper.send_chat_action(self.token, chat_id, action, timeout)
def kick_chat_member( def kick_chat_member(
self, chat_id: Union[int, str], user_id: int, self, chat_id: Union[int, str], user_id: int,
until_date:Optional[Union[int, datetime]]=None, until_date:Optional[Union[int, datetime]]=None,
@@ -1742,11 +1741,10 @@ class TeleBot:
If user is restricted for more than 366 days or less than 30 seconds from the current time, If user is restricted for more than 366 days or less than 30 seconds from the current time,
they are considered to be restricted forever they are considered to be restricted forever
:param can_send_messages: Pass True, if the user can send text messages, contacts, locations and venues :param can_send_messages: Pass True, if the user can send text messages, contacts, locations and venues
:param can_send_media_messages Pass True, if the user can send audios, documents, photos, videos, video notes :param can_send_media_messages: Pass True, if the user can send audios, documents, photos, videos, video notes
and voice notes, implies can_send_messages and voice notes, implies can_send_messages
:param can_send_polls: Pass True, if the user is allowed to send polls, implies can_send_messages :param can_send_polls: Pass True, if the user is allowed to send polls, implies can_send_messages
:param can_send_other_messages: Pass True, if the user can send animations, games, stickers and :param can_send_other_messages: Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
use inline bots, implies can_send_media_messages
:param can_add_web_page_previews: Pass True, if the user may add web page previews to their messages, :param can_add_web_page_previews: Pass True, if the user may add web page previews to their messages,
implies can_send_media_messages implies can_send_media_messages
:param can_change_info: Pass True, if the user is allowed to change the chat title, photo and other settings. :param can_change_info: Pass True, if the user is allowed to change the chat title, photo and other settings.
@@ -1932,7 +1930,7 @@ class TeleBot:
""" """
Use this method to revoke an invite link created by the bot. Use this method to revoke an invite link created by the bot.
Note: If the primary link is revoked, a new link is automatically generated The bot must be an administrator Note: If the primary link is revoked, a new link is automatically generated The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#revokechatinvitelink Telegram documentation: https://core.telegram.org/bots/api#revokechatinvitelink
@@ -1994,7 +1992,7 @@ class TeleBot:
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Returns True on success. Returns True on success.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins
setting is off in the target group. setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#setchatphoto Telegram documentation: https://core.telegram.org/bots/api#setchatphoto
@@ -2010,8 +2008,7 @@ class TeleBot:
Use this method to delete a chat photo. Photos can't be changed for private chats. Use this method to delete a chat photo. Photos can't be changed for private chats.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Returns True on success. Returns True on success.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.
setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto
@@ -2078,7 +2075,7 @@ class TeleBot:
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Returns True on success. Returns True on success.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins
setting is off in the target group. setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#setchattitle Telegram documentation: https://core.telegram.org/bots/api#setchattitle
@@ -2989,30 +2986,32 @@ class TeleBot:
All message handlers are tested in the order they were added. All message handlers are tested in the order they were added.
Example: Example:
.. code-block:: python
bot = TeleBot('TOKEN') bot = TeleBot('TOKEN')
# Handles all messages which text matches regexp. # Handles all messages which text matches regexp.
@bot.message_handler(regexp='someregexp') @bot.message_handler(regexp='someregexp')
def command_help(message): def command_help(message):
bot.send_message(message.chat.id, 'Did someone call for help?') bot.send_message(message.chat.id, 'Did someone call for help?')
# Handles messages in private chat # Handles messages in private chat
@bot.message_handler(chat_types=['private']) # You can add more chat types @bot.message_handler(chat_types=['private']) # You can add more chat types
def command_help(message): def command_help(message):
bot.send_message(message.chat.id, 'Private chat detected, sir!') bot.send_message(message.chat.id, 'Private chat detected, sir!')
# Handle all sent documents of type 'text/plain'. # Handle all sent documents of type 'text/plain'.
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', @bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain',
content_types=['document']) content_types=['document'])
def command_handle_document(message): def command_handle_document(message):
bot.send_message(message.chat.id, 'Document received, sir!') bot.send_message(message.chat.id, 'Document received, sir!')
# Handle all other messages. # Handle all other messages.
@bot.message_handler(func=lambda message: True, content_types=['audio', 'photo', 'voice', 'video', 'document', @bot.message_handler(func=lambda message: True, content_types=['audio', 'photo', 'voice', 'video', 'document',
'text', 'location', 'contact', 'sticker']) 'text', 'location', 'contact', 'sticker'])
def default_command(message): def default_command(message):
bot.send_message(message.chat.id, "This is the default command handler.") bot.send_message(message.chat.id, "This is the default command handler.")
:param commands: Optional list of strings (commands to handle). :param commands: Optional list of strings (commands to handle).
:param regexp: Optional regular expression. :param regexp: Optional regular expression.

View File

@@ -584,29 +584,31 @@ class AsyncTeleBot:
Example: Example:
bot = TeleBot('TOKEN') .. code-block:: python
# Handles all messages which text matches regexp. bot = TeleBot('TOKEN')
@bot.message_handler(regexp='someregexp')
async def command_help(message):
bot.send_message(message.chat.id, 'Did someone call for help?')
# Handles messages in private chat # Handles all messages which text matches regexp.
@bot.message_handler(chat_types=['private']) # You can add more chat types @bot.message_handler(regexp='someregexp')
async def command_help(message): async def command_help(message):
bot.send_message(message.chat.id, 'Private chat detected, sir!') bot.send_message(message.chat.id, 'Did someone call for help?')
# Handle all sent documents of type 'text/plain'. # Handles messages in private chat
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', @bot.message_handler(chat_types=['private']) # You can add more chat types
content_types=['document']) async def command_help(message):
async def command_handle_document(message): bot.send_message(message.chat.id, 'Private chat detected, sir!')
bot.send_message(message.chat.id, 'Document received, sir!')
# Handle all other messages. # Handle all sent documents of type 'text/plain'.
@bot.message_handler(func=lambda message: True, content_types=['audio', 'photo', 'voice', 'video', 'document', @bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain',
'text', 'location', 'contact', 'sticker']) content_types=['document'])
async def async default_command(message): async def command_handle_document(message):
bot.send_message(message.chat.id, "This is the async default command handler.") bot.send_message(message.chat.id, 'Document received, sir!')
# Handle all other messages.
@bot.message_handler(func=lambda message: True, content_types=['audio', 'photo', 'voice', 'video', 'document',
'text', 'location', 'contact', 'sticker'])
async def async default_command(message):
bot.send_message(message.chat.id, "This is the async default command handler.")
:param commands: Optional list of strings (commands to handle). :param commands: Optional list of strings (commands to handle).
:param regexp: Optional regular expression. :param regexp: Optional regular expression.
@@ -950,6 +952,7 @@ class AsyncTeleBot:
""" """
Description: TBD Description: TBD
:param func: :param func:
:param kwargs: :param kwargs:
:return: :return:
@@ -1487,13 +1490,12 @@ class AsyncTeleBot:
""" """
Use this method to get a list of administrators in a chat. Use this method to get a list of administrators in a chat.
On success, returns an Array of ChatMember objects that contains On success, returns an Array of ChatMember objects that contains
information about all chat administrators except other bots. information about all chat administrators except other bots.
Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators
:param chat_id: Unique identifier for the target chat or username :param chat_id: Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
of the target supergroup or channel (in the format @channelusername) :return: API reply.
:return:
""" """
result = await asyncio_helper.get_chat_administrators(self.token, chat_id) result = await asyncio_helper.get_chat_administrators(self.token, chat_id)
return [types.ChatMember.de_json(r) for r in result] return [types.ChatMember.de_json(r) for r in result]
@@ -1527,10 +1529,9 @@ class AsyncTeleBot:
Telegram documentation: https://core.telegram.org/bots/api#setchatstickerset Telegram documentation: https://core.telegram.org/bots/api#setchatstickerset
:param chat_id: Unique identifier for the target chat or username of the target supergroup :param chat_id: Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
(in the format @supergroupusername)
:param sticker_set_name: Name of the sticker set to be set as the group sticker set :param sticker_set_name: Name of the sticker set to be set as the group sticker set
:return: :return: API reply.
""" """
result = await asyncio_helper.set_chat_sticker_set(self.token, chat_id, sticker_set_name) result = await asyncio_helper.set_chat_sticker_set(self.token, chat_id, sticker_set_name)
return result return result
@@ -1543,8 +1544,7 @@ class AsyncTeleBot:
Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset
:param chat_id: Unique identifier for the target chat or username of the target supergroup :param chat_id: Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
(in the format @supergroupusername)
:return: API reply. :return: API reply.
""" """
result = await asyncio_helper.delete_chat_sticker_set(self.token, chat_id) result = await asyncio_helper.delete_chat_sticker_set(self.token, chat_id)
@@ -1767,10 +1767,10 @@ class AsyncTeleBot:
:param caption: :param caption:
:param duration: Duration of the audio in seconds :param duration: Duration of the audio in seconds
:param performer: Performer :param performer: Performer
:param title:Track name :param title: Track name
:param reply_to_message_id: If the message is a reply, ID of the original message :param reply_to_message_id: If the message is a reply, ID of the original message
:param reply_markup: :param reply_markup:
:param parse_mode :param parse_mode:
:param disable_notification: :param disable_notification:
:param timeout: :param timeout:
:param thumb: :param thumb:
@@ -1810,7 +1810,7 @@ class AsyncTeleBot:
:param duration: Duration of sent audio in seconds :param duration: Duration of sent audio in seconds
:param reply_to_message_id: :param reply_to_message_id:
:param reply_markup: :param reply_markup:
:param parse_mode :param parse_mode:
:param disable_notification: :param disable_notification:
:param timeout: :param timeout:
:param caption_entities: :param caption_entities:
@@ -2338,24 +2338,23 @@ class AsyncTeleBot:
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
:param chat_id: Int or String : Unique identifier for the target group or username of the target supergroup :param chat_id: Int or String : Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
or channel (in the format @channelusername)
:param user_id: Int : Unique identifier of the target user :param user_id: Int : Unique identifier of the target user
:param until_date: Date when restrictions will be lifted for the user, unix time. :param until_date: Date when restrictions will be lifted for the user, unix time.
If user is restricted for more than 366 days or less than 30 seconds from the current time, If user is restricted for more than 366 days or less than 30 seconds from the current time,
they are considered to be restricted forever they are considered to be restricted forever
:param can_send_messages: Pass True, if the user can send text messages, contacts, locations and venues :param can_send_messages: Pass True, if the user can send text messages, contacts, locations and venues
:param can_send_media_messages Pass True, if the user can send audios, documents, photos, videos, video notes :param can_send_media_messages Pass True, if the user can send audios, documents, photos, videos, video notes
and voice notes, implies can_send_messages and voice notes, implies can_send_messages
:param can_send_polls: Pass True, if the user is allowed to send polls, implies can_send_messages :param can_send_polls: Pass True, if the user is allowed to send polls, implies can_send_messages
:param can_send_other_messages: Pass True, if the user can send animations, games, stickers and :param can_send_other_messages: Pass True, if the user can send animations, games, stickers and
use inline bots, implies can_send_media_messages use inline bots, implies can_send_media_messages
:param can_add_web_page_previews: Pass True, if the user may add web page previews to their messages, :param can_add_web_page_previews: Pass True, if the user may add web page previews to their messages,
implies can_send_media_messages implies can_send_media_messages
:param can_change_info: Pass True, if the user is allowed to change the chat title, photo and other settings. :param can_change_info: Pass True, if the user is allowed to change the chat title, photo and other settings.
Ignored in public supergroups Ignored in public supergroups
:param can_invite_users: Pass True, if the user is allowed to invite new users to the chat, :param can_invite_users: Pass True, if the user is allowed to invite new users to the chat,
implies can_invite_users implies can_invite_users
:param can_pin_messages: Pass True, if the user is allowed to pin messages. Ignored in public supergroups :param can_pin_messages: Pass True, if the user is allowed to pin messages. Ignored in public supergroups
:return: True on success :return: True on success
""" """
@@ -2536,14 +2535,13 @@ class AsyncTeleBot:
""" """
Use this method to revoke an invite link created by the bot. Use this method to revoke an invite link created by the bot.
Note: If the primary link is revoked, a new link is automatically generated The bot must be an administrator Note: If the primary link is revoked, a new link is automatically generated The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#revokechatinvitelink Telegram documentation: https://core.telegram.org/bots/api#revokechatinvitelink
:param chat_id: Id: Unique identifier for the target chat or username of the target channel :param chat_id: Id: Unique identifier for the target chat or username of the target channel(in the format @channelusername)
(in the format @channelusername)
:param invite_link: The invite link to revoke :param invite_link: The invite link to revoke
:return: :return: API reply.
""" """
return types.ChatInviteLink.de_json( return types.ChatInviteLink.de_json(
await asyncio_helper.revoke_chat_invite_link(self.token, chat_id, invite_link) await asyncio_helper.revoke_chat_invite_link(self.token, chat_id, invite_link)
@@ -2598,13 +2596,11 @@ class AsyncTeleBot:
Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Returns True on success. Returns True on success.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.
setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#setchatphoto Telegram documentation: https://core.telegram.org/bots/api#setchatphoto
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel :param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
(in the format @channelusername)
:param photo: InputFile: New chat photo, uploaded using multipart/form-data :param photo: InputFile: New chat photo, uploaded using multipart/form-data
:return: :return:
""" """
@@ -2616,7 +2612,7 @@ class AsyncTeleBot:
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Returns True on success. Returns True on success.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins
setting is off in the target group. setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto
@@ -2683,7 +2679,7 @@ class AsyncTeleBot:
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Returns True on success. Returns True on success.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins Note: In regular groups (non-supergroups), this method will only work if the All Members Are Admins
setting is off in the target group. setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#setchattitle Telegram documentation: https://core.telegram.org/bots/api#setchattitle

View File

@@ -1041,9 +1041,9 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable, JsonDeserializable)
def __init__(self, keyboard=None, row_width=3): def __init__(self, keyboard=None, row_width=3):
""" """
This object represents an inline keyboard that appears This object represents an inline keyboard that appears
right next to the message it belongs to. right next to the message it belongs to.
:return: :return: None
""" """
if row_width > self.max_row_keys: if row_width > self.max_row_keys:
# Todo: Will be replaced with Exception in future releases # Todo: Will be replaced with Exception in future releases
@@ -1058,10 +1058,10 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable, JsonDeserializable)
This method adds buttons to the keyboard without exceeding row_width. This method adds buttons to the keyboard without exceeding row_width.
E.g. InlineKeyboardMarkup.add("A", "B", "C") yields the json result: E.g. InlineKeyboardMarkup.add("A", "B", "C") yields the json result:
{keyboard: [["A"], ["B"], ["C"]]} {keyboard: [["A"], ["B"], ["C"]]}
when row_width is set to 1. when row_width is set to 1.
When row_width is set to 2, the result: When row_width is set to 2, the result:
{keyboard: [["A", "B"], ["C"]]} {keyboard: [["A", "B"], ["C"]]}
See https://core.telegram.org/bots/api#inlinekeyboardmarkup See https://core.telegram.org/bots/api#inlinekeyboardmarkup
:param args: Array of InlineKeyboardButton to append to the keyboard :param args: Array of InlineKeyboardButton to append to the keyboard
@@ -1085,10 +1085,10 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable, JsonDeserializable)
def row(self, *args): def row(self, *args):
""" """
Adds a list of InlineKeyboardButton to the keyboard. Adds a list of InlineKeyboardButton to the keyboard.
This method does not consider row_width. This method does not consider row_width.
InlineKeyboardMarkup.row("A").row("B", "C").to_json() outputs: InlineKeyboardMarkup.row("A").row("B", "C").to_json() outputs:
'{keyboard: [["A"], ["B", "C"]]}' '{keyboard: [["A"], ["B", "C"]]}'
See https://core.telegram.org/bots/api#inlinekeyboardmarkup See https://core.telegram.org/bots/api#inlinekeyboardmarkup
:param args: Array of InlineKeyboardButton to append to the keyboard :param args: Array of InlineKeyboardButton to append to the keyboard
@@ -1100,7 +1100,7 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable, JsonDeserializable)
def to_json(self): def to_json(self):
""" """
Converts this object to its json representation Converts this object to its json representation
following the Telegram API guidelines described here: following the Telegram API guidelines described here:
https://core.telegram.org/bots/api#inlinekeyboardmarkup https://core.telegram.org/bots/api#inlinekeyboardmarkup
:return: :return:
""" """

View File

@@ -350,24 +350,27 @@ def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int=2) -> types.I
This is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)' This is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)'
Example: Example:
quick_markup({
'Twitter': {'url': 'https://twitter.com'},
'Facebook': {'url': 'https://facebook.com'},
'Back': {'callback_data': 'whatever'}
}, row_width=2):
returns an InlineKeyboardMarkup with two buttons in a row, one leading to Twitter, the other to facebook
and a back button below
kwargs can be: .. code-block:: python
{
'url': None, quick_markup({
'callback_data': None, 'Twitter': {'url': 'https://twitter.com'},
'switch_inline_query': None, 'Facebook': {'url': 'https://facebook.com'},
'switch_inline_query_current_chat': None, 'Back': {'callback_data': 'whatever'}
'callback_game': None, }, row_width=2):
'pay': None, # returns an InlineKeyboardMarkup with two buttons in a row, one leading to Twitter, the other to facebook
'login_url': None # and a back button below
}
# kwargs can be:
{
'url': None,
'callback_data': None,
'switch_inline_query': None,
'switch_inline_query_current_chat': None,
'callback_game': None,
'pay': None,
'login_url': None
}
:param values: a dict containing all buttons to create in this format: {text: kwargs} {str:} :param values: a dict containing all buttons to create in this format: {text: kwargs} {str:}
:param row_width: int row width :param row_width: int row width
@@ -484,12 +487,17 @@ def antiflood(function, *args, **kwargs):
""" """
Use this function inside loops in order to avoid getting TooManyRequests error. Use this function inside loops in order to avoid getting TooManyRequests error.
Example: Example:
from telebot.util import antiflood .. code-block:: python3
for chat_id in chat_id_list:
from telebot.util import antiflood
for chat_id in chat_id_list:
msg = antiflood(bot.send_message, chat_id, text) msg = antiflood(bot.send_message, chat_id, text)
You want get the :param function:
:param args:
:param kwargs:
:return: None
""" """
from telebot.apihelper import ApiTelegramException from telebot.apihelper import ApiTelegramException
from time import sleep from time import sleep