asyncio debug and format current code

This commit is contained in:
grey-cat-1908 2022-04-10 10:13:56 +03:00
parent 15da6ac9d2
commit 017ad57190
3 changed files with 34 additions and 27 deletions

View file

@ -4,9 +4,9 @@
import logging
import asyncio
import signal
from typing import Dict, List, Union, Any, Iterable
from .models.app.intents import Intents
from typing import Dict, List, Union, Any, Iterable, Optional, TYPE_CHECKING
from .models import User, Guild, Activity
from .models.app import Shard
from .utils import Snowflake, APIModelBase
@ -16,6 +16,9 @@ from .core.gateway import GatewayBotInfo
from .models.guild.channel import Channel, ChannelType, channel_types_for_converting
from .utils.logging import init_logging
if TYPE_CHECKING:
from .models.app.intents import Intents
_logger = logging.getLogger("melisa")
@ -29,6 +32,8 @@ class Client:
----------
token: :class:`str`
The token to login (you can found it in the developer portal)
asyncio_debug: :class:`bool`
If ``True``, then debugging is enabled for the asyncio event loop in use.
intents: :class:`Union[~melisa.Intents, Iterable[~melisa.Intents]]`
The Discord Intents values.
activity: :class:`~models.user.presence.BotActivity`
@ -59,8 +64,9 @@ class Client:
self,
token: str,
*,
asyncio_debug: bool = False,
intents: Union[Intents, Iterable[Intents]] = None,
activity: Activity = None,
activity: Optional[Activity] = None,
status: str = None,
mobile: bool = False,
logs: Union[None, int, str, Dict[str, Any]] = "INFO",
@ -106,6 +112,9 @@ class Client:
print("(SIGINT received some seconds ago) Successfully stopped client loop")
if asyncio_debug:
self._loop.set_debug(True)
signal.signal(signal.SIGINT, sigint_handler)
async def _get_gateway(self):

View file

@ -25,7 +25,8 @@ class WebhookType(IntEnum):
Incoming:
Incoming Webhooks can post messages to channels with a generated token
Channel_Follower:
Channel Follower Webhooks are internal webhooks used with Channel Following to post new messages into channels
Channel Follower Webhooks are internal webhooks used with Channel Following
to post new messages into channels
Application:
Application webhooks are webhooks used with Interactions
"""
@ -64,7 +65,8 @@ class Webhook(APIModelBase):
application_id: :class:`~melisa.utils.types.snowflake.Snowflake`
The bot/OAuth2 application that created this webhook
source_guild: :class:`~melisa.models.guild.guild.Guild`
The guild of the channel that this webhook is following (returned for Channel Follower Webhooks)
The guild of the channel that this webhook is following
(returned for Channel Follower Webhooks)
source_channel: :class:`~melisa.models.guild.channel.Channel`
The channel that this webhook is following (returned for Channel Follower Webhooks)
url: :class:`str`
@ -85,19 +87,22 @@ class Webhook(APIModelBase):
url: APINullable[str] = None
async def create(
self,
*,
channel_id: Optional[Snowflake] = None,
name: Optional[str] = None,
reason: Optional[str] = None
self,
*,
channel_id: Optional[Snowflake] = None,
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.
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:
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
* It follows the nickname guidelines in the Usernames
and Nicknames documentation, with an exception that
webhook names can be up to 80 characters
Parameters
@ -108,13 +113,9 @@ class Webhook(APIModelBase):
Name of the webhook (1-80 characters)
reason: Optional[:class:`str`]
The reason for pinning the message. Shows up on the audit log.
Returns
-------
¯\_()_/¯
"""
await self._http.post(
f"/channels/{channel_id}/webhooks",
headers={"name": name, "X-Audit-Log-Reason": reason}
headers={"name": name, "X-Audit-Log-Reason": reason},
)

View file

@ -201,9 +201,7 @@ class Message(APIModelBase):
sticker_items: APINullable[List] = None
stickers: APINullable[List] = None
async def pin(
self, *, reason: Optional[str] = None
):
async def pin(self, *, reason: Optional[str] = None):
"""|coro|
Pins the message.
@ -218,7 +216,8 @@ class Message(APIModelBase):
Raises
-------
HTTPException
Pinning the message failed, probably due to the channel having more than 50 pinned messages.
Pinning the message failed,
probably due to the channel having more than 50 pinned messages.
ForbiddenError
You do not have permissions to pin the message.
NotFound
@ -230,9 +229,7 @@ class Message(APIModelBase):
headers={"X-Audit-Log-Reason": reason},
)
async def unpin(
self, *, reason: Optional[str] = None
):
async def unpin(self, *, reason: Optional[str] = None):
"""|coro|
Unpins the message.
@ -247,7 +244,8 @@ class Message(APIModelBase):
Raises
-------
HTTPException
Pinning the message failed, probably due to the channel having more than 50 pinned messages.
Pinning the message failed,
probably due to the channel having more than 50 pinned messages.
ForbiddenError
You do not have permissions to unpin the message.
NotFound
@ -258,4 +256,3 @@ class Message(APIModelBase):
f"channels/{self.channel_id}/pins/{self.id}",
headers={"X-Audit-Log-Reason": reason},
)