Merge branch '26-signature-extraction-failed' into 'develop'

Resolve "Signature extraction failed"

Closes #26

See merge request ekzyis/musicube!23
This commit is contained in:
Ramdip Gill 2022-04-14 23:19:23 +00:00
commit 550f36652b
4 changed files with 28 additions and 6 deletions

3
.vscode/launch.json vendored
View File

@ -9,7 +9,8 @@
"type": "python",
"request": "launch",
"program": "src/bot.py",
"console": "integratedTerminal"
"console": "integratedTerminal",
"justMyCode": false
},
{
"name": "pytest",

View File

@ -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

View File

@ -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)

View File

@ -1,14 +1,31 @@
import re
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):
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<error>\w+Error): ?(ERROR: ?)?(?P<message>.*): ?Traceback", message):
description = f"{match.group('error')}: {match.group('message')}"
super().__init__(
title=f"Error: {message}",
title=title,
description=description,
color=discord.Color.red()
)