diff options
| author | 2019-12-03 20:29:23 -0800 | |
|---|---|---|
| committer | 2019-12-03 20:29:23 -0800 | |
| commit | 0f71c817320c077463a483701c6d51a8fa3e2164 (patch) | |
| tree | cbf509a1117a9c5bab6f6c1071e578e1b91ea862 | |
| parent | Utils: add send_attachments param to disable linking to too-large files (diff) | |
Utils: log send_attachments failures instead of raising exceptions
| -rw-r--r-- | bot/utils/messages.py | 11 | 
1 files changed, 10 insertions, 1 deletions
diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 232d3cba6..a39521b72 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -1,5 +1,6 @@  import asyncio  import contextlib +import logging  from io import BytesIO  from typing import List, Optional, Sequence, Union @@ -9,6 +10,8 @@ from discord.errors import HTTPException  from bot.constants import Emojis +log = logging.getLogger(__name__) +  async def wait_for_deletion(      message: Message, @@ -64,6 +67,10 @@ async def send_attachments(      large = []      urls = []      for attachment in message.attachments: +        failure_msg = ( +            f"Failed to re-upload attachment {attachment.filename} from message {message.id}" +        ) +          try:              # Allow 512 bytes of leeway for the rest of the request.              # This should avoid most files that are too large, @@ -84,11 +91,13 @@ async def send_attachments(                          )              elif link_large:                  large.append(attachment) +            else: +                log.warning(f"{failure_msg} because it's too large.")          except HTTPException as e:              if link_large and e.status == 413:                  large.append(attachment)              else: -                raise +                log.warning(f"{failure_msg} with status {e.status}.")      if link_large and large:          desc = f"\n".join(f"[{attachment.filename}]({attachment.url})" for attachment in large)  |