Skip to content

Commit

Permalink
Fix attachments in plain messages #3102
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Nov 21, 2021
1 parent fb2e904 commit 33adfc3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
- 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))
- Stickers were not working in Modmail.
- Large server sizes results in Guild.name == None. ([GH #3088](https://github.com/kyb3r/modmail/issues/3088))
- Attachments did not work on plain replies. ([GH #3102](https://github.com/kyb3r/modmail/issues/3102))

### Internal

Expand Down
4 changes: 4 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

logger = getLogger(__name__)

# # prevent "coroutine noop was never awaited" warning.
# asyncio.coroutines._DEBUG = False # type: ignore


temp_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp")
if not os.path.exists(temp_dir):
os.mkdir(temp_dir)
Expand Down
24 changes: 13 additions & 11 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import time
import typing
import warnings
from datetime import timedelta
from types import SimpleNamespace

Expand Down Expand Up @@ -835,6 +836,7 @@ async def reply(
user_msg = await asyncio.gather(*user_msg_tasks)
except Exception as e:
logger.error("Message delivery failed:", exc_info=True)
user_msg = None
if isinstance(e, discord.Forbidden):
description = (
"Your message could not be delivered as "
Expand All @@ -848,12 +850,10 @@ async def reply(
"to an unknown error. Check `?debug` for "
"more information"
)
tasks.append(
message.channel.send(
embed=discord.Embed(
color=self.bot.error_color,
description=description,
)
msg = await message.channel.send(
embed=discord.Embed(
color=self.bot.error_color,
description=description,
)
)
else:
Expand Down Expand Up @@ -1095,17 +1095,19 @@ async def send(
if plain:
if from_mod and not isinstance(destination, discord.TextChannel):
# Plain to user
with warnings.catch_warnings():
# Catch coroutines not awaited warning
warnings.simplefilter("ignore")
additional_images = []

if embed.footer.text:
plain_message = f"**({embed.footer.text}) "
else:
plain_message = "**"
plain_message += f"{embed.author.name}:** {embed.description}"
files = []
for i in embed.fields:
if "Image" in i.name:
async with self.bot.session.get(i.field[i.field.find("http") : -1]) as resp:
stream = io.BytesIO(await resp.read())
files.append(discord.File(stream))
for i in message.attachments:
files.append(await i.to_file())

msg = await destination.send(plain_message, files=files)
else:
Expand Down

0 comments on commit 33adfc3

Please sign in to comment.