Skip to content

Commit

Permalink
Merge branch 'Pycord-Development:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby authored Oct 29, 2021
2 parents dbf409c + 9496c72 commit 162cce6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 18 deletions.
12 changes: 5 additions & 7 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,18 +569,16 @@ async def on_application_command_error(
This only fires if you do not specify any listeners for command error.
"""
# TODO
# if self.extra_events.get('on_application_command_error', None):
# return
if self.extra_events.get('on_application_command_error', None):
return

command = context.command
if command and command.has_error_handler():
return

# TODO
# cog = context.cog
# if cog and cog.has_error_handler():
# return
cog = context.cog
if cog and cog.has_error_handler():
return

print(f"Ignoring exception in command {context.command}:", file=sys.stderr)
traceback.print_exception(
Expand Down
14 changes: 13 additions & 1 deletion discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations

from typing import TYPE_CHECKING, Optional, Union

Expand All @@ -31,6 +32,9 @@
import discord
from discord.state import ConnectionState

from .commands import ApplicationCommand
from ..cog import Cog

from ..guild import Guild
from ..interactions import Interaction, InteractionResponse
from ..member import Member
Expand Down Expand Up @@ -63,7 +67,7 @@ class ApplicationContext(discord.abc.Messageable):
def __init__(self, bot: "discord.Bot", interaction: Interaction):
self.bot = bot
self.interaction = interaction
self.command = None
self.command: ApplicationCommand = None # type: ignore
self._state: ConnectionState = self.interaction._state

async def _get_channel(self) -> discord.abc.Messageable:
Expand Down Expand Up @@ -130,3 +134,11 @@ async def delete(self):
@property
def edit(self):
return self.interaction.edit_original_message

@property
def cog(self) -> Optional[Cog]:
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. None if it does not exist."""
if self.command is None:
return None

return self.command.cog
31 changes: 31 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,24 @@ class ApplicationFlags(BaseFlags):
rather than using this raw value.
"""

@flag_value
def managed_emoji(self):
""":class:`bool`: Returns ``True`` if the application is a managed emoji.
"""
return 1 << 2

@flag_value
def group_dm_create(self):
""":class:`bool`: Returns ``True`` if the application can create group DMs.
"""
return 1 << 5

@flag_value
def rpc_has_connected(self):
""":class:`bool`: Returns ``True`` if the application has connected to RPC.
"""
return 1 << 11

@flag_value
def gateway_presence(self):
""":class:`bool`: Returns ``True`` if the application is verified and is allowed to
Expand Down Expand Up @@ -1129,3 +1147,16 @@ def verification_pending_guild_limit(self):
def embedded(self):
""":class:`bool`: Returns ``True`` if the application is embedded within the Discord client."""
return 1 << 17

@flag_value
def gateway_message_content(self):
""":class:`bool`: Returns ``True`` if the application is allowed to read message contents in guilds.
"""
return 1 << 18

@flag_value
def gateway_message_content_limited(self):
""":class:`bool`: Returns ``True`` if the application is currently pending verification
and has hit the guild limit.
"""
return 1 << 19
53 changes: 48 additions & 5 deletions discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,21 @@ def get_webhook_message(
message_id: int,
*,
session: aiohttp.ClientSession,
thread_id: Optional[int] = None,
) -> Response[MessagePayload]:
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'GET',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session)
return self.request(route, session, params=params)

def edit_webhook_message(
self,
Expand All @@ -291,18 +297,24 @@ def edit_webhook_message(
message_id: int,
*,
session: aiohttp.ClientSession,
thread_id: Optional[int] = None,
payload: Optional[Dict[str, Any]] = None,
multipart: Optional[List[Dict[str, Any]]] = None,
files: Optional[List[File]] = None,
) -> Response[Message]:
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'PATCH',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session, payload=payload, multipart=multipart, files=files)
return self.request(route, session, params=params, payload=payload, multipart=multipart, files=files)

def delete_webhook_message(
self,
Expand All @@ -311,15 +323,21 @@ def delete_webhook_message(
message_id: int,
*,
session: aiohttp.ClientSession,
thread_id: Optional[int] = None,
) -> Response[None]:
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'DELETE',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session)
return self.request(route, session, params=params)

def fetch_webhook(
self,
Expand Down Expand Up @@ -1429,7 +1447,12 @@ async def send(

return msg

async def fetch_message(self, id: int, /) -> WebhookMessage:
async def fetch_message(
self,
id: int,
*,
thread_id: Optional[int] = None
) -> WebhookMessage:
"""|coro|
Retrieves a single :class:`~discord.WebhookMessage` owned by this webhook.
Expand All @@ -1440,6 +1463,8 @@ async def fetch_message(self, id: int, /) -> WebhookMessage:
------------
id: :class:`int`
The message ID to look for.
thread_id: Optional[:class:`int`]
The ID of the thread that contains the message.
Raises
--------
Expand Down Expand Up @@ -1467,6 +1492,7 @@ async def fetch_message(self, id: int, /) -> WebhookMessage:
self.token,
id,
session=self.session,
thread_id=thread_id,
)
return self._create_message(data)

Expand All @@ -1481,6 +1507,7 @@ async def edit_message(
files: List[File] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
thread: Optional[Snowflake] = MISSING
) -> WebhookMessage:
"""|coro|
Expand Down Expand Up @@ -1523,6 +1550,8 @@ async def edit_message(
:meth:`send`.
.. versionadded:: 2.0
thread: Optional[:class:`~discord.abc.Snowflake`]
The thread that contains the message.
Raises
-------
Expand Down Expand Up @@ -1564,12 +1593,18 @@ async def edit_message(
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)

thread_id: Optional[int] = None
if thread_id is not MISSING:
thread_id = thread.id

adapter = async_context.get()
data = await adapter.edit_webhook_message(
self.id,
self.token,
message_id,
session=self.session,
thread_id=thread_id,
payload=params.payload,
multipart=params.multipart,
files=params.files,
Expand All @@ -1580,7 +1615,12 @@ async def edit_message(
self._state.store_view(view, message_id)
return message

async def delete_message(self, message_id: int, /) -> None:
async def delete_message(
self,
message_id: int,
*,
thread_id: Optional[int] = None
) -> None:
"""|coro|
Deletes a message owned by this webhook.
Expand All @@ -1594,6 +1634,8 @@ async def delete_message(self, message_id: int, /) -> None:
------------
message_id: :class:`int`
The message ID to delete.
thread_id: Optional[:class:`int`]
The ID of the thread that contains the message.
Raises
-------
Expand All @@ -1611,4 +1653,5 @@ async def delete_message(self, message_id: int, /) -> None:
self.token,
message_id,
session=self.session,
thread_id=thread_id,
)
Loading

0 comments on commit 162cce6

Please sign in to comment.