mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-05 11:27:13 +00:00
Add remaining template endpoints
This commit is contained in:
parent
6f748e5da5
commit
fb773dc1dd
@ -1460,6 +1460,29 @@ class Guild(Hashable):
|
|||||||
|
|
||||||
data = await self._state.http.prune_members(self.id, days, compute_prune_count=compute_prune_count, roles=roles, reason=reason)
|
data = await self._state.http.prune_members(self.id, days, compute_prune_count=compute_prune_count, roles=roles, reason=reason)
|
||||||
return data['pruned']
|
return data['pruned']
|
||||||
|
|
||||||
|
async def templates(self):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Gets the list of templates from this guild.
|
||||||
|
|
||||||
|
Requires :attr:`~.Permissions.manage_guild` permissions.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
Forbidden
|
||||||
|
You don't have permissions to get the templates.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
List[:class:`Template`]
|
||||||
|
The templates for this guild.
|
||||||
|
"""
|
||||||
|
from .template import Template
|
||||||
|
data = await self._state.http.guild_templates(self.id)
|
||||||
|
return [Template(data=d, state=self._state) for d in data]
|
||||||
|
|
||||||
async def webhooks(self):
|
async def webhooks(self):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
@ -1546,6 +1569,36 @@ class Guild(Hashable):
|
|||||||
result.append(Invite(state=self._state, data=invite))
|
result.append(Invite(state=self._state, data=invite))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
async def create_template(self, *, name, description=None):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Creates a template for the guild.
|
||||||
|
|
||||||
|
You must have the :attr:`~Permissions.manage_guild` permission to
|
||||||
|
do this.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
-----------
|
||||||
|
name: :class:`str`
|
||||||
|
The name of the template.
|
||||||
|
description: Optional[:class:`str`]
|
||||||
|
The description of the template.
|
||||||
|
"""
|
||||||
|
from .template import Template
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
'name': name
|
||||||
|
}
|
||||||
|
|
||||||
|
if description:
|
||||||
|
payload['description'] = description
|
||||||
|
|
||||||
|
data = await self._state.http.create_template(self.id, payload)
|
||||||
|
|
||||||
|
return Template(state=self._state, data=data)
|
||||||
|
|
||||||
async def create_integration(self, *, type, id):
|
async def create_integration(self, *, type, id):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
@ -670,6 +670,28 @@ class HTTPClient:
|
|||||||
def get_template(self, code):
|
def get_template(self, code):
|
||||||
return self.request(Route('GET', '/guilds/templates/{code}', code=code))
|
return self.request(Route('GET', '/guilds/templates/{code}', code=code))
|
||||||
|
|
||||||
|
def guild_templates(self, guild_id):
|
||||||
|
return self.request(Route('GET', '/guilds/{guild_id}/templates', guild_id=guild_id))
|
||||||
|
|
||||||
|
def create_template(self, guild_id, payload):
|
||||||
|
return self.request(Route('POST', '/guilds/{guild_id}/templates', guild_id=guild_id), json=payload)
|
||||||
|
|
||||||
|
def sync_template(self, guild_id, code):
|
||||||
|
return self.request(Route('PUT', '/guilds/{guild_id}/templates/{code}', guild_id=guild_id, code=code))
|
||||||
|
|
||||||
|
def edit_template(self, guild_id, code, payload):
|
||||||
|
valid_keys = (
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
)
|
||||||
|
payload = {
|
||||||
|
k: v for k, v in payload.items() if k in valid_keys
|
||||||
|
}
|
||||||
|
return self.request(Route('PATCH', '/guilds/{guild_id}/templates/{code}', guild_id=guild_id, code=code), json=payload)
|
||||||
|
|
||||||
|
def delete_template(self, guild_id, code):
|
||||||
|
return self.request(Route('DELETE', '/guilds/{guild_id}/templates/{code}', guild_id=guild_id, code=code))
|
||||||
|
|
||||||
def create_from_template(self, code, name, region, icon):
|
def create_from_template(self, code, name, region, icon):
|
||||||
payload = {
|
payload = {
|
||||||
'name': name,
|
'name': name,
|
||||||
|
@ -105,7 +105,9 @@ class Template:
|
|||||||
|
|
||||||
def __init__(self, *, state, data):
|
def __init__(self, *, state, data):
|
||||||
self._state = state
|
self._state = state
|
||||||
|
self._store(data)
|
||||||
|
|
||||||
|
def _store(self, data):
|
||||||
self.code = data['code']
|
self.code = data['code']
|
||||||
self.uses = data['usage_count']
|
self.uses = data['usage_count']
|
||||||
self.name = data['name']
|
self.name = data['name']
|
||||||
@ -117,11 +119,16 @@ class Template:
|
|||||||
self.updated_at = parse_time(data.get('updated_at'))
|
self.updated_at = parse_time(data.get('updated_at'))
|
||||||
|
|
||||||
id = _get_as_snowflake(data, 'source_guild_id')
|
id = _get_as_snowflake(data, 'source_guild_id')
|
||||||
source_serialised = data['serialized_source_guild']
|
|
||||||
source_serialised['id'] = id
|
|
||||||
state = _PartialTemplateState(state=self._state)
|
|
||||||
|
|
||||||
self.source_guild = Guild(data=source_serialised, state=state)
|
guild = self._state._get_guild(id)
|
||||||
|
|
||||||
|
if guild is None:
|
||||||
|
source_serialised = data['serialized_source_guild']
|
||||||
|
source_serialised['id'] = id
|
||||||
|
state = _PartialTemplateState(state=self._state)
|
||||||
|
guild = Guild(data=source_serialised, state=state)
|
||||||
|
|
||||||
|
self.source_guild = guild
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Template code={0.code!r} uses={0.uses} name={0.name!r}' \
|
return '<Template code={0.code!r} uses={0.uses} name={0.name!r}' \
|
||||||
@ -147,9 +154,9 @@ class Template:
|
|||||||
|
|
||||||
Raises
|
Raises
|
||||||
------
|
------
|
||||||
:exc:`.HTTPException`
|
HTTPException
|
||||||
Guild creation failed.
|
Guild creation failed.
|
||||||
:exc:`.InvalidArgument`
|
InvalidArgument
|
||||||
Invalid icon image format given. Must be PNG or JPG.
|
Invalid icon image format given. Must be PNG or JPG.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
@ -168,3 +175,76 @@ class Template:
|
|||||||
|
|
||||||
data = await self._state.http.create_from_template(self.code, name, region, icon)
|
data = await self._state.http.create_from_template(self.code, name, region, icon)
|
||||||
return Guild(data=data, state=self._state)
|
return Guild(data=data, state=self._state)
|
||||||
|
|
||||||
|
async def sync(self):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Sync the template to the guild's current state.
|
||||||
|
|
||||||
|
You must have the :attr:`~Permissions.manage_guild` permission in the
|
||||||
|
source guild to do this.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
HTTPException
|
||||||
|
Editing the template failed.
|
||||||
|
Forbidden
|
||||||
|
You don't have permissions to edit the template.
|
||||||
|
NotFound
|
||||||
|
This template does not exist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
data = await self._state.http.sync_template(self.source_guild.id, self.code)
|
||||||
|
self._store(data)
|
||||||
|
|
||||||
|
async def edit(self, **kwargs):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Edit the template metadata.
|
||||||
|
|
||||||
|
You must have the :attr:`~Permissions.manage_guild` permission in the
|
||||||
|
source guild to do this.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
------------
|
||||||
|
name: Optional[:class:`str`]
|
||||||
|
The template's new name.
|
||||||
|
description: Optional[:class:`str`]
|
||||||
|
The template's description.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
HTTPException
|
||||||
|
Editing the template failed.
|
||||||
|
Forbidden
|
||||||
|
You don't have permissions to edit the template.
|
||||||
|
NotFound
|
||||||
|
This template does not exist.
|
||||||
|
"""
|
||||||
|
data = await self._state.http.edit_template(self.source_guild.id, self.code, kwargs)
|
||||||
|
self._store(data)
|
||||||
|
|
||||||
|
async def delete(self):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Delete the template.
|
||||||
|
|
||||||
|
You must have the :attr:`~Permissions.manage_guild` permission in the
|
||||||
|
source guild to do this.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
HTTPException
|
||||||
|
Editing the template failed.
|
||||||
|
Forbidden
|
||||||
|
You don't have permissions to edit the template.
|
||||||
|
NotFound
|
||||||
|
This template does not exist.
|
||||||
|
"""
|
||||||
|
await self._state.http.delete_template(self.source_guild.id, self.code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user