forked from OmegaDevStudio/Selfcord-Old
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import annotations | ||
from typing import Optional, TYPE_CHECKING | ||
from .assets import Asset | ||
from .message import Message | ||
|
||
if TYPE_CHECKING: | ||
from ..bot import Bot | ||
|
||
|
||
# TODO: Implement webhooks | ||
|
||
|
||
class Webhook: | ||
def __init__(self, payload: dict, bot: Bot): | ||
self.bot = bot | ||
self.http = bot.http | ||
self.update(payload) | ||
|
||
@property | ||
def url(self) -> str: | ||
return f"https://discord.com/api/webhooks/{self.id}/{self.token}" | ||
|
||
@property | ||
def avatar(self) -> Asset: | ||
return Asset(self.id, self.avatar) | ||
|
||
|
||
def update(self, payload: dict): | ||
self.id = payload.get("id") | ||
self.type = payload.get("type") | ||
self.guild_id = payload.get("guild_id") | ||
self.channel_id = payload.get("channel_id") | ||
self.user = payload.get("user") | ||
self.name = payload.get("name") | ||
|
||
self.token = payload.get("token") | ||
self.application_id = payload.get("application_id") | ||
self.source_guild = payload.get("source_guild") | ||
self.source_channel = payload.get("source_channel") | ||
|
||
async def delete(self): | ||
await self.http.request( | ||
"DELETE", | ||
f"/webhooks/{self.id}/{self.token}" | ||
) | ||
|
||
async def send(self, content: Optional[str] = None): | ||
json = await self.http.request( | ||
"POST", | ||
f"/webhooks/{self.id}/{self.token}", | ||
json={ | ||
"content": content, | ||
|
||
} | ||
) | ||
if json is not None: | ||
return Message(json, self.bot) | ||
|