Type hints

This commit is contained in:
Gabben 2020-01-01 00:46:27 +05:00
parent b01095e61c
commit 4cd59971db

View file

@ -4,12 +4,12 @@ import asyncio
import datetime
import typing
from . import base
from . import fields
from ..utils import helper, markdown
from . import base, fields
from .chat_member import ChatMember
from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto
from ..utils import helper
from ..utils import markdown
from .input_file import InputFile
class Chat(base.TelegramObject):
@ -37,7 +37,7 @@ class Chat(base.TelegramObject):
return self.id
@property
def full_name(self):
def full_name(self) -> base.String:
if self.type == ChatType.PRIVATE:
full_name = self.first_name
if self.last_name:
@ -46,7 +46,7 @@ class Chat(base.TelegramObject):
return self.title
@property
def mention(self):
def mention(self) -> typing.Union[base.String, None]:
"""
Get mention if a Chat has a username, or get full name if this is a Private Chat, otherwise None is returned
"""
@ -57,20 +57,20 @@ class Chat(base.TelegramObject):
return None
@property
def user_url(self):
def user_url(self) -> base.String:
if self.type != ChatType.PRIVATE:
raise TypeError('`user_url` property is only available in private chats!')
return f"tg://user?id={self.id}"
def get_mention(self, name=None, as_html=True):
def get_mention(self, name=None, as_html=True) -> base.String:
if name is None:
name = self.mention
if as_html:
return markdown.hlink(name, self.user_url)
return markdown.link(name, self.user_url)
async def get_url(self):
async def get_url(self) -> base.String:
"""
Use this method to get chat link.
Private chat returns user link.
@ -101,7 +101,7 @@ class Chat(base.TelegramObject):
for key, value in other:
self[key] = value
async def set_photo(self, photo):
async def set_photo(self, photo: InputFile) -> base.Boolean:
"""
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.
@ -118,7 +118,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.set_chat_photo(self.id, photo)
async def delete_photo(self):
async def delete_photo(self) -> base.Boolean:
"""
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.
@ -133,7 +133,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.delete_chat_photo(self.id)
async def set_title(self, title):
async def set_title(self, title: base.String) -> base.Boolean:
"""
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.
@ -150,7 +150,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.set_chat_title(self.id, title)
async def set_description(self, description):
async def set_description(self, description: base.String) -> base.Boolean:
"""
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.
@ -165,7 +165,7 @@ class Chat(base.TelegramObject):
return await self.bot.delete_chat_description(self.id, description)
async def kick(self, user_id: base.Integer,
until_date: typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None] = None):
until_date: typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None] = None) -> base.Boolean:
"""
Use this method to kick a user from a group, a supergroup or a channel.
In the case of supergroups and channels, the user will not be able to return to the group
@ -188,7 +188,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.kick_chat_member(self.id, user_id=user_id, until_date=until_date)
async def unban(self, user_id: base.Integer):
async def unban(self, user_id: base.Integer) -> base.Boolean:
"""
Use this method to unban a previously kicked user in a supergroup or channel. `
The user will not return to the group or channel automatically, but will be able to join via link, etc.
@ -309,7 +309,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.set_chat_permissions(self.id, permissions=permissions)
async def pin_message(self, message_id: int, disable_notification: bool = False):
async def pin_message(self, message_id: base.Integer, disable_notification: base.Boolean = False) -> base.Boolean:
"""
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.
@ -326,7 +326,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.pin_chat_message(self.id, message_id, disable_notification)
async def unpin_message(self):
async def unpin_message(self) -> base.Boolean:
"""
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.
@ -338,7 +338,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.unpin_chat_message(self.id)
async def leave(self):
async def leave(self) -> base.Boolean:
"""
Use this method for your bot to leave a group, supergroup or channel.
@ -349,7 +349,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.leave_chat(self.id)
async def get_administrators(self):
async def get_administrators(self) -> typing.List[ChatMember]:
"""
Use this method to get a list of administrators in a chat.
@ -363,7 +363,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.get_chat_administrators(self.id)
async def get_members_count(self):
async def get_members_count(self) -> base.Integer:
"""
Use this method to get the number of members in a chat.
@ -374,7 +374,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.get_chat_members_count(self.id)
async def get_member(self, user_id):
async def get_member(self, user_id: base.Integer) -> ChatMember:
"""
Use this method to get information about a member of a chat.
@ -417,9 +417,9 @@ class Chat(base.TelegramObject):
:return: Returns True on success
:rtype: :obj:`base.Boolean`
"""
return self.bot.delete_chat_sticker_set(self.id)
return await self.bot.delete_chat_sticker_set(self.id)
async def do(self, action):
async def do(self, action: base.String) -> base.Boolean:
"""
Use this method when you need to tell the user that something is happening on the bot's side.
The status is set for 5 seconds or less
@ -437,7 +437,7 @@ class Chat(base.TelegramObject):
"""
return await self.bot.send_chat_action(self.id, action)
async def export_invite_link(self):
async def export_invite_link(self) -> base.String:
"""
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.