Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit e9b7a6c

Browse files
authored
🔀 Merge pull request #281 from trag1c/main
✨ Added Webhook related endpoints
2 parents 8444c39 + bd11b64 commit e9b7a6c

File tree

6 files changed

+447
-22
lines changed

6 files changed

+447
-22
lines changed

pincer/__init__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
DispatchError, DisallowedIntentsError, InvalidTokenError, HeartbeatError,
2525
UnavailableGuildError, HTTPError, NotModifiedError, BadRequestError,
2626
UnauthorizedError, ForbiddenError, NotFoundError, MethodNotAllowedError,
27+
<<<<<<< HEAD
28+
RateLimitError, GatewayError, ServerError, EmbedOverflow
29+
=======
2730
RateLimitError, GatewayError, ServerError, ImageEncodingError
31+
>>>>>>> upstream/main
2832
)
2933
from .objects import Intents
3034

@@ -63,15 +67,15 @@ def __repr__(self) -> str:
6367
"CogAlreadyExists", "CogError", "CogNotFound", "CommandAlreadyRegistered",
6468
"CommandCooldownError", "CommandDescriptionTooLong", "CommandError",
6569
"CommandIsNotCoroutine", "CommandReturnIsEmpty", "DisallowedIntentsError",
66-
"DispatchError", "EmbedFieldError", "ForbiddenError", "GatewayConfig",
67-
"GatewayError", "HTTPError", "HeartbeatError", "ImageEncodingError",
68-
"Intents", "InvalidArgumentAnnotation", "InvalidCommandGuild",
69-
"InvalidCommandName", "InvalidEventName", "InvalidPayload",
70-
"InvalidTokenError", "InvalidUrlError", "MethodNotAllowedError",
71-
"NoCogManagerReturnFound", "NoExportMethod", "NoValidSetupMethod",
72-
"NotFoundError", "NotModifiedError", "PincerError", "RateLimitError",
73-
"ServerError", "TaskAlreadyRunning", "TaskCancelError", "TaskError",
74-
"TaskInvalidDelay", "TaskIsNotCoroutine", "TooManyArguments",
70+
"DispatchError", "EmbedFieldError", "EmbedOverflow", "ForbiddenError",
71+
"GatewayConfig", "GatewayError", "HTTPError", "HeartbeatError",
72+
"ImageEncodingError", "Intents", "InvalidArgumentAnnotation",
73+
"InvalidCommandGuild", "InvalidCommandName", "InvalidEventName",
74+
"InvalidPayload", "InvalidTokenError", "InvalidUrlError",
75+
"MethodNotAllowedError", "NoCogManagerReturnFound", "NoExportMethod",
76+
"NoValidSetupMethod", "NotFoundError", "NotModifiedError", "PincerError",
77+
"RateLimitError", "ServerError", "TaskAlreadyRunning", "TaskCancelError",
78+
"TaskError", "TaskInvalidDelay", "TaskIsNotCoroutine", "TooManyArguments",
7579
"TooManySetupArguments", "UnauthorizedError", "UnavailableGuildError",
7680
"UnhandledException", "__author__", "__email__", "__package__",
7781
"__title__", "__version__", "command", "event_middleware"

pincer/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .utils.snowflake import Snowflake
3838
from .core.dispatch import GatewayDispatch
3939
from .objects.app.throttling import ThrottleInterface
40+
from .objects.guild import Webhook
4041

4142
_log = logging.getLogger(__package__)
4243

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

837+
async def get_webhook(
838+
self,
839+
id: Snowflake,
840+
token: Optional[str] = None
841+
) -> Webhook:
842+
"""|coro|
843+
Fetch a Webhook from its identifier.
844+
845+
Parameters
846+
----------
847+
id: :class:`int`
848+
The id of the webhook which should be
849+
fetched from the Discord gateway.
850+
token: Optional[:class:`str`]
851+
The webhook token.
852+
853+
Returns
854+
-------
855+
:class:`~pincer.objects.guild.webhook.Webhook`
856+
A Webhook object.
857+
"""
858+
return await Webhook.from_id(self, id, token)
836859

837860
Bot = Client

pincer/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def from_desc(cls, _type: str, max_size: int, cur_size: int):
189189
)
190190

191191

192+
class EmbedOverflow(PincerError):
193+
"""Exception that is raised when too many embeds are passed in."""
194+
195+
192196
class TaskError(PincerError):
193197
"""Base class for exceptions that are related to tasks.
194198

pincer/objects/guild/channel.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
from ...utils.types import MISSING
1717

1818
if TYPE_CHECKING:
19-
from typing import Dict, List, Optional, Union
19+
from typing import AsyncGenerator, Dict, List, Optional, Union
2020

2121
from .member import GuildMember
2222
from .overwrite import Overwrite
2323
from .thread import ThreadMetadata
24+
from .webhook import Webhook
2425
from ..message.message import Message
2526
from ..message.embed import Embed
2627
from ..user.user import User
@@ -215,15 +216,21 @@ async def from_id(cls, client: Client, channel_id: int) -> Channel:
215216

216217
@overload
217218
async def edit(
218-
self, *, name: str = None,
219-
type: ChannelType = None,
220-
position: int = None, topic: str = None, nsfw: bool = None,
221-
rate_limit_per_user: int = None, bitrate: int = None,
222-
user_limit: int = None,
223-
permissions_overwrites: List[Overwrite] = None,
224-
parent_id: Snowflake = None, rtc_region: str = None,
225-
video_quality_mod: int = None,
226-
default_auto_archive_duration: int = None
219+
self,
220+
*,
221+
name: str = None,
222+
type: ChannelType = None,
223+
position: int = None,
224+
topic: str = None,
225+
nsfw: bool = None,
226+
rate_limit_per_user: int = None,
227+
bitrate: int = None,
228+
user_limit: int = None,
229+
permissions_overwrites: List[Overwrite] = None,
230+
parent_id: Snowflake = None,
231+
rtc_region: str = None,
232+
video_quality_mod: int = None,
233+
default_auto_archive_duration: int = None
227234
) -> Channel:
228235
...
229236

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

354+
async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
355+
"""|coro|
356+
Get all webhooks in the channel.
357+
Requires the ``MANAGE_WEBHOOKS`` permission.
358+
359+
Yields
360+
-------
361+
AsyncGenerator[:class:`~.pincer.objects.guild.webhook.Webhook`, None]
362+
"""
363+
data = await self._http.get(f"channels/{self.id}/webhooks")
364+
for webhook_data in data:
365+
yield Webhook.from_dict(
366+
construct_client_dict(
367+
self._client,
368+
webhook_data
369+
)
370+
)
371+
347372
def __str__(self):
348373
"""return the discord tag when object gets used as a string."""
349374
return self.name or str(self.id)

pincer/objects/guild/guild.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .template import GuildTemplate
3030
from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
3131
from .widget import GuildWidget
32+
from .webhook import Webhook
3233
from ..user.user import User
3334
from ..user.integration import Integration
3435
from ..voice.region import VoiceRegion
@@ -1537,6 +1538,21 @@ async def delete_template(
15371538
construct_client_dict(self._client, data)
15381539
)
15391540

1541+
async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1542+
"""|coro|
1543+
Returns an async generator of the guild webhooks.
1544+
1545+
Yields
1546+
-------
1547+
AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1548+
The guild webhook object.
1549+
"""
1550+
data = await self._http.get(f"guilds/{self.id}/webhooks")
1551+
for webhook_data in data:
1552+
yield Webhook.from_dict(
1553+
construct_client_dict(self._client, webhook_data)
1554+
)
1555+
15401556
@classmethod
15411557
def from_dict(cls, data) -> Guild:
15421558
"""

0 commit comments

Comments
 (0)