Skip to content

Commit b9098b8

Browse files
authored
Merge pull request #2392 from python-discord/use-paste-service-for-long-autoban-filters
Upload weekly autoban report to pastebin
2 parents e8ef3a2 + 074ec33 commit b9098b8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

bot/exts/filtering/filtering.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import io
23
import json
34
import re
45
import unicodedata
@@ -46,6 +47,7 @@
4647
from bot.utils.channel import is_mod_channel
4748
from bot.utils.lock import lock_arg
4849
from bot.utils.message_cache import MessageCache
50+
from bot.utils.services import PasteTooLongError, PasteUploadError, send_to_paste_service
4951

5052
log = get_logger(__name__)
5153

@@ -1400,7 +1402,7 @@ async def send_weekly_auto_infraction_report(self, channel: discord.TextChannel
14001402
"""
14011403
Send a list of auto-infractions added in the last 7 days to the specified channel.
14021404
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.
14041406
"""
14051407
log.trace("Preparing weekly auto-infraction report.")
14061408
seven_days_ago = arrow.utcnow().shift(days=-7)
@@ -1435,9 +1437,24 @@ async def send_weekly_auto_infraction_report(self, channel: discord.TextChannel
14351437
if len(lines) == 1:
14361438
lines.append("Nothing to show")
14371439

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+
)
14401456

1457+
log.info("Successfully sent auto-infraction report.")
14411458
# endregion
14421459

14431460
async def cog_unload(self) -> None:

0 commit comments

Comments
 (0)