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:
commit
550f36652b
|
@ -9,7 +9,8 @@
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "src/bot.py",
|
"program": "src/bot.py",
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pytest",
|
"name": "pytest",
|
||||||
|
|
|
@ -33,4 +33,4 @@ toml==0.10.2
|
||||||
typing-extensions==3.10.0.2
|
typing-extensions==3.10.0.2
|
||||||
wrapt==1.12.1
|
wrapt==1.12.1
|
||||||
yarl==1.6.3
|
yarl==1.6.3
|
||||||
youtube-dl==2021.6.6
|
youtube-dl==2021.12.17
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
@ -27,8 +28,11 @@ class ErrorHandler(commands.Cog):
|
||||||
else:
|
else:
|
||||||
message = "Oh no! Something went wrong while running the command!"
|
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)
|
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)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,31 @@
|
||||||
|
import re
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
|
||||||
class BotMessage(discord.Embed):
|
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):
|
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__(
|
super().__init__(
|
||||||
title=f"Error: {message}",
|
title=title,
|
||||||
|
description=description,
|
||||||
color=discord.Color.red()
|
color=discord.Color.red()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue