From 9970fab505ef4c0619a2b0f76fde79e649be1525 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 15 Apr 2022 00:58:32 +0200 Subject: [PATCH 1/5] Set justMyCode to false --- .vscode/launch.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7dd7d90..f20797a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,8 @@ "type": "python", "request": "launch", "program": "src/bot.py", - "console": "integratedTerminal" + "console": "integratedTerminal", + "justMyCode": false }, { "name": "pytest", From d2d135652166030f34416eff618a4a5127a723b2 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 15 Apr 2022 01:01:33 +0200 Subject: [PATCH 2/5] Escape ANSI escape sequences --- src/error.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/error.py b/src/error.py index 7bca386..17249e8 100644 --- a/src/error.py +++ b/src/error.py @@ -1,4 +1,5 @@ import logging +import re from discord.ext import commands @@ -27,8 +28,11 @@ class ErrorHandler(commands.Cog): else: message = "Oh no! Something went wrong while running the command!" + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + message = ansi_escape.sub("", message) + self.logger.error('Error during command "%s": %s', command_name, message) - embed = ErrorMessage(message) + embed = ErrorMessage(message, command_name=command_name) await ctx.send(embed=embed) From bbbb39bf3d67aaabb8a160f80f3ae60bd225fca0 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 15 Apr 2022 01:01:55 +0200 Subject: [PATCH 3/5] Truncate title to 256 characters --- src/message.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/message.py b/src/message.py index 6998ef0..a505b4e 100644 --- a/src/message.py +++ b/src/message.py @@ -2,7 +2,15 @@ import discord class BotMessage(discord.Embed): - pass + def __init__(self, **kwargs): + title = kwargs.pop("title", None)[:256] + if title is not None: + # Max embed title length is 256 + title = title[:256] + super().__init__( + **kwargs, + title=title + ) class ErrorMessage(BotMessage): From e9e6e07a835b8a6f9ce2fb6c8167744257de1405 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 15 Apr 2022 01:03:36 +0200 Subject: [PATCH 4/5] Better user error messages for errors by youtubedl --- src/message.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/message.py b/src/message.py index a505b4e..61908e7 100644 --- a/src/message.py +++ b/src/message.py @@ -1,3 +1,5 @@ +import re + import discord @@ -14,9 +16,16 @@ class BotMessage(discord.Embed): class ErrorMessage(BotMessage): - def __init__(self, message): + def __init__(self, message, *, command_name: str = None): + title = message + if command_name: + title = f'Error during command "{command_name}"' + description = None + if match := re.search(r"(?P\w+Error): ?(ERROR: ?)?(?P.*): ?Traceback", message): + description = f"{match.group('error')}: {match.group('message')}" super().__init__( - title=f"Error: {message}", + title=title, + description=description, color=discord.Color.red() ) From fe8243cf95fee36e08c958a78b4703ada2dc8b0d Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 15 Apr 2022 01:18:01 +0200 Subject: [PATCH 5/5] Update youtube-dl to 2021.12.17 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 99068a4..a667e18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,4 +33,4 @@ toml==0.10.2 typing-extensions==3.10.0.2 wrapt==1.12.1 yarl==1.6.3 -youtube-dl==2021.6.6 +youtube-dl==2021.12.17