hide typehints and embed add_field method

This commit is contained in:
grey-cat-1908 2022-04-13 21:23:20 +03:00
parent aba0aebccd
commit c783acd340
3 changed files with 68 additions and 37 deletions

View file

@ -50,6 +50,8 @@ autodoc_default_options = {
'show-inheritance': True
}
autodoc_typehints = 'none'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

View file

@ -239,47 +239,15 @@ class Channel(APIModelBase):
Returns
-------
Dict[:class:`str`, Any]
Channel
Channel object.
"""
message = await self._http.delete(
data = await self._http.delete(
f"/channels/{self.id}", headers={"X-Audit-Log-Reason": reason}
)
return message
async def create_webhook(
self,
*,
name: Optional[str] = None,
reason: Optional[str] = None,
):
"""|coro|
Creates a new webhook and returns a webhook object on success.
Requires the ``MANAGE_WEBHOOKS`` permission.
An error will be returned if a webhook name (`name`) is not valid.
A webhook name is valid if:
* It does not contain the substring 'clyde' (case-insensitive)
* It follows the nickname guidelines in the Usernames
and Nicknames documentation, with an exception that
webhook names can be up to 80 characters
Parameters
----------
name: Optional[:class:`str`]
Name of the webhook (1-80 characters)
reason: Optional[:class:`str`]
The reason for create the webhook. Shows up on the audit log.
"""
await self._http.post(
f"/channels/{self.id}/webhooks",
headers={"name": name, "X-Audit-Log-Reason": reason},
)
return Channel.from_dict(data)
class MessageableChannel(Channel):
"""A subclass of ``Channel`` with methods that are only available for channels,
@ -569,7 +537,9 @@ class MessageableChannel(Channel):
embeds = []
content = str(content) if content is not None else None
embeds.append(embed.to_dict()) if embed is not None else None
if embed is not None:
embeds.append(embed.to_dict())
for _embed in embeds:
if embed.total_length() > 6000:
@ -745,6 +715,37 @@ class TextChannel(MessageableChannel):
"""
return await super().edit(**kwargs)
async def create_webhook(
self,
*,
name: Optional[str] = None,
reason: Optional[str] = None,
):
"""|coro|
Creates a new webhook and returns a webhook object on success.
Requires the ``MANAGE_WEBHOOKS`` permission.
An error will be returned if a webhook name (`name`) is not valid.
A webhook name is valid if:
* It does not contain the substring 'clyde' (case-insensitive)
* It follows the nickname guidelines in the Usernames
and Nicknames documentation, with an exception that
webhook names can be up to 80 characters
Parameters
----------
name: Optional[:class:`str`]
Name of the webhook (1-80 characters)
reason: Optional[:class:`str`]
The reason for create the webhook. Shows up on the audit log.
"""
await self._http.post(
f"/channels/{self.id}/webhooks",
headers={"name": name, "X-Audit-Log-Reason": reason},
)
class Thread(MessageableChannel):
"""A subclass of ``Channel`` for threads with all the same attributes."""

View file

@ -184,7 +184,7 @@ class EmbedField(APIModelBase):
name: str
value: str
inline: APINullable[str] = None
inline: APINullable[bool] = False
@dataclass(repr=False)
@ -372,6 +372,34 @@ class Embed(APIModelBase):
return self
def add_field(self, name: str, value: str, *, inline: bool = False):
"""
Adds a field to the embed object.
This function returns the class instance to allow for fluent-style chaining.
Parameters
----------
name: :class:`str`
The name of the field.
value: :class:`str`
The value of the field.
inline: :class:`bool`
Whether the field should be displayed inline.
Returns
-------
Embed
This embed.
"""
if self.fields is None:
self.fields = []
self.fields.append(EmbedField(name=name, value=value, inline=inline))
return self
def total_length(self) -> int:
"""Get the total character count of the embed.