aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2023-01-29 17:12:30 +0000
committerGravatar Chris Lovering <[email protected]>2023-04-13 14:28:36 +0100
commite75a94a836d0de81ccd8644544581c1465203af9 (patch)
tree64aa3fbd6b4856999fd7025eac4f75af7d4c9714
parentBump pip-licenses from 4.1.0 to 4.2.0 (#2531) (diff)
Upload weekly autoban report to pastebin
This fixes #2391 and solves BOT-3CR which was caused by the weekly report being longer than 2000 characters. Instead of posting the entire report to Discord, it is now upload to the pastebin, and uploaded as a text file to the channel, so people can use what they prefer.
-rw-r--r--bot/exts/filtering/filtering.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/bot/exts/filtering/filtering.py b/bot/exts/filtering/filtering.py
index 8e7ba7476..aa53cab26 100644
--- a/bot/exts/filtering/filtering.py
+++ b/bot/exts/filtering/filtering.py
@@ -1,4 +1,5 @@
import datetime
+import io
import json
import re
import unicodedata
@@ -46,6 +47,7 @@ from bot.pagination import LinePaginator
from bot.utils.channel import is_mod_channel
from bot.utils.lock import lock_arg
from bot.utils.message_cache import MessageCache
+from bot.utils.services import PasteTooLongError, PasteUploadError, send_to_paste_service
log = get_logger(__name__)
@@ -1400,7 +1402,7 @@ class Filtering(Cog):
"""
Send a list of auto-infractions added in the last 7 days to the specified channel.
- If `channel` is not specified, it is sent to #mod-meta.
+ If `channel` is not specified, the report is sent to #mod-meta instead.
"""
log.trace("Preparing weekly auto-infraction report.")
seven_days_ago = arrow.utcnow().shift(days=-7)
@@ -1435,9 +1437,24 @@ class Filtering(Cog):
if len(lines) == 1:
lines.append("Nothing to show")
- await channel.send("\n\n".join(lines))
- log.info("Successfully sent auto-infraction report.")
+ report = "\n\n".join(lines)
+ try:
+ await channel.send(report)
+ except discord.HTTPException as e:
+ if e.code != 50035: # Content too long
+ raise
+ report = discord.utils.remove_markdown(report)
+ try:
+ paste_resp = await send_to_paste_service(report, extension="txt")
+ except (ValueError, PasteTooLongError, PasteUploadError):
+ paste_resp = ":warning: Failed to upload report to paste service"
+ file_buffer = io.StringIO(report)
+ await channel.send(
+ f"**{lines[0]}**\n\n{paste_resp}",
+ file=discord.File(file_buffer, "last_weeks_autoban_filters.txt"),
+ )
+ log.info("Successfully sent auto-infraction report.")
# endregion
async def cog_unload(self) -> None: