|
1 | 1 | import datetime
|
| 2 | +import io |
2 | 3 | import json
|
3 | 4 | import re
|
4 | 5 | import unicodedata
|
|
46 | 47 | from bot.utils.channel import is_mod_channel
|
47 | 48 | from bot.utils.lock import lock_arg
|
48 | 49 | from bot.utils.message_cache import MessageCache
|
| 50 | +from bot.utils.services import PasteTooLongError, PasteUploadError, send_to_paste_service |
49 | 51 |
|
50 | 52 | log = get_logger(__name__)
|
51 | 53 |
|
@@ -1400,7 +1402,7 @@ async def send_weekly_auto_infraction_report(self, channel: discord.TextChannel
|
1400 | 1402 | """
|
1401 | 1403 | Send a list of auto-infractions added in the last 7 days to the specified channel.
|
1402 | 1404 |
|
1403 |
| - If `channel` is not specified, it is sent to #mod-meta. |
| 1405 | + If `channel` is not specified, the report is sent to #mod-meta instead. |
1404 | 1406 | """
|
1405 | 1407 | log.trace("Preparing weekly auto-infraction report.")
|
1406 | 1408 | seven_days_ago = arrow.utcnow().shift(days=-7)
|
@@ -1435,9 +1437,24 @@ async def send_weekly_auto_infraction_report(self, channel: discord.TextChannel
|
1435 | 1437 | if len(lines) == 1:
|
1436 | 1438 | lines.append("Nothing to show")
|
1437 | 1439 |
|
1438 |
| - await channel.send("\n\n".join(lines)) |
1439 |
| - log.info("Successfully sent auto-infraction report.") |
| 1440 | + report = "\n\n".join(lines) |
| 1441 | + try: |
| 1442 | + await channel.send(report) |
| 1443 | + except discord.HTTPException as e: |
| 1444 | + if e.code != 50035: # Content too long |
| 1445 | + raise |
| 1446 | + report = discord.utils.remove_markdown(report) |
| 1447 | + try: |
| 1448 | + paste_resp = await send_to_paste_service(report, extension="txt") |
| 1449 | + except (ValueError, PasteTooLongError, PasteUploadError): |
| 1450 | + paste_resp = ":warning: Failed to upload report to paste service" |
| 1451 | + file_buffer = io.StringIO(report) |
| 1452 | + await channel.send( |
| 1453 | + f"**{lines[0]}**\n\n{paste_resp}", |
| 1454 | + file=discord.File(file_buffer, "last_weeks_autoban_filters.txt"), |
| 1455 | + ) |
1440 | 1456 |
|
| 1457 | + log.info("Successfully sent auto-infraction report.") |
1441 | 1458 | # endregion
|
1442 | 1459 |
|
1443 | 1460 | async def cog_unload(self) -> None:
|
|
0 commit comments