From 5b87708049034064285396e4a626da062a8c9e1e Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 12 Jul 2017 00:16:29 +0300 Subject: [PATCH] Provide some actions from data types. --- aiogram/bot/bot.py | 2 +- aiogram/types/base.py | 2 +- aiogram/types/chat.py | 35 ++++++++++++++++++++++++++++++++++- aiogram/types/file.py | 3 +++ aiogram/types/message.py | 3 +++ aiogram/types/user.py | 3 +++ 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index 47ebf95b..b64d74ad 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -549,7 +549,7 @@ class Bot(BaseBot): """ 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: + async def pin_chat_message(self, chat_id: int, message_id: int, disable_notification: bool = False) -> 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. diff --git a/aiogram/types/base.py b/aiogram/types/base.py index a0e0ca69..829004b3 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -61,7 +61,7 @@ class Deserializable: return result @property - def bot(self): + def bot(self) -> 'Bot': """ Bot instance """ diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 8c65bdfc..d2816f29 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -1,5 +1,5 @@ -from .chat_photo import ChatPhoto from .base import Deserializable +from .chat_photo import ChatPhoto class Chat(Deserializable): @@ -60,6 +60,39 @@ class Chat(Deserializable): return self.full_name return None + async def set_photo(self, photo): + return await self.bot.set_chat_photo(self.id, photo) + + async def delete_photo(self): + return await self.bot.delete_chat_photo(self.id) + + async def set_title(self, title): + return await self.bot.set_chat_title(self.id, title) + + async def set_description(self, description): + return await self.bot.delete_chat_description(self.id, description) + + async def pin_message(self, message_id: int, disable_notification: bool = False): + return await self.bot.pin_chat_message(self.id, message_id, disable_notification) + + async def unpin_message(self): + return await self.bot.unpin_chat_message(self.id) + + async def leave(self): + return await self.bot.leave_chat(self.id) + + async def get_administrators(self): + return await self.bot.get_chat_administrators(self.id) + + async def get_members_count(self): + return await self.bot.get_chat_members_count(self.id) + + async def get_member(self, user_id): + return await self.bot.get_chat_member(self.id, user_id) + + async def do(self, action): + return await self.bot.send_chat_action(self.id, action) + class ChatType: """ diff --git a/aiogram/types/file.py b/aiogram/types/file.py index da10af51..0f07f7ad 100644 --- a/aiogram/types/file.py +++ b/aiogram/types/file.py @@ -26,3 +26,6 @@ class File(Deserializable): file_path = raw_data.get('file_path') return File(file_id, file_size, file_path) + + async def download(self, destination=None, timeout=30, chunk_size=65536, seek=True): + return await self.bot.download_file(self.file_path, destination, timeout, chunk_size, seek) diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 3cd85eee..dd8828c4 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -216,6 +216,9 @@ class Message(Deserializable): return False return True + async def pin(self, disable_notification: bool = False): + return await self.chat.pin_message(self.message_id, disable_notification) + class ContentType: """ diff --git a/aiogram/types/user.py b/aiogram/types/user.py index 247bae09..ed42fa8d 100644 --- a/aiogram/types/user.py +++ b/aiogram/types/user.py @@ -69,3 +69,6 @@ class User(Deserializable): if not hasattr(self, '_locale'): setattr(self, '_locale', babel.core.Locale.parse(self.language_code, sep='-')) return getattr(self, '_locale') + + async def get_user_profile_photos(self, offset=None, limit=None): + return await self.bot.get_user_profile_photos(self.id, offset, limit)