Skip to content

Commit

Permalink
[EmbedUtils] Allow replying to messages in commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
AAA3A-AAA3A committed May 9, 2024
1 parent 45fe50a commit 34cc9d5
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions embedutils/embedutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def embed_message(
self,
ctx: commands.Context,
channel_or_message: typing.Optional[MessageableOrMessageConverter],
message: discord.Message,
message: discord.Message = None,
index: int = None,
include_content: typing.Optional[bool] = None,
):
Expand All @@ -283,6 +283,14 @@ async def embed_message(
If you provide a message, it will be edited.
"""
if message is None:
if (
ctx.message.reference is not None
and isinstance((reference := ctx.message.reference.resolved), discord.Message)
):
message = reference
else:
raise commands.UserInputError()
if include_content is None and message.content:
include_content = index is None
data = {}
Expand Down Expand Up @@ -316,7 +324,7 @@ async def embed_message(
async def embed_download(
self,
ctx: commands.Context,
message: discord.Message,
message: discord.Message = None,
index: int = None,
include_content: typing.Optional[bool] = None,
):
Expand All @@ -326,6 +334,14 @@ async def embed_download(
You can specify an index (starting by 0) if you want to include only one of the embeds.
The content of the message already sent is included if no index is specified.
"""
if message is None:
if (
ctx.message.reference is not None
and isinstance((reference := ctx.message.reference.resolved), discord.Message)
):
message = reference
else:
raise commands.UserInputError()
if include_content is None:
include_content = index is None
data = {}
Expand Down Expand Up @@ -410,9 +426,15 @@ async def embed_edit(
raise commands.UserInputError()
data = await PASTEBIN_LIST_CONVERTER.convert(ctx, argument=data)
elif conversion_type in ("message", "frommessage", "msg", "frommsg"):
if data is None:
if data is not None:
message = await commands.MessageConverter().convert(ctx, argument=data)
elif (
ctx.message.reference is not None
and isinstance((reference := ctx.message.reference.resolved), discord.Message)
):
message = reference
else:
raise commands.UserInputError()
message = await commands.MessageConverter().convert(ctx, argument=data)
data = {}
if message.content:
data["content"] = message.content
Expand Down Expand Up @@ -505,9 +527,15 @@ async def embed_store(
raise commands.UserInputError()
data = await PASTEBIN_CONVERTER.convert(ctx, argument=data)
elif conversion_type in ("message", "frommessage", "msg", "frommsg"):
if data is None:
if data is not None:
message = await commands.MessageConverter().convert(ctx, argument=data)
elif (
ctx.message.reference is not None
and isinstance((reference := ctx.message.reference.resolved), discord.Message)
):
message = reference
else:
raise commands.UserInputError()
message = await commands.MessageConverter().convert(ctx, argument=data)
if not message.embeds:
raise commands.UserInputError()
data = {"embed": message.embeds[0].to_dict()}
Expand Down Expand Up @@ -814,9 +842,15 @@ async def dashboard(
raise commands.UserInputError()
data = await PASTEBIN_LIST_CONVERTER.convert(ctx, argument=data)
elif conversion_type in ("message", "frommessage", "msg", "frommsg"):
if data is None:
if data is not None:
message = await commands.MessageConverter().convert(ctx, argument=data)
elif (
ctx.message.reference is not None
and isinstance((reference := ctx.message.reference.resolved), discord.Message)
):
message = reference
else:
raise commands.UserInputError()
message = await commands.MessageConverter().convert(ctx, argument=data)
data = {}
if message.content:
data["content"] = message.content
Expand Down

0 comments on commit 34cc9d5

Please sign in to comment.