Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

API 4.4 changes#1464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tsnoam merged 22 commits intopython-telegram-bot:masterfromBibo-Joshi:api-4.4
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
22 commits
Select commitHold shift + click to select a range
93a3b03
API 4.4 changes
Aug 5, 2019
5002fbb
Adjust existing tests
Aug 5, 2019
c97a772
Add test for ChatPermissions
Aug 7, 2019
0b8e95e
Fix ChatPermissions, Add convenience method in Chat & test set_chat_p…
Aug 7, 2019
b48b8ce
Add can_send_polss to ChatMember and update tests
Aug 7, 2019
6572169
Allow for nested MessageEntities in Message._parse_markdown/html, adj…
Aug 8, 2019
5d971ec
remove testing relict
Bibo-JoshiAug 23, 2019
eb6dc1c
Merge remote-tracking branch 'origin/master' into api-4.4
tsnoamAug 28, 2019
0087ad3
Chat no longer lists all_members_are_administrators in the documentation
tsnoamAug 28, 2019
9499f0d
Use MessageEntitys new equality check (#1465)
Bibo-JoshiAug 31, 2019
d34cfb5
Fix unittests
Bibo-JoshiAug 31, 2019
9fc5bd5
Remove unused variable
Bibo-JoshiAug 31, 2019
9d7cf88
Remove deprecation warning for all_members_are_administrators
Bibo-JoshiSep 5, 2019
36879a6
Correct use of Optional in chatpermissions doc string
Bibo-JoshiSep 5, 2019
c4538e5
Remove all_members_are_administrators from test_official
Bibo-JoshiSep 5, 2019
7c2378a
Revert "Remove unused variable"
Bibo-JoshiSep 6, 2019
c62fbe7
Revert "Use MessageEntitys new equality check (#1465)"
Bibo-JoshiSep 6, 2019
b23798d
Revert "remove testing relict"
Bibo-JoshiSep 6, 2019
f7c5d60
Revert "Allow for nested MessageEntities in Message._parse_markdown/h…
Bibo-JoshiSep 6, 2019
2581fb0
chat.py: import what we can at the top of the file
tsnoamSep 6, 2019
a4f6ad9
chatpermissions: no need to implement to_dict() it does nothing but c…
tsnoamSep 6, 2019
adbac74
Revert "Remove all_members_are_administrators from test_official"
tsnoamSep 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionsdocs/source/telegram.chatpermissions.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
telegram.ChatPermissions
========================

.. autoclass:: telegram.ChatPermissions
:members:
:show-inheritance:
1 change: 1 addition & 0 deletionsdocs/source/telegram.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ telegram package
telegram.chat
telegram.chataction
telegram.chatmember
telegram.chatpermissions
telegram.chatphoto
telegram.constants
telegram.contact
Expand Down
5 changes: 3 additions & 2 deletionstelegram/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
from .files.chatphoto import ChatPhoto
from .chat import Chat
from .chatmember import ChatMember
from .chatpermissions import ChatPermissions
from .files.photosize import PhotoSize
from .files.audio import Audio
from .files.voice import Voice
Expand DownExpand Up@@ -125,8 +126,8 @@
__author__ = 'devs@python-telegram-bot.org'

__all__ = [
'Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult', 'CallbackQuery',
'Contact', 'Document', 'File', 'ForceReply', 'InlineKeyboardButton',
'Audio', 'Bot', 'Chat', 'ChatMember', 'ChatPermissions', 'ChatAction', 'ChosenInlineResult',
'CallbackQuery', 'Contact', 'Document', 'File', 'ForceReply', 'InlineKeyboardButton',
'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult', 'InlineQueryResult',
'InlineQueryResultArticle', 'InlineQueryResultAudio', 'InlineQueryResultCachedAudio',
'InlineQueryResultCachedDocument', 'InlineQueryResultCachedGif',
Expand Down
70 changes: 46 additions & 24 deletionstelegram/bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2685,14 +2685,18 @@ def answer_pre_checkout_query(self, pre_checkout_query_id, ok,
return result

@log
def restrict_chat_member(self, chat_id, user_id, until_date=None, can_send_messages=None,
can_send_media_messages=None, can_send_other_messages=None,
can_add_web_page_previews=None, timeout=None, **kwargs):
def restrict_chat_member(self, chat_id, user_id, permissions, until_date=None,
timeout=None, **kwargs):
"""
Use this method to restrict a user in a supergroup. The bot must be an administrator in
the supergroup for this to work and must have the appropriate admin rights. Pass True for
all boolean parameters to lift restrictions from a user.

Note:
Since Bot API 4.4, :attr:`restrict_chat_member` takes the new user permissions in a
single argument of type :class:`telegram.ChatPermissions`. The old way of passing
parameters will not keep working forever.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target supergroup (in the format @supergroupusername).
Expand All@@ -2701,15 +2705,7 @@ def restrict_chat_member(self, chat_id, user_id, until_date=None, can_send_messa
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, they are considered to be
restricted forever.
can_send_messages (:obj:`bool`, optional): Pass True, if the user can send text
messages, contacts, locations and venues.
can_send_media_messages (:obj:`bool`, optional): Pass True, if the user can send
audios, documents, photos, videos, video notes and voice notes, implies
can_send_messages.
can_send_other_messages (:obj:`bool`, optional): Pass True, if the user can send
animations, games, stickers and use inline bots, implies can_send_media_messages.
can_add_web_page_previews (:obj:`bool`, optional): Pass True, if the user may add
web page previews to their messages, implies can_send_media_messages.
permissions (:class:`telegram.ChatPermissions`): New user permissions.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
Expand All@@ -2720,24 +2716,15 @@ def restrict_chat_member(self, chat_id, user_id, until_date=None, can_send_messa

Raises:
:class:`telegram.TelegramError`

"""
url = '{0}/restrictChatMember'.format(self.base_url)

data = {'chat_id': chat_id, 'user_id': user_id}
data = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions.to_dict()}

if until_date is not None:
if isinstance(until_date, datetime):
until_date = to_timestamp(until_date)
data['until_date'] = until_date
if can_send_messages is not None:
data['can_send_messages'] = can_send_messages
if can_send_media_messages is not None:
data['can_send_media_messages'] = can_send_media_messages
if can_send_other_messages is not None:
data['can_send_other_messages'] = can_send_other_messages
if can_add_web_page_previews is not None:
data['can_add_web_page_previews'] = can_add_web_page_previews
data.update(kwargs)

result = self._request.post(url, data, timeout=timeout)
Expand DownExpand Up@@ -2815,6 +2802,38 @@ def promote_chat_member(self, chat_id, user_id, can_change_info=None,

return result

@log
def set_chat_permissions(self, chat_id, permissions, timeout=None, **kwargs):
"""
Use this method to set default chat permissions for all members. The bot must be an
administrator in the group or a supergroup for this to work and must have the
:attr:`can_restrict_members` admin rights. Returns True on success.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username of
the target supergroup (in the format `@supergroupusername`).
permissions (:class:`telegram.ChatPermissions`): New default chat permissions.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments

Returns:
:obj:`bool`: Returns True on success.

Raises:
:class:`telegram.TelegramError`

"""
url = '{0}/setChatPermissions'.format(self.base_url)

data = {'chat_id': chat_id, 'permissions': permissions.to_dict()}
data.update(kwargs)

result = self._request.post(url, data, timeout=timeout)

return result

@log
def export_chat_invite_link(self, chat_id, timeout=None, **kwargs):
"""
Expand DownExpand Up@@ -2958,8 +2977,9 @@ def set_chat_title(self, chat_id, title, timeout=None, **kwargs):
@log
def set_chat_description(self, chat_id, description, timeout=None, **kwargs):
"""
Use this method to change the description of a supergroup or a channel. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights.
Use this method to change the description of a group, a supergroup or a channel. The bot
must be an administrator in the chat for this to work and must have the appropriate admin
rights.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
Expand DownExpand Up@@ -3526,6 +3546,8 @@ def __reduce__(self):
"""Alias for :attr:`restrict_chat_member`"""
promoteChatMember = promote_chat_member
"""Alias for :attr:`promote_chat_member`"""
setChatPermissions = set_chat_permissions
"""Alias for :attr:`set_chat_permissions`"""
exportChatInviteLink = export_chat_invite_link
"""Alias for :attr:`export_chat_invite_link`"""
setChatPhoto = set_chat_photo
Expand Down
25 changes: 20 additions & 5 deletionstelegram/chat.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
"""This module contains an object that represents a Telegram Chat."""

from telegram import TelegramObject, ChatPhoto
from .chatpermissions import ChatPermissions


class Chat(TelegramObject):
Expand All@@ -32,12 +33,13 @@ class Chat(TelegramObject):
username (:obj:`str`): Optional. Username.
first_name (:obj:`str`): Optional. First name of the other party in a private chat.
last_name (:obj:`str`): Optional. Last name of the other party in a private chat.
all_members_are_administrators (:obj:`bool`): Optional.
photo (:class:`telegram.ChatPhoto`): Optional. Chat photo.
description (:obj:`str`): Optional. Description, for supergroups and channel chats.
description (:obj:`str`): Optional. Description, forgroups,supergroups and channel chats.
invite_link (:obj:`str`): Optional. Chat invite link, for supergroups and channel chats.
pinned_message (:class:`telegram.Message`): Optional. Pinned message, for supergroups.
Returned only in get_chat.
permissions (:class:`telegram.ChatPermission`): Optional. Default chat member permissions,
for groups and supergroups. Returned only in getChat.
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
can_set_sticker_set (:obj:`bool`): Optional. ``True``, if the bot can change group the
sticker set.
Expand All@@ -54,15 +56,15 @@ class Chat(TelegramObject):
available.
first_name(:obj:`str`, optional): First name of the other party in a private chat.
last_name(:obj:`str`, optional): Last name of the other party in a private chat.
all_members_are_administrators (:obj:`bool`, optional): True if a group has `All Members
Are Admins` enabled.
photo (:class:`telegram.ChatPhoto`, optional): Chat photo. Returned only in getChat.
description (:obj:`str`, optional): Description, for supergroups and channel chats.
description (:obj:`str`, optional): Description, forgroups,supergroups and channel chats.
Returned only in get_chat.
invite_link (:obj:`str`, optional): Chat invite link, for supergroups and channel chats.
Returned only in get_chat.
pinned_message (:class:`telegram.Message`, optional): Pinned message, for supergroups.
Returned only in get_chat.
permissions (:class:`telegram.ChatPermission`): Optional. Default chat member permissions,
for groups and supergroups. Returned only in getChat.
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
sticker_set_name (:obj:`str`, optional): For supergroups, name of Group sticker set.
Returned only in get_chat.
Expand DownExpand Up@@ -94,6 +96,7 @@ def __init__(self,
description=None,
invite_link=None,
pinned_message=None,
permissions=None,
sticker_set_name=None,
can_set_sticker_set=None,
**kwargs):
Expand All@@ -110,6 +113,7 @@ def __init__(self,
self.description = description
self.invite_link = invite_link
self.pinned_message = pinned_message
self.permissions = permissions
self.sticker_set_name = sticker_set_name
self.can_set_sticker_set = can_set_sticker_set

Expand All@@ -132,6 +136,7 @@ def de_json(cls, data, bot):
data['photo'] = ChatPhoto.de_json(data.get('photo'), bot)
from telegram import Message
data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
data['permissions'] = ChatPermissions.de_json(data.get('permissions'), bot)

return cls(bot=bot, **data)

Expand DownExpand Up@@ -221,6 +226,16 @@ def unban_member(self, *args, **kwargs):
"""
return self.bot.unban_chat_member(self.id, *args, **kwargs)

def set_permissions(self, *args, **kwargs):
"""Shortcut for::
bot.set_chat_permissions(update.message.chat.id, *args, **kwargs)

Returns:
:obj:`bool`: If the action was sent successfully.

"""
return self.bot.set_chat_permissions(self.id, *args, **kwargs)

def send_message(self, *args, **kwargs):
"""Shortcut for::

Expand Down
28 changes: 16 additions & 12 deletionstelegram/chatmember.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,18 +32,17 @@ class ChatMember(TelegramObject):
for this user.
can_be_edited (:obj:`bool`): Optional. If the bot is allowed to edit administrator
privileges of that user.
can_change_info (:obj:`bool`): Optional. If theadministrator can change the chat title,
photo andother settings.
can_change_info (:obj:`bool`): Optional. If theuser can change the chat title, photo and
other settings.
can_post_messages (:obj:`bool`): Optional. If the administrator can post in the channel.
can_edit_messages (:obj:`bool`): Optional. If the administrator can edit messages of other
users.
can_delete_messages (:obj:`bool`): Optional. If the administrator can delete messages of
other users.
can_invite_users (:obj:`bool`): Optional. If the administrator can invite new users to the
chat.
can_invite_users (:obj:`bool`): Optional. If the user can invite new users to the chat.
can_restrict_members (:obj:`bool`): Optional. If the administrator can restrict, ban or
unban chat members.
can_pin_messages (:obj:`bool`): Optional. If theadministrator can pin messages.
can_pin_messages (:obj:`bool`): Optional. If theuser can pin messages.
can_promote_members (:obj:`bool`): Optional. If the administrator can add new
administrators.
is_member (:obj:`bool`): Optional. Restricted only. True, if the user is a member of the
Expand All@@ -52,6 +51,8 @@ class ChatMember(TelegramObject):
locations and venues.
can_send_media_messages (:obj:`bool`): Optional. If the user can send media messages,
implies can_send_messages.
can_send_polls (:obj:`bool`): Optional. True, if the user is allowed to
send polls.
can_send_other_messages (:obj:`bool`): Optional. If the user can send animations, games,
stickers and use inline bots, implies can_send_media_messages.
can_add_web_page_previews (:obj:`bool`): Optional. If user may add web page previews to his
Expand All@@ -65,20 +66,20 @@ class ChatMember(TelegramObject):
restrictions will be lifted for this user.
can_be_edited (:obj:`bool`, optional): Administrators only. True, if the bot is allowed to
edit administrator privileges of that user.
can_change_info (:obj:`bool`, optional): Administrators only. True, if the administrator
can change the chat title, photo and other settings.
can_change_info (:obj:`bool`, optional): Administratorsand restrictedonly. True, if the
usercan change the chat title, photo and other settings.
can_post_messages (:obj:`bool`, optional): Administrators only. True, if the administrator
can post in the channel, channels only.
can_edit_messages (:obj:`bool`, optional): Administrators only. True, if the administrator
can edit messages of other users, channels only.
can_delete_messages (:obj:`bool`, optional): Administrators only. True, if the
administrator can delete messages of other user.
can_invite_users (:obj:`bool`, optional): Administrators only. True, if the administrator
can invite new users to the chat.
can_invite_users (:obj:`bool`, optional): Administratorsand restrictedonly. True, if the
usercan invite new users to the chat.
can_restrict_members (:obj:`bool`, optional): Administrators only. True, if the
administrator can restrict, ban or unban chat members.
can_pin_messages (:obj:`bool`, optional): Administrators only. True, if the administrator
can pin messages, supergroups only.
can_pin_messages (:obj:`bool`, optional): Administratorsand restrictedonly. True, if the
usercan pin messages, supergroups only.
can_promote_members (:obj:`bool`, optional): Administrators only. True, if the
administrator can add new administrators with a subset of his own privileges or demote
administrators that he has promoted, directly or indirectly (promoted by administrators
Expand All@@ -90,6 +91,8 @@ class ChatMember(TelegramObject):
can_send_media_messages (:obj:`bool`, optional): Restricted only. True, if the user can
send audios, documents, photos, videos, video notes and voice notes, implies
can_send_messages.
can_send_polls (:obj:`bool`, optional): Restricted only. True, if the user is allowed to
send polls.
can_send_other_messages (:obj:`bool`, optional): Restricted only. True, if the user can
send animations, games, stickers and use inline bots, implies can_send_media_messages.
can_add_web_page_previews (:obj:`bool`, optional): Restricted only. True, if user may add
Expand All@@ -114,7 +117,7 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,
can_delete_messages=None, can_invite_users=None,
can_restrict_members=None, can_pin_messages=None,
can_promote_members=None, can_send_messages=None,
can_send_media_messages=None, can_send_other_messages=None,
can_send_media_messages=None,can_send_polls=None,can_send_other_messages=None,
can_add_web_page_previews=None, is_member=None, **kwargs):
# Required
self.user = user
Expand All@@ -131,6 +134,7 @@ def __init__(self, user, status, until_date=None, can_be_edited=None,
self.can_promote_members = can_promote_members
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.is_member = is_member
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp