Provide some actions from data types.

This commit is contained in:
Alex Root Junior 2017-07-12 00:16:29 +03:00
parent 49961e5b2b
commit 5b87708049
6 changed files with 45 additions and 3 deletions

View file

@ -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.

View file

@ -61,7 +61,7 @@ class Deserializable:
return result
@property
def bot(self):
def bot(self) -> 'Bot':
"""
Bot instance
"""

View file

@ -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:
"""

View file

@ -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)

View file

@ -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:
"""

View file

@ -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)