mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
feat(webhook): add classmethod
This commit is contained in:
parent
cc5f94f380
commit
b725b96578
1 changed files with 34 additions and 1 deletions
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING, Optional, Dict
|
||||
|
||||
from ...utils import Snowflake
|
||||
from ...utils.api_model import APIModelBase
|
||||
|
@ -86,6 +86,39 @@ class Webhook(APIModelBase):
|
|||
source_channel: APINullable[Channel] = UNDEFINED
|
||||
url: APINullable[str] = UNDEFINED
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict[str, any]) -> Webhook:
|
||||
"""Generate a webhook from the given data.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
data: :class:`dict`
|
||||
The dictionary to convert into a webhook.
|
||||
"""
|
||||
|
||||
self: Webhook = super().__new__(cls)
|
||||
|
||||
self.id = int(data["id"])
|
||||
self.type = data.get("type")
|
||||
self.guild_id = data.get("guild_id")
|
||||
self.channel_id = data.get("channel_id")
|
||||
self.user = data.get("user", {})
|
||||
self.avatar = data.get("avatar")
|
||||
self.token = data.get("token")
|
||||
self.application_id = data.get("application_id")
|
||||
|
||||
if data.get("source_guild") is not None:
|
||||
self.source_guild = data.get("source_guild", {})
|
||||
else:
|
||||
self.source_guild = None
|
||||
|
||||
if data.get("source_channel") is not None:
|
||||
self.source_channel = data.get("source_channel", {})
|
||||
else:
|
||||
self.source_channel = None
|
||||
|
||||
self.url = data.get("url")
|
||||
|
||||
async def delete(self, *, reason: Optional[str] = None):
|
||||
"""|coro|
|
||||
Delete a webhook permanently. Requires the ``MANAGE_WEBHOOKS`` permission.
|
||||
|
|
Loading…
Reference in a new issue