58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
import re
|
|
|
|
import discord
|
|
|
|
|
|
class BotMessage(discord.Embed):
|
|
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
|
|
)
|
|
image_url = kwargs.pop('image_url', None)
|
|
if image_url:
|
|
super().set_image(url=image_url)
|
|
# Message content before embed
|
|
self.content = kwargs.pop('content', None)
|
|
|
|
|
|
class ErrorMessage(BotMessage):
|
|
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=title,
|
|
description=description,
|
|
color=discord.Color.red()
|
|
)
|
|
|
|
|
|
class NowPlayingMessage(BotMessage):
|
|
def __init__(self, title, url, image_url):
|
|
super().__init__(
|
|
content='Now playing:',
|
|
title=title,
|
|
url=url,
|
|
image_url=image_url,
|
|
color=discord.Color.green()
|
|
)
|
|
|
|
|
|
class QueuedMessage(BotMessage):
|
|
def __init__(self, title, url, image_url):
|
|
super().__init__(
|
|
content='Queued:',
|
|
title=title,
|
|
url=url,
|
|
image_url=image_url,
|
|
color=discord.Color.blue()
|
|
)
|