Skip to content

Commit

Permalink
Minor Message Discovery Update (#39)
Browse files Browse the repository at this point in the history
Embeds are now fetched while discovering messages that lack content.
  • Loading branch information
Tech-TTGames authored Mar 5, 2023
2 parents 7c0865e + b04bf8b commit 9005bf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 28 additions & 11 deletions main_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,39 @@ async def on_message(self, message: discord.Message) -> None:
return
if self._bt.intents.message_content:
alpha = re.search(
r"https:\/\/(?:canary\.)?discord\.com\/channels\/(?P<srv>\d{18})\/(?P<cha>\d{18})\/(?P<msg>\d*)", # skipcq: FLK-E501 # pylint: disable=line-too-long
r"https:\/\/(?:canary\.)?discord\.com\/channels\/(?P<srv>\d{18})\/(?P<cha>\d{18})\/(?P<msg>\d*)", # pylint: disable=line-too-long
message.content,
) # pylint: disable=line-too-long
)
if alpha:
try:
chan = self._bt.get_guild(int(alpha.group("srv"))).get_channel_or_thread(int(alpha.group("cha"))) # type: ignore pylint: disable=line-too-long
got_msg = await chan.fetch_message(int(alpha.groupdict()["msg"])) # type: ignore # pylint: disable=line-too-long
except: # pylint: disable=bare-except
try: # We do not check any types in this block as we are catching the error for it.
gld = self._bt.get_guild(int(alpha.group("srv")))
chan = gld.get_channel_or_thread(int(alpha.group("cha"))) # type: ignore
got_msg = await chan.fetch_message(int(alpha.group("msg"))) # type: ignore
except (
AttributeError,
discord.HTTPException,
):
return
data = discord.Embed(description=got_msg.content, color=0x0D0EB4)
data.set_author(name=got_msg.author.name, icon_url=got_msg.author.avatar.url) # type: ignore # pylint: disable=line-too-long
data.set_footer(text=f"Sent in {got_msg.channel.name} at {got_msg.created_at}") # type: ignore # pylint: disable=line-too-long
data.set_image(
if not got_msg.content and got_msg.embeds:
discovered_result = got_msg.embeds[0]
discovered_result.set_footer(
text=f"[EMBED CAPTURED] Sent in {chan.name}" # type: ignore
f" at {got_msg.created_at}"
)
else:
discovered_result = discord.Embed(
description=got_msg.content, color=0x0D0EB4
)
discovered_result.set_footer(
text=f"Sent in {chan.name} at {got_msg.created_at}" # type: ignore
)
discovered_result.set_author(
name=got_msg.author.name, icon_url=got_msg.author.display_avatar.url
)
discovered_result.set_image(
url=got_msg.attachments[0].url if got_msg.attachments else None
)
await message.reply(embed=data)
await message.reply(embed=discovered_result)

@app_commands.command(
name="ping", description="The classic ping command. Checks the bot's latency."
Expand Down
2 changes: 1 addition & 1 deletion variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# v[major].[minor].[release].[build]
# MAJOR and MINOR version changes can be compatibility-breaking
VERSION = "v0.0.3.0"
VERSION = "v0.0.3.1"
PROG_DIR = os.path.dirname(os.path.realpath(__file__))

intents = discord.Intents.default()
Expand Down

0 comments on commit 9005bf1

Please sign in to comment.