mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-15 03:08:51 +00:00
Update to Bot API 3.1
This commit is contained in:
parent
1413baf4b8
commit
4e093680c4
7 changed files with 285 additions and 10 deletions
|
|
@ -116,6 +116,15 @@ class Methods:
|
|||
GET_CHAT_ADMINISTRATORS = 'getChatAdministrators'
|
||||
GET_CHAT_MEMBERS_COUNT = 'getChatMembersCount'
|
||||
GET_CHAT_MEMBER = 'getChatMember'
|
||||
RESTRICT_CHAT_MEMBER = 'restrictChatMember'
|
||||
PROMOTE_CHAT_MEMBER = 'promoteChatMember'
|
||||
EXPORT_CHAT_INVITE_LINK = 'exportChatInviteLink'
|
||||
SET_CHAT_PHOTO = 'setChatPhoto'
|
||||
DELETE_CHAT_PHOTO = 'deleteChatPhoto'
|
||||
SET_CHAT_TITLE = 'setChatTitle'
|
||||
SET_CHAT_DESCRIPTION = 'setChatDescription'
|
||||
PIN_CHAT_MESSAGE = 'pinChatMessage'
|
||||
UNPIN_CHAT_MESSAGE = 'unpinChatMessage'
|
||||
ANSWER_CALLBACK_QUERY = 'answerCallbackQuery'
|
||||
ANSWER_INLINE_QUERY = 'answerInlineQuery'
|
||||
EDIT_MESSAGE_TEXT = 'editMessageText'
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class BaseBot:
|
|||
'sticker': api.Methods.SEND_STICKER,
|
||||
'video': api.Methods.SEND_VIDEO,
|
||||
'voice': api.Methods.SEND_VOICE,
|
||||
'video_note': api.Methods.SEND_VIDEO_NOTE
|
||||
'video_note': api.Methods.SEND_VIDEO_NOTE,
|
||||
}
|
||||
|
||||
method = methods[file_type]
|
||||
|
|
@ -274,10 +274,70 @@ class BaseBot:
|
|||
payload = generate_payload(**locals())
|
||||
return await self.request(api.Methods.GET_FILE, payload)
|
||||
|
||||
async def kick_chat_user(self, chat_id, user_id) -> bool:
|
||||
async def kick_chat_member(self, chat_id, user_id) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
return await self.request(api.Methods.KICK_CHAT_MEMBER, payload)
|
||||
|
||||
async def promote_chat_member(self, chat_id: int, user_id: int, can_change_info: bool, can_post_messages: bool,
|
||||
can_edit_messages: bool, can_delete_messages: bool, can_invite_users: bool,
|
||||
can_restrict_members: bool, can_pin_messages: bool,
|
||||
can_promote_members: bool) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.PROMOTE_CHAT_MEMBER, payload)
|
||||
|
||||
async def restrict_chat_member(self, chat_id: int, user_id: int, until_date: int, can_send_messages: bool,
|
||||
can_send_media_messages: bool, can_send_other_messages: bool,
|
||||
can_add_web_page_previews: bool) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.RESTRICT_CHAT_MEMBER, payload)
|
||||
|
||||
async def export_chat_invite_link(self, chat_id: int) -> str:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.EXPORT_CHAT_INVITE_LINK, payload)
|
||||
|
||||
async def set_chat_photo(self, chat_id: int, photo) -> bool:
|
||||
payload = generate_payload(**locals(), exclude=['photo'])
|
||||
|
||||
if isinstance(photo, str):
|
||||
payload['photo'] = photo
|
||||
req = self.request(api.Methods.SET_CHAT_PHOTO, payload)
|
||||
elif isinstance(photo, io.IOBase):
|
||||
data = {'photo': photo.read()}
|
||||
req = self.request(api.Methods.SET_CHAT_PHOTO, payload, data)
|
||||
else:
|
||||
data = {'photo': photo}
|
||||
req = self.request(api.Methods.SET_CHAT_PHOTO, payload, data)
|
||||
|
||||
return await req
|
||||
|
||||
async def delete_chat_photo(self, chat_id: int) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.DELETE_CHAT_PHOTO, payload)
|
||||
|
||||
async def set_chat_title(self, chat_id: int, title: str) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.SET_CHAT_TITLE, payload)
|
||||
|
||||
async def set_chat_description(self, chat_id: int, description: str) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.SET_CHAT_DESCRIPTION, payload)
|
||||
|
||||
async def pin_chat_message(self, chat_id: int, message_id: int, disable_notification: bool) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.PIN_CHAT_MESSAGE, payload)
|
||||
|
||||
async def unpin_chat_message(self, chat_id: int) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.UNPIN_CHAT_MESSAGE, payload)
|
||||
|
||||
async def unban_chat_member(self, chat_id, user_id) -> bool:
|
||||
payload = generate_payload(**locals())
|
||||
return await self.request(api.Methods.UNBAN_CHAT_MEMBER, payload)
|
||||
|
|
@ -407,4 +467,4 @@ class BaseBot:
|
|||
inline_message_id: str = None) -> dict:
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.GET_GAME_HIGH_SCORES, payload)
|
||||
return await self.request(api.Methods.GET_GAME_HIGH_SCORES, payload)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import datetime
|
||||
import json
|
||||
import time
|
||||
|
||||
from .. import types
|
||||
from .base import BaseBot
|
||||
from .. import types
|
||||
|
||||
|
||||
class Bot(BaseBot):
|
||||
|
|
@ -431,7 +433,7 @@ class Bot(BaseBot):
|
|||
file = await super(Bot, self).get_file(file_id)
|
||||
return self.prepare_object(types.File.de_json(file))
|
||||
|
||||
async def kick_chat_user(self, chat_id, user_id) -> bool:
|
||||
async def kick_chat_member(self, chat_id, user_id) -> bool:
|
||||
"""
|
||||
Use this method to kick a user from a group or a supergroup. In the case of supergroups,
|
||||
the user will not be able to return to the group on their own using invite links, etc.,
|
||||
|
|
@ -441,7 +443,133 @@ class Bot(BaseBot):
|
|||
:param user_id: int
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).kick_chat_user(chat_id, user_id)
|
||||
return await super(Bot, self).kick_chat_member(chat_id, user_id)
|
||||
|
||||
async def promote_chat_member(self, chat_id: int, user_id: int, can_change_info: bool, can_post_messages: bool,
|
||||
can_edit_messages: bool, can_delete_messages: bool, can_invite_users: bool,
|
||||
can_restrict_members: bool, can_pin_messages: bool,
|
||||
can_promote_members: bool) -> bool:
|
||||
"""
|
||||
Use this method to promote or demote a user in 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.
|
||||
Pass False for all boolean parameters to demote a user.
|
||||
|
||||
:param chat_id: int
|
||||
:param user_id: int
|
||||
:param can_change_info: bool
|
||||
:param can_post_messages: bool
|
||||
:param can_edit_messages: bool
|
||||
:param can_delete_messages: bool
|
||||
:param can_invite_users: bool
|
||||
:param can_restrict_members: bool
|
||||
:param can_pin_messages: bool
|
||||
:param can_promote_members: bool
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).promote_chat_member(chat_id, user_id, can_change_info, can_post_messages,
|
||||
can_edit_messages, can_delete_messages, can_invite_users,
|
||||
can_restrict_members, can_pin_messages, can_promote_members)
|
||||
|
||||
async def restrict_chat_member(self, chat_id: int, user_id: int, until_date: int, can_send_messages: bool,
|
||||
can_send_media_messages: bool, can_send_other_messages: bool,
|
||||
can_add_web_page_previews: bool) -> bool:
|
||||
"""
|
||||
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.
|
||||
|
||||
:param chat_id: int
|
||||
:param user_id: int
|
||||
:param until_date: int
|
||||
:param can_send_messages: bool
|
||||
:param can_send_media_messages: bool
|
||||
:param can_send_other_messages: bool
|
||||
:param can_add_web_page_previews: bool
|
||||
:return: bool
|
||||
"""
|
||||
if isinstance(until_date, datetime.datetime):
|
||||
until_date = int(time.mktime(until_date.timetuple()))
|
||||
return await super(Bot, self).restrict_chat_member(chat_id, user_id, until_date, can_send_messages,
|
||||
can_send_media_messages, can_send_other_messages,
|
||||
can_add_web_page_previews)
|
||||
|
||||
async def export_chat_invite_link(self, chat_id: int) -> str:
|
||||
"""
|
||||
Use this method to export an invite link to 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.
|
||||
|
||||
:param chat_id: int
|
||||
:return:
|
||||
"""
|
||||
return await super(Bot, self).export_chat_invite_link(chat_id)
|
||||
|
||||
async def set_chat_photo(self, chat_id: int, photo) -> bool:
|
||||
"""
|
||||
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.
|
||||
|
||||
:param chat_id: int
|
||||
:param photo: file or str
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).set_chat_photo(chat_id, photo)
|
||||
|
||||
async def delete_chat_photo(self, chat_id: int) -> bool:
|
||||
"""
|
||||
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.
|
||||
|
||||
:param chat_id: int
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).delete_chat_photo(chat_id)
|
||||
|
||||
async def set_chat_title(self, chat_id: int, title: str) -> bool:
|
||||
"""
|
||||
Use this method to change the title of a chat.
|
||||
Titles 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.
|
||||
|
||||
:param chat_id: int
|
||||
:param title: str
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).set_chat_title(chat_id, title)
|
||||
|
||||
async def set_chat_description(self, chat_id: int, description: str) -> bool:
|
||||
"""
|
||||
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.
|
||||
|
||||
:param chat_id: int
|
||||
:param description: str
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).set_chat_description(chat_id, description)
|
||||
|
||||
async def pin_chat_message(self, chat_id: int, message_id: int, disable_notification: bool) -> bool:
|
||||
"""
|
||||
Use this method to pin a message in a supergroup.
|
||||
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
|
||||
:param chat_id: int
|
||||
:param message_id: int
|
||||
:param disable_notification: bool
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).pin_chat_message(chat_id, message_id, disable_notification)
|
||||
|
||||
async def unpin_chat_message(self, chat_id: int) -> bool:
|
||||
"""
|
||||
Use this method to unpin a message in a supergroup chat.
|
||||
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
|
||||
:param chat_id: int
|
||||
:return: bool
|
||||
"""
|
||||
return await super(Bot, self).unpin_chat_message(chat_id)
|
||||
|
||||
async def unban_chat_member(self, chat_id, user_id) -> bool:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue