Skip to content

Commit 33adfc3

Browse files
committed
Fix attachments in plain messages modmail-dev#3102
1 parent fb2e904 commit 33adfc3

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
2525
- Certain cases where `?close` would fail if closer isn't in cache. ([GH #3104](https://github.com/kyb3r/modmail/issues/3104), [PR #3105](https://github.com/kyb3r/modmail/pull/3105))
2626
- Stickers were not working in Modmail.
2727
- Large server sizes results in Guild.name == None. ([GH #3088](https://github.com/kyb3r/modmail/issues/3088))
28+
- Attachments did not work on plain replies. ([GH #3102](https://github.com/kyb3r/modmail/issues/3102))
2829

2930
### Internal
3031

bot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050

5151
logger = getLogger(__name__)
5252

53+
# # prevent "coroutine noop was never awaited" warning.
54+
# asyncio.coroutines._DEBUG = False # type: ignore
55+
56+
5357
temp_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp")
5458
if not os.path.exists(temp_dir):
5559
os.mkdir(temp_dir)

core/thread.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import time
66
import typing
7+
import warnings
78
from datetime import timedelta
89
from types import SimpleNamespace
910

@@ -835,6 +836,7 @@ async def reply(
835836
user_msg = await asyncio.gather(*user_msg_tasks)
836837
except Exception as e:
837838
logger.error("Message delivery failed:", exc_info=True)
839+
user_msg = None
838840
if isinstance(e, discord.Forbidden):
839841
description = (
840842
"Your message could not be delivered as "
@@ -848,12 +850,10 @@ async def reply(
848850
"to an unknown error. Check `?debug` for "
849851
"more information"
850852
)
851-
tasks.append(
852-
message.channel.send(
853-
embed=discord.Embed(
854-
color=self.bot.error_color,
855-
description=description,
856-
)
853+
msg = await message.channel.send(
854+
embed=discord.Embed(
855+
color=self.bot.error_color,
856+
description=description,
857857
)
858858
)
859859
else:
@@ -1095,17 +1095,19 @@ async def send(
10951095
if plain:
10961096
if from_mod and not isinstance(destination, discord.TextChannel):
10971097
# Plain to user
1098+
with warnings.catch_warnings():
1099+
# Catch coroutines not awaited warning
1100+
warnings.simplefilter("ignore")
1101+
additional_images = []
1102+
10981103
if embed.footer.text:
10991104
plain_message = f"**({embed.footer.text}) "
11001105
else:
11011106
plain_message = "**"
11021107
plain_message += f"{embed.author.name}:** {embed.description}"
11031108
files = []
1104-
for i in embed.fields:
1105-
if "Image" in i.name:
1106-
async with self.bot.session.get(i.field[i.field.find("http") : -1]) as resp:
1107-
stream = io.BytesIO(await resp.read())
1108-
files.append(discord.File(stream))
1109+
for i in message.attachments:
1110+
files.append(await i.to_file())
11091111

11101112
msg = await destination.send(plain_message, files=files)
11111113
else:

0 commit comments

Comments
 (0)