Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
131e1df
Added Channel.get_webhooks
Nov 30, 2021
6a09caa
Adjusted docstring
Nov 30, 2021
d2b9765
Replaced `Returns` with `Yields`
Nov 30, 2021
8e26a2c
Added Guild.get_webhooks
Nov 30, 2021
e676b40
Improved formatting
Nov 30, 2021
f0713f3
Added Webhook.from_id
Nov 30, 2021
21a1641
Added Client.get_webhook
Nov 30, 2021
359bfaa
Added token support
Nov 30, 2021
25bdfd0
Added token support
Nov 30, 2021
58982a9
Added Webhook.edit
Nov 30, 2021
a34eb5f
Added token support
Nov 30, 2021
984a95e
Added Webhook.delete
Nov 30, 2021
ceaa612
Refactored `request_data`
Nov 30, 2021
ec20815
Added Webhook.execute_slack
Nov 30, 2021
1454f09
Added Webhook.execute and Webhook.get_message
Nov 30, 2021
ff721fe
Merge branch 'Pincer-org:main' into main
trag1c Nov 30, 2021
9b6092c
Fixed Webhook.get_message, added Webhook.delete_message
Nov 30, 2021
6e8e597
Merge branch 'Pincer-org:main' into main
trag1c Nov 30, 2021
8ca3f3b
Merge branch 'main' of https://github.com/trag1c/Pincer
Nov 30, 2021
23f1fd4
Added Webhook.edit_message
Nov 30, 2021
1dbc5ea
Fixed `typing.overload` import
Nov 30, 2021
ead5768
Ignoring line length limit
Nov 30, 2021
add72af
Added EmbedOverflow
Nov 30, 2021
5ce55d1
Fixed issues
Nov 30, 2021
5fd2ee8
Fixed typehints
Nov 30, 2021
404e6f0
Added EmbedOverflow
Dec 1, 2021
359f274
:art: Automatic sorting
Dec 1, 2021
f9a4e06
:art: removed slash in WebhookCompatability
zunda-arrow Dec 2, 2021
eba58f8
:hammer: Automatic update of setup.cfg
Dec 2, 2021
fbee189
:bug: added .value in if statement
zunda-arrow Dec 2, 2021
a733185
Merge branch 'main' of https://github.com/trag1c/Pincer into tragic_main
zunda-arrow Dec 2, 2021
2b721ea
Merge remote-tracking branch 'upstream/main' into HEAD
zunda-arrow Dec 3, 2021
70c6d25
:twisted_rightwards_arrows: merge with https://github.com/Pincer-org/…
zunda-arrow Dec 3, 2021
bd11b64
:art: Automatic sorting
Dec 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pincer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from .utils.snowflake import Snowflake
from .core.dispatch import GatewayDispatch
from .objects.app.throttling import ThrottleInterface
from .objects.guild import Webhook

_log = logging.getLogger(__package__)

Expand Down Expand Up @@ -833,5 +834,27 @@ async def get_channel(self, _id: int) -> Channel:
"""
return await Channel.from_id(self, _id)

async def get_webhook(
self,
id: Snowflake,
token: Optional[str] = None
) -> Webhook:
"""|coro|
Fetch a Webhook from its identifier.

Parameters
----------
id: :class:`int`
The id of the webhook which should be
fetched from the Discord gateway.
token: Optional[:class:`str`]
The webhook token.

Returns
-------
:class:`~pincer.objects.guild.webhook.Webhook`
A Webhook object.
"""
return await Webhook.from_id(self, id, token)

Bot = Client
45 changes: 35 additions & 10 deletions pincer/objects/guild/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from ...utils.types import MISSING

if TYPE_CHECKING:
from typing import Dict, List, Optional, Union
from typing import AsyncGenerator, Dict, List, Optional, Union

from .member import GuildMember
from .overwrite import Overwrite
from .thread import ThreadMetadata
from .webhook import Webhook
from ..message.message import Message
from ..message.embed import Embed
from ..user.user import User
Expand Down Expand Up @@ -215,15 +216,21 @@ async def from_id(cls, client: Client, channel_id: int) -> Channel:

@overload
async def edit(
self, *, name: str = None,
type: ChannelType = None,
position: int = None, topic: str = None, nsfw: bool = None,
rate_limit_per_user: int = None, bitrate: int = None,
user_limit: int = None,
permissions_overwrites: List[Overwrite] = None,
parent_id: Snowflake = None, rtc_region: str = None,
video_quality_mod: int = None,
default_auto_archive_duration: int = None
self,
*,
name: str = None,
type: ChannelType = None,
position: int = None,
topic: str = None,
nsfw: bool = None,
rate_limit_per_user: int = None,
bitrate: int = None,
user_limit: int = None,
permissions_overwrites: List[Overwrite] = None,
parent_id: Snowflake = None,
rtc_region: str = None,
video_quality_mod: int = None,
default_auto_archive_duration: int = None
) -> Channel:
...

Expand Down Expand Up @@ -344,6 +351,24 @@ async def send(self, message: Union[Embed, Message, str]) -> UserMessage:
self.__post_sent(msg)
return msg

async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
"""|coro|
Get all webhooks in the channel.
Requires the ``MANAGE_WEBHOOKS`` permission.

Yields
-------
AsyncGenerator[:class:`~.pincer.objects.guild.webhook.Webhook`, None]
"""
data = await self._http.get(f"channels/{self.id}/webhooks")
for webhook_data in data:
yield Webhook.from_dict(
construct_client_dict(
self._client,
webhook_data
)
)

def __str__(self):
"""return the discord tag when object gets used as a string."""
return self.name or str(self.id)
Expand Down
16 changes: 16 additions & 0 deletions pincer/objects/guild/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .template import GuildTemplate
from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
from .widget import GuildWidget
from .webhook import Webhook
from ..user.user import User
from ..user.integration import Integration
from ..voice.region import VoiceRegion
Expand Down Expand Up @@ -1532,6 +1533,21 @@ async def delete_template(
construct_client_dict(self._client, data)
)

async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
"""|coro|
Returns an async generator of the guild webhooks.

Yields
-------
AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
The guild webhook object.
"""
data = await self._http.get(f"guilds/{self.id}/webhooks")
for webhook_data in data:
yield Webhook.from_dict(
construct_client_dict(self._client, webhook_data)
)

@classmethod
def from_dict(cls, data) -> Guild:
"""
Expand Down
Loading