Add typings for invites, templates, and bans

This commit is contained in:
Nadir Chowdhury
2021-04-10 07:55:10 +01:00
committed by GitHub
parent 3e92196a2b
commit 1efdef3ac3
7 changed files with 185 additions and 38 deletions

View File

@ -22,6 +22,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from typing import Any, Optional, TYPE_CHECKING, overload
from .utils import parse_time, _get_as_snowflake, _bytes_to_base64_data
from .enums import VoiceRegion
from .guild import Guild
@ -30,6 +31,9 @@ __all__ = (
'Template',
)
if TYPE_CHECKING:
from .types.template import Template as TemplatePayload
class _FriendlyHttpAttributeErrorHelper:
__slots__ = ()
@ -101,11 +105,11 @@ class Template:
The source guild.
"""
def __init__(self, *, state, data):
def __init__(self, *, state, data: TemplatePayload):
self._state = state
self._store(data)
def _store(self, data):
def _store(self, data: TemplatePayload):
self.code = data['code']
self.uses = data['usage_count']
self.name = data['name']
@ -120,7 +124,7 @@ class Template:
guild = self._state._get_guild(id)
if guild is None:
if guild is None and id:
source_serialised = data['serialized_source_guild']
source_serialised['id'] = id
state = _PartialTemplateState(state=self._state)
@ -128,13 +132,13 @@ class Template:
self.source_guild = guild
def __repr__(self):
def __repr__(self) -> str:
return (
f'<Template code={self.code!r} uses={self.uses} name={self.name!r}'
f' creator={self.creator!r} source_guild={self.source_guild!r}>'
)
async def create_guild(self, name, region=None, icon=None):
async def create_guild(self, name: str, region: Optional[VoiceRegion] = None, icon: Any = None):
"""|coro|
Creates a :class:`.Guild` using the template.
@ -174,7 +178,7 @@ class Template:
data = await self._state.http.create_from_template(self.code, name, region_value, icon)
return Guild(data=data, state=self._state)
async def sync(self):
async def sync(self) -> None:
"""|coro|
Sync the template to the guild's current state.
@ -197,7 +201,20 @@ class Template:
data = await self._state.http.sync_template(self.source_guild.id, self.code)
self._store(data)
async def edit(self, **kwargs):
@overload
async def edit(
self,
*,
name: Optional[str] = ...,
description: Optional[str] = ...,
) -> None:
...
@overload
async def edit(self) -> None:
...
async def edit(self, **kwargs) -> None:
"""|coro|
Edit the template metadata.
@ -226,7 +243,7 @@ class Template:
data = await self._state.http.edit_template(self.source_guild.id, self.code, kwargs)
self._store(data)
async def delete(self):
async def delete(self) -> None:
"""|coro|
Delete the template.