Skip to content

Commit f718c36

Browse files
committed
Merge remote-tracking branch 'refs/remotes/eternnoir/master'
2 parents ed88939 + 0632cfb commit f718c36

6 files changed

Lines changed: 360 additions & 16 deletions

File tree

‎README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [The listener mechanism](#the-listener-mechanism)
2626
* [Using web hooks](#using-web-hooks)
2727
* [Logging](#logging)
28+
* [Proxy](#proxy)
2829
* [F.A.Q.](#faq)
2930
* [Bot 2.0](#bot-20)
3031
* [How can I distinguish a User and a GroupChat in message.chat?](#how-can-i-distinguish-a-user-and-a-groupchat-in-messagechat)
@@ -125,6 +126,10 @@ All types are defined in types.py. They are all completely in line with the [Tel
125126
The Message object also has a `content_type`attribute, which defines the type of the Message. `content_type` can be one of the following strings:
126127
`text`, `audio`, `document`, `photo`, `sticker`, `video`, `video_note`, `voice`, `location`, `contact`, `new_chat_member`, `left_chat_member`, `new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`, `supergroup_chat_created`, `channel_chat_created`, `migrate_to_chat_id`, `migrate_from_chat_id`, `pinned_message`.
127128

129+
You can use some types in one function. Example:
130+
131+
```content_types=["text", "sticker", "pinned_message", "photo", "audio"]```
132+
128133
### Methods
129134

130135
All [API methods](https://core.telegram.org/bots/api#available-methods) are located in the TeleBot class. They are renamed to follow common Python naming conventions. E.g. `getMe` is renamed to `get_me` and `sendMessage` to `send_message`.
@@ -488,6 +493,26 @@ logger = telebot.logger
488493
telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console.
489494
```
490495

496+
### Proxy
497+
498+
You can use proxy for request. `apihelper.proxy` object will use by call `requests` proxies argument.
499+
500+
```python
501+
from telebot import apihelper
502+
503+
apihelper.proxy = {'http', 'http://10.10.1.10:3128'}
504+
```
505+
506+
If you want to use socket5 proxy you need install dependency `pip install requests[socks]`.
507+
508+
```python
509+
proxies = {
510+
'http': 'socks5://user:pass@host:port',
511+
'https': 'socks5://user:pass@host:port'
512+
}
513+
```
514+
515+
491516
## F.A.Q.
492517

493518
### Bot 2.0

‎examples/download_file_example.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
bot = telebot.TeleBot(TOKEN)
77

8-
ret_msg = bot.send_voice(CHAT_ID, open('tests/test_data/record.ogg'))
8+
ret_msg = bot.send_voice(CHAT_ID, open('tests/test_data/record.ogg', 'rb'))
99

1010
file_info = bot.get_file(ret_msg.voice.file_id)
1111

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def readme():
77
return f.read()
88

99
setup(name='pyTelegramBotAPI',
10-
version='3.0.1',
10+
version='3.1.1',
1111
description='Python Telegram bot api. ',
1212
long_description=readme(),
1313
author='eternnoir',

‎telebot/__init__.py‎

Lines changed: 166 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,26 @@ class TeleBot:
4444
sendChatAction
4545
getUserProfilePhotos
4646
getUpdates
47-
"""
47+
getFile
48+
kickChatMember
49+
unbanChatMember
50+
restrictChatMember
51+
promoteChatMember
52+
exportChatInviteLink
53+
setChatPhoto
54+
deleteChatPhoto
55+
setChatTitle
56+
setChatDescription
57+
pinChatMessage
58+
unpinChatMessage
59+
leaveChat
60+
getChat
61+
getChatAdministrators
62+
getChatMembersCount
63+
getChatMember
64+
answerCallbackQuery
65+
answerInlineQuery
66+
"""
4867

4968
def __init__(self, token, threaded=True, skip_pending=False, num_threads=2):
5069
"""
@@ -601,18 +620,162 @@ def send_chat_action(self, chat_id, action):
601620
"""
602621
return apihelper.send_chat_action(self.token, chat_id, action)
603622

604-
def kick_chat_member(self, chat_id, user_id):
623+
def kick_chat_member(self, chat_id, user_id, until_date=None):
605624
"""
606625
Use this method to kick a user from a group or a supergroup.
607626
:param chat_id: Int or string : Unique identifier for the target group or username of the target supergroup
608627
:param user_id: Int : Unique identifier of the target user
628+
:param until_date: Date when the user will be unbanned, unix time. If user is banned for more than 366 days or
629+
less than 30 seconds from the current time they are considered to be banned forever
609630
:return: types.Message
610631
"""
611-
return apihelper.kick_chat_member(self.token, chat_id, user_id)
632+
return apihelper.kick_chat_member(self.token, chat_id, user_id, until_date)
612633

613634
def unban_chat_member(self, chat_id, user_id):
614635
return apihelper.unban_chat_member(self.token, chat_id, user_id)
615636

637+
def restrict_chat_member(self, chat_id, user_id, until_date=None, can_send_messages=None,
638+
can_send_media_messages=None, can_send_other_messages=None,
639+
can_add_web_page_previews=None):
640+
"""
641+
Use this method to restrict a user in a supergroup.
642+
The bot must be an administrator in the supergroup for this to work and must have
643+
the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user.
644+
Returns True on success.
645+
:param chat_id: Int or String : Unique identifier for the target group or username of the target supergroup
646+
or channel (in the format @channelusername)
647+
:param user_id: Int : Unique identifier of the target user
648+
:param until_date: Date when restrictions will be lifted for the user, unix time.
649+
If user is restricted for more than 366 days or less than 30 seconds from the current time,
650+
they are considered to be restricted forever
651+
:param can_send_messages: Pass True, if the user can send text messages, contacts, locations and venues
652+
:param can_send_media_messages Pass True, if the user can send audios, documents, photos, videos, video notes
653+
and voice notes, implies can_send_messages
654+
:param can_send_other_messages: Pass True, if the user can send animations, games, stickers and
655+
use inline bots, implies can_send_media_messages
656+
:param can_add_web_page_previews: Pass True, if the user may add web page previews to their messages,
657+
implies can_send_media_messages
658+
:return: types.Message
659+
"""
660+
return apihelper.restrict_chat_member(self.token, chat_id, user_id, until_date, can_send_messages,
661+
can_send_media_messages, can_send_other_messages,
662+
can_add_web_page_previews)
663+
664+
def promote_chat_member(self, chat_id, user_id, can_change_info=None, can_post_messages=None,
665+
can_edit_messages=None, can_delete_messages=None, can_invite_users=None,
666+
can_restrict_members=None, can_pin_messages=None, can_promote_members=None):
667+
"""
668+
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator
669+
in the chat for this to work and must have the appropriate admin rights.
670+
Pass False for all boolean parameters to demote a user. Returns True on success.
671+
:param chat_id: Unique identifier for the target chat or username of the target channel (
672+
in the format @channelusername)
673+
:param user_id: Int : Unique identifier of the target user
674+
:param can_change_info: Bool: Pass True, if the administrator can change chat title, photo and other settings
675+
:param can_post_messages: Bool : Pass True, if the administrator can create channel posts, channels only
676+
:param can_edit_messages: Bool : Pass True, if the administrator can edit messages of other users, channels only
677+
:param can_delete_messages: Bool : Pass True, if the administrator can delete messages of other users
678+
:param can_invite_users: Bool : Pass True, if the administrator can invite new users to the chat
679+
:param can_restrict_members: Bool: Pass True, if the administrator can restrict, ban or unban chat members
680+
:param can_pin_messages: Bool: Pass True, if the administrator can pin messages, supergroups only
681+
:param can_promote_members: Bool: Pass True, if the administrator can add new administrators with a subset
682+
of his own privileges or demote administrators that he has promoted, directly or indirectly
683+
(promoted by administrators that were appointed by him)
684+
:return:
685+
"""
686+
return apihelper.promote_chat_member(self.token, chat_id, user_id, can_change_info, can_post_messages,
687+
can_edit_messages, can_delete_messages, can_invite_users,
688+
can_restrict_members, can_pin_messages, can_promote_members)
689+
690+
def export_chat_invite_link(self, chat_id):
691+
"""
692+
Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator
693+
in the chat for this to work and must have the appropriate admin rights.
694+
Returns exported invite link as String on success.
695+
:param chat_id: Id: Unique identifier for the target chat or username of the target channel
696+
(in the format @channelusername)
697+
:return:
698+
"""
699+
return apihelper.export_chat_invite_link(self.token, chat_id)
700+
701+
def set_chat_photo(self, chat_id, photo):
702+
"""
703+
Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
704+
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
705+
Returns True on success.
706+
Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’
707+
setting is off in the target group.
708+
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel
709+
(in the format @channelusername)
710+
:param photo: InputFile: New chat photo, uploaded using multipart/form-data
711+
:return:
712+
"""
713+
return apihelper.set_chat_photo(self.token, chat_id, photo)
714+
715+
def delete_chat_photo(self, chat_id):
716+
"""
717+
Use this method to delete a chat photo. Photos can't be changed for private chats.
718+
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
719+
Returns True on success.
720+
Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’
721+
setting is off in the target group.
722+
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel
723+
(in the format @channelusername)
724+
:return:
725+
"""
726+
return apihelper.delete_chat_photo(self.token, chat_id)
727+
728+
def set_chat_title(self, chat_id, title):
729+
"""
730+
Use this method to change the title of a chat. Titles can't be changed for private chats.
731+
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
732+
Returns True on success.
733+
Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’
734+
setting is off in the target group.
735+
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel
736+
(in the format @channelusername)
737+
:param title: New chat title, 1-255 characters
738+
:return:
739+
"""
740+
return apihelper.set_chat_title(self.token, chat_id, title)
741+
742+
def set_chat_description(self, chat_id, description):
743+
"""
744+
Use this method to change the description of a supergroup or a channel.
745+
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
746+
Returns True on success.
747+
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel
748+
(in the format @channelusername)
749+
:param description: Str: New chat description, 0-255 characters
750+
:return:
751+
"""
752+
return apihelper.set_chat_description(self.token, chat_id, description)
753+
754+
def pin_chat_message(self, chat_id, message_id, disable_notification=False):
755+
"""
756+
Use this method to pin a message in a supergroup.
757+
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
758+
Returns True on success.
759+
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel
760+
(in the format @channelusername)
761+
:param message_id: Int: Identifier of a message to pin
762+
:param disable_notification: Bool: Pass True, if it is not necessary to send a notification
763+
to all group members about the new pinned message
764+
:return:
765+
"""
766+
return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification)
767+
768+
def unpin_chat_message(self, chat_id):
769+
"""
770+
Use this method to unpin a message in a supergroup chat.
771+
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
772+
Returns True on success.
773+
:param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel
774+
(in the format @channelusername)
775+
:return:
776+
"""
777+
return apihelper.unpin_chat_message(self.token, chat_id)
778+
616779
def edit_message_text(self, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None,
617780
disable_web_page_preview=None, reply_markup=None):
618781
result = apihelper.edit_message_text(self.token, text, chat_id, message_id, inline_message_id, parse_mode,

0 commit comments

Comments
 (0)