diff --git a/tux/bot.py b/tux/bot.py index f74cea74d..4581f61b3 100644 --- a/tux/bot.py +++ b/tux/bot.py @@ -6,7 +6,6 @@ from tux.cog_loader import CogLoader from tux.database.client import db -from tux.help import TuxHelp class Tux(commands.Bot): @@ -14,7 +13,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self.setup_task = asyncio.create_task(self.setup()) self.is_shutting_down = False - self.help_command = TuxHelp() async def setup(self) -> None: """ diff --git a/tux/cogs/admin/eval.py b/tux/cogs/admin/eval.py index fd06347cf..a2086f043 100644 --- a/tux/cogs/admin/eval.py +++ b/tux/cogs/admin/eval.py @@ -5,8 +5,8 @@ from loguru import logger from tux.bot import Tux +from tux.ui.embeds import EmbedCreator from tux.utils import checks -from tux.utils.embeds import EmbedCreator def insert_returns(body: list[ast.stmt]) -> None: @@ -108,26 +108,27 @@ async def eval(self, ctx: commands.Context[Tux], *, cmd: str) -> None: # Evaluate the function evaluated = await eval(f"{fn_name}()", env) - embed = EmbedCreator.create_success_embed( - title="Success!", + embed = EmbedCreator.create_embed( + EmbedCreator.SUCCESS, + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description=f"```py\n{evaluated}```", - ctx=ctx, ) - + await ctx.reply(embed=embed, ephemeral=True, delete_after=30) logger.info(f"{ctx.author} ran an expression: {cmd}") except Exception as error: - embed = EmbedCreator.create_error_embed( - title="Error!", + embed = EmbedCreator.create_embed( + EmbedCreator.ERROR, + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description=f"```py\n{error}```", - ctx=ctx, ) - + await ctx.reply(embed=embed, ephemeral=True, delete_after=30) logger.error(f"An error occurred while running an expression: {error}") - else: - await ctx.send(embed=embed, ephemeral=True, delete_after=30) - async def setup(bot: Tux) -> None: await bot.add_cog(Eval(bot)) diff --git a/tux/cogs/admin/git.py b/tux/cogs/admin/git.py index 9ce8ede97..e87d85be5 100644 --- a/tux/cogs/admin/git.py +++ b/tux/cogs/admin/git.py @@ -1,400 +1,15 @@ -# import discord -# from discord import app_commands -# from discord.ext import commands -# from githubkit.versions.latest.models import Issue -# from loguru import logger - - -# from tux.wrappers.github import GitHubService -# from tux.utils.constants import Constants as CONST -# from tux.utils.embeds import EmbedCreator - - -# class LinkButton(discord.ui.View): -# def __init__(self, url: str) -> None: -# super().__init__() -# self.add_item( -# discord.ui.Button(style=discord.ButtonStyle.link, label="View on Github", url=url), -# ) - - -# class Git(commands.Cog): -# def __init__(self, bot: Tux) -> None: -# self.bot = bot -# self.github = GitHubService() -# self.repo_url = CONST.GITHUB_REPO_URL - -# git = app_commands.Group(name="git", description="Github commands.") - -# async def create_error_embed(self, interaction: discord.Interaction, error: str) -> None: -# """ -# Create an error embed and send it as a followup message for all commands. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation -# error : str -# The error message to display. -# """ - -# embed = EmbedCreator.create_error_embed( -# title="Uh oh!", -# description=error, -# interaction=interaction, -# ) - -# await interaction.followup.send(embed=embed) - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_repo") -# async def get_repo(self, interaction: discord.Interaction) -> None: -# """ -# Get repository information. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# """ - -# await interaction.response.defer() - -# try: -# repo = await self.github.get_repo() - -# embed = EmbedCreator.create_info_embed( -# title="Tux", -# description="", -# interaction=interaction, -# ) -# embed.add_field(name="Description", value=repo.description, inline=False) -# embed.add_field(name="Stars", value=repo.stargazers_count) -# embed.add_field(name="Forks", value=repo.forks_count) -# embed.add_field(name="Open Issues", value=repo.open_issues_count) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching repository: {e}") -# logger.error(f"Error fetching repository: {e}") - -# else: -# await interaction.followup.send(embed=embed, view=LinkButton(repo.html_url)) -# logger.info(f"{interaction.user} fetched repository information.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="create_issue") -# async def create_issue(self, interaction: discord.Interaction, title: str, body: str) -> None: -# """ -# Create an issue. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# title : str -# The title of the issue. -# body : str -# The body of the issue. -# """ - -# await interaction.response.defer() - -# try: -# created_issue = await self.github.create_issue(title, body) - -# embed = EmbedCreator.create_success_embed( -# title="Issue Created", -# description="The issue has been created successfully.", -# interaction=interaction, -# ) -# embed.add_field(name="Issue Number", value=created_issue.number, inline=False) -# embed.add_field(name="Title", value=title) -# embed.add_field(name="Body", value=body) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error creating issue: {e}") -# logger.error(f"Error creating issue: {e}") - -# else: -# await interaction.followup.send(embed=embed, view=LinkButton(created_issue.html_url)) -# logger.info(f"{interaction.user} created an issue.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="close_issue", description="Close an issue.") -# async def close_issue(self, interaction: discord.Interaction, issue_number: int) -> None: -# """ -# Close an issue. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# issue_number : int -# The number of the issue to close. -# """ - -# await interaction.response.defer() - -# try: -# closed_issue = await self.github.close_issue(issue_number) - -# embed = EmbedCreator.create_success_embed( -# title="Issue Closed", -# description="The issue has been closed successfully.", -# interaction=interaction, -# ) -# embed.add_field(name="Issue Number", value=issue_number) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error closing issue: {e}") -# logger.error(f"Error closing issue: {e}") - -# else: -# await interaction.followup.send(embed=embed, view=LinkButton(closed_issue.html_url)) -# logger.info(f"{interaction.user} closed an issue.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_issue", description="Get an issue.") -# async def get_issue(self, interaction: discord.Interaction, issue_number: int) -> None: -# """ -# Get an issue. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# issue_number : int -# The number of the issue to retrieve. -# """ - -# await interaction.response.defer() - -# try: -# issue = await self.github.get_issue(issue_number) - -# embed = EmbedCreator.create_info_embed( -# title=issue.title, -# description=str(issue.body) if issue.body is not None else "", -# interaction=interaction, -# ) -# embed.add_field(name="State", value=issue.state) -# embed.add_field(name="Number", value=issue.number) -# embed.add_field(name="User", value=issue.user.login if issue.user else "Unknown") -# embed.add_field(name="Created At", value=issue.created_at) -# embed.add_field(name="Updated At", value=issue.updated_at) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching issue: {e}") -# logger.error(f"Error fetching issue: {e}") - -# else: -# await interaction.followup.send(embed=embed, view=LinkButton(issue.html_url)) -# logger.info(f"{interaction.user} fetched an issue.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_open_issues", description="Get open issues.") -# async def get_open_issues(self, interaction: discord.Interaction) -> None: -# """ -# Get open issues. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# """ - -# await interaction.response.defer() - -# try: -# open_issues: list[Issue] = await self.github.get_open_issues() - -# embed = EmbedCreator.create_info_embed( -# title="Open Issues", -# description="Here are the open issues for the repository.", -# interaction=interaction, -# ) - -# for issue in open_issues[:25]: -# embed.add_field(name=issue.title, value=str(issue.number), inline=False) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching issues: {e}") -# logger.error(f"Error fetching issues: {e}") - -# else: -# await interaction.followup.send( -# embed=embed, -# view=LinkButton(f"{self.repo_url}/issues?q=is%3Aissue+is%3Aopen"), -# ) -# logger.info(f"{interaction.user} fetched open issues.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_closed_issues", description="Get closed issues.") -# async def get_closed_issues(self, interaction: discord.Interaction) -> None: -# """ -# Get closed issues. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# """ - -# await interaction.response.defer() - -# try: -# closed_issues = await self.github.get_closed_issues() - -# embed = EmbedCreator.create_info_embed( -# title="Closed Issues", -# description="Here are the closed issues for the repository.", -# interaction=interaction, -# ) - -# for issue in closed_issues[:25]: -# embed.add_field(name=issue.title, value=str(issue.number), inline=False) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching issues: {e}") -# logger.error(f"Error fetching issues: {e}") - -# else: -# await interaction.followup.send( -# embed=embed, -# view=LinkButton( -# "https://github.com/allthingslinux/tux/issues?q=is%3Aissue+is%3Aclosed", -# ), -# ) -# logger.info(f"{interaction.user} fetched closed issues.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_open_pulls", description="Get open pull requests.") -# async def get_open_pulls(self, interaction: discord.Interaction) -> None: -# """ -# Get open pull requests. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# """ - -# await interaction.response.defer() - -# try: -# open_pulls = await self.github.get_open_pulls() - -# embed = EmbedCreator.create_info_embed( -# title="Open Pull Requests", -# description="Here are the open pull requests for the repository.", -# interaction=interaction, -# ) - -# for pull in open_pulls[:25]: -# embed.add_field(name=pull.title, value=str(pull.number), inline=False) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching pull requests: {e}") -# logger.error(f"Error fetching pull requests: {e}") - -# else: -# await interaction.followup.send( -# embed=embed, -# view=LinkButton("https://github.com/allthingslinux/tux/pulls?q=is%3Aopen+is%3Apr"), -# ) -# logger.info(f"{interaction.user} fetched open pull requests.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_closed_pulls", description="Get closed pull requests.") -# async def get_closed_pulls(self, interaction: discord.Interaction) -> None: -# """ -# Get closed pull requests. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# """ - -# await interaction.response.defer() - -# try: -# closed_pulls = await self.github.get_closed_pulls() - -# embed = EmbedCreator.create_info_embed( -# title="Closed Pull Requests", -# description="Here are the closed pull requests for the repository.", -# interaction=interaction, -# ) - -# for pull in closed_pulls[:25]: -# embed.add_field(name=pull.title, value=str(pull.number), inline=False) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching pull requests: {e}") -# logger.error(f"Error fetching pull requests: {e}") - -# else: -# await interaction.followup.send( -# embed=embed, -# view=LinkButton("https://github.com/allthingslinux/tux/"), -# ) -# logger.info(f"{interaction.user} fetched closed pull requests.") - -# @app_commands.checks.has_any_role("Contributor", "Root", "Admin") -# @git.command(name="get_pull", description="Get a pull request.") -# async def get_pull(self, interaction: discord.Interaction, pull_number: int) -> None: -# """ -# Get a pull request. - -# Parameters -# ---------- -# interaction : discord.Interaction -# The interaction object representing the command invocation. -# pull_number : int -# The number of the pull request to retrieve. -# """ - -# await interaction.response.defer() - -# try: -# pull = await self.github.get_pull(pull_number) - -# embed = EmbedCreator.create_info_embed( -# title=pull.title, -# description=str(pull.body) if pull.body is not None else "", -# interaction=interaction, -# ) -# embed.add_field(name="State", value=pull.state) -# embed.add_field(name="Number", value=pull.number) -# embed.add_field(name="User", value=pull.user.login) -# embed.add_field(name="Created At", value=pull.created_at) -# embed.add_field(name="Updated At", value=pull.updated_at) - -# except Exception as e: -# await self.create_error_embed(interaction, f"Error fetching pull request: {e}") -# logger.error(f"Error fetching pull request: {e}") - -# else: -# await interaction.followup.send(embed=embed, view=LinkButton(pull.html_url)) -# logger.info(f"{interaction.user} fetched a pull request.") - - -# async def setup(bot: Tux) -> None: -# await bot.add_cog(Git(bot)) - -# TODO: Rewrite this cog to use the new hybrid command system. - from discord.ext import commands from loguru import logger from tux.bot import Tux from tux.ui.buttons import GithubButton +from tux.ui.embeds import EmbedCreator from tux.utils import checks from tux.utils.constants import Constants as CONST -from tux.utils.embeds import EmbedCreator from tux.wrappers.github import GithubService +# TODO: Rewrite this cog to use the new hybrid command system. + class Git(commands.Cog): def __init__(self, bot: Tux) -> None: @@ -442,10 +57,13 @@ async def get_repo(self, ctx: commands.Context[Tux]) -> None: try: repo = await self.github.get_repo() - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + EmbedCreator.INFO, + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Tux", description="", - ctx=ctx, ) embed.add_field(name="Description", value=repo.description, inline=False) embed.add_field(name="Stars", value=repo.stargazers_count) @@ -485,10 +103,13 @@ async def create_issue(self, ctx: commands.Context[Tux], title: str, body: str) try: created_issue = await self.github.create_issue(title, body) - embed = EmbedCreator.create_success_embed( + embed = EmbedCreator.create_embed( + EmbedCreator.SUCCESS, + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Issue Created", description="The issue has been created successfully.", - ctx=ctx, ) embed.add_field(name="Issue Number", value=created_issue.number, inline=False) embed.add_field(name="Title", value=title, inline=False) @@ -524,10 +145,13 @@ async def get_issue(self, ctx: commands.Context[Tux], issue_number: int) -> None try: issue = await self.github.get_issue(issue_number) - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + EmbedCreator.INFO, + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title=issue.title, description=str(issue.body) if issue.body is not None else "", - ctx=ctx, ) embed.add_field(name="State", value=issue.state, inline=False) embed.add_field(name="Number", value=issue.number, inline=False) diff --git a/tux/cogs/fun/fact.py b/tux/cogs/fun/fact.py index ea1f95cb7..8c635dc52 100644 --- a/tux/cogs/fun/fact.py +++ b/tux/cogs/fun/fact.py @@ -3,7 +3,7 @@ from discord.ext import commands from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class Fact(commands.Cog): @@ -46,10 +46,13 @@ async def fact(self, ctx: commands.Context[Tux]) -> None: ctx : commands.Context[Tux] The context object for the command. """ - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Fun Fact", description=random.choice(self.facts), - ctx=ctx, ) # set author diff --git a/tux/cogs/fun/imgeffect.py b/tux/cogs/fun/imgeffect.py index f3bfac323..fe6353894 100644 --- a/tux/cogs/fun/imgeffect.py +++ b/tux/cogs/fun/imgeffect.py @@ -8,7 +8,7 @@ from PIL import Image, ImageEnhance, ImageOps from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class ImgEffect(commands.Cog): @@ -43,10 +43,13 @@ async def deepfry(self, interaction: discord.Interaction, image: discord.Attachm if image.content_type not in self.allowed_mimetypes: logger.error("The file is not a permitted image.") - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title="Invalid File", description="The file must be an image. Allowed types are PNG, JPEG, and JPG.", - interaction=interaction, ) await interaction.response.send_message(embed=embed, ephemeral=True) diff --git a/tux/cogs/fun/random.py b/tux/cogs/fun/random.py index 561800fec..441cb091c 100644 --- a/tux/cogs/fun/random.py +++ b/tux/cogs/fun/random.py @@ -3,7 +3,7 @@ from discord.ext import commands from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class Random(commands.Cog): @@ -174,10 +174,13 @@ async def dice(self, ctx: commands.Context[Tux], sides: int = 6) -> None: await ctx.send(content="The dice must have at least 2 sides.", ephemeral=True, delete_after=30) return - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title=f"Dice Roll (D{sides})", description=f"You rolled a {random.randint(1, sides)}!", - ctx=ctx, ) await ctx.send(embed=embed) diff --git a/tux/cogs/fun/xkcd.py b/tux/cogs/fun/xkcd.py index 460cdf902..5d8740f9d 100644 --- a/tux/cogs/fun/xkcd.py +++ b/tux/cogs/fun/xkcd.py @@ -4,7 +4,7 @@ from tux.bot import Tux from tux.ui.buttons import XkcdButtons -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator from tux.wrappers import xkcd @@ -123,7 +123,9 @@ async def get_comic_and_embed( else: comic = self.client.get_random_comic(raw_comic_image=True) - embed = EmbedCreator.create_success_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, title="", description=f"\n\n> {comic.description.strip()}" if comic.description else "", ) @@ -134,8 +136,9 @@ async def get_comic_and_embed( except xkcd.HttpError: logger.error("HTTP error occurred while fetching xkcd comic") - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, description="I couldn't find the xkcd comic. Please try again later.", ) ephemeral = True @@ -143,8 +146,9 @@ async def get_comic_and_embed( except Exception as e: logger.error(f"Error getting xkcd comic: {e}") - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, description="An error occurred while fetching the xkcd comic", ) ephemeral = True diff --git a/tux/cogs/guild/config.py b/tux/cogs/guild/config.py index 1a74490be..d3a9fe176 100644 --- a/tux/cogs/guild/config.py +++ b/tux/cogs/guild/config.py @@ -6,9 +6,9 @@ from tux.bot import Tux from tux.database.controllers import DatabaseController +from tux.ui.embeds import EmbedCreator from tux.ui.views.config import ConfigSetChannels, ConfigSetPrivateLogs, ConfigSetPublicLogs from tux.utils.constants import CONST -from tux.utils.embeds import EmbedCreator # TODO: Add onboarding setup to ensure all required channels, logs, and roles are set up # TODO: Figure out how to handle using our custom checks because the current checks would result in a lock out @@ -339,10 +339,13 @@ async def config_set_prefix( await self.db.update_guild_prefix(interaction.guild.id, prefix) await interaction.response.send_message( - embed=EmbedCreator.create_success_embed( + embed=EmbedCreator.create_embed( + bot=self.bot, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, + embed_type=EmbedCreator.SUCCESS, title="Guild Config", description=f"The prefix was updated to `{prefix}`", - interaction=interaction, ), ) @@ -367,10 +370,13 @@ async def config_clear_prefix( await self.db.delete_guild_prefix(interaction.guild.id) await interaction.response.send_message( - embed=EmbedCreator.create_success_embed( + embed=EmbedCreator.create_embed( + bot=self.bot, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, + embed_type=EmbedCreator.SUCCESS, title="Guild Config", description=f"The prefix was reset to `{CONST.DEFAULT_PREFIX}`", - interaction=interaction, ), ) diff --git a/tux/cogs/guild/export.py b/tux/cogs/guild/export.py index c8200fb37..5ede478c3 100644 --- a/tux/cogs/guild/export.py +++ b/tux/cogs/guild/export.py @@ -3,8 +3,8 @@ from discord.ext import commands from tux.bot import Tux +from tux.ui.embeds import EmbedCreator from tux.utils import checks, exports -from tux.utils.embeds import EmbedCreator class Export(commands.Cog): @@ -38,7 +38,11 @@ async def export_banned( valid_flags = ["user", "display", "id", "reason", "mention", "created"] if not bans: - embed = EmbedCreator.create_success_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title=f"{interaction.guild} Banned Users", description="There are no banned users in this server.", ) diff --git a/tux/cogs/guild/rolecount.py b/tux/cogs/guild/rolecount.py index 88b82c689..121273d50 100644 --- a/tux/cogs/guild/rolecount.py +++ b/tux/cogs/guild/rolecount.py @@ -4,7 +4,7 @@ from reactionmenu import ViewButton, ViewMenu from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator des_ids = [ [1175177565086953523, "_kde"], @@ -316,10 +316,13 @@ def _create_embed( The created embed. """ - return EmbedCreator.create_info_embed( + return EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title=f"{which.name} Roles", description="Number of users in each role", - interaction=interaction, ) async def _send_response( diff --git a/tux/cogs/info/membercount.py b/tux/cogs/info/membercount.py index 44f3614e2..d705c5c50 100644 --- a/tux/cogs/info/membercount.py +++ b/tux/cogs/info/membercount.py @@ -3,7 +3,7 @@ from discord.ext import commands from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class MemberCount(commands.Cog): @@ -33,10 +33,13 @@ async def membercount(self, interaction: discord.Interaction) -> None: staff_role = discord.utils.get(interaction.guild.roles, name="%wheel") staff = len(staff_role.members) if staff_role else 0 - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title="Member Count", description="Here is the member count for the server.", - interaction=interaction, ) embed.add_field(name="Members", value=str(members), inline=False) diff --git a/tux/cogs/moderation/__init__.py b/tux/cogs/moderation/__init__.py index 5076d8fde..bd28cec10 100644 --- a/tux/cogs/moderation/__init__.py +++ b/tux/cogs/moderation/__init__.py @@ -7,8 +7,8 @@ from prisma.enums import CaseType from tux.bot import Tux from tux.database.controllers import DatabaseController +from tux.ui.embeds import EmbedCreator from tux.utils.constants import Constants as CONST -from tux.utils.embeds import create_embed_footer, create_error_embed class ModerationCogBase(commands.Cog): @@ -55,7 +55,11 @@ def create_embed( embed.set_author(name=title, icon_url=icon_url) embed.set_thumbnail(url=thumbnail_url) - footer_text, footer_icon_url = create_embed_footer(ctx) + footer_text, footer_icon_url = EmbedCreator.get_footer( + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + ) embed.set_footer(text=footer_text, icon_url=footer_icon_url) for name, value, inline in fields: @@ -155,17 +159,38 @@ async def check_conditions( assert ctx.guild if user == ctx.author: - embed = create_error_embed(f"You cannot {action} yourself.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + title="You cannot self-moderate", + description=f"You cannot {action} yourself.", + ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) return False if isinstance(moderator, discord.Member) and user.top_role >= moderator.top_role: - embed = create_error_embed(f"You cannot {action} a user with a higher or equal role.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + title="You cannot self-moderate", + description=f"You cannot {action} a user with a higher or equal role.", + ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) return False if user == ctx.guild.owner: - embed = create_error_embed(f"You cannot {action} the server owner.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + title="You cannot self-moderate", + description=f"You cannot {action} the server owner.", + ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) return False diff --git a/tux/cogs/moderation/cases.py b/tux/cogs/moderation/cases.py index 07c068d05..c797e52fa 100644 --- a/tux/cogs/moderation/cases.py +++ b/tux/cogs/moderation/cases.py @@ -6,9 +6,9 @@ from prisma.models import Case from prisma.types import CaseWhereInput from tux.bot import Tux +from tux.ui.embeds import EmbedCreator from tux.utils import checks from tux.utils.constants import Constants as CONST -from tux.utils.embeds import create_embed_footer from tux.utils.flags import CaseModifyFlags, CasesViewFlags, generate_usage from . import ModerationCogBase @@ -346,7 +346,11 @@ def _create_case_list_embed( if ctx.guild: embed.set_author(name=ctx.guild.name, icon_url=ctx.guild.icon) - footer_text, footer_icon_url = create_embed_footer(ctx) + footer_text, footer_icon_url = EmbedCreator.get_footer( + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + ) embed.set_footer(text=footer_text, icon_url=footer_icon_url) for case in cases: diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 72b8e81df..7e86a8b08 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -5,8 +5,8 @@ from loguru import logger from tux.bot import Tux +from tux.ui.embeds import EmbedCreator from tux.utils.constants import Constants as CONST -from tux.utils.embeds import EmbedCreator class Bookmarks(commands.Cog): @@ -54,7 +54,9 @@ def _create_bookmark_embed( if len(message.content) > CONST.EMBED_MAX_DESC_LENGTH: message.content = f"{message.content[:CONST.EMBED_MAX_DESC_LENGTH - 3]}..." - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, title="Message Bookmarked", description=f"> {message.content}", ) diff --git a/tux/cogs/services/starboard.py b/tux/cogs/services/starboard.py index a6b7588c3..7d05c27a9 100644 --- a/tux/cogs/services/starboard.py +++ b/tux/cogs/services/starboard.py @@ -6,8 +6,8 @@ from tux.bot import Tux from tux.database.controllers.starboard import StarboardController, StarboardMessageController +from tux.ui.embeds import EmbedCreator from tux.utils import checks -from tux.utils.embeds import EmbedCreator class Starboard(commands.Cog): @@ -57,30 +57,39 @@ async def setup_starboard( if len(emoji) != 1 or not emoji.isprintable(): await ctx.send( - embed=EmbedCreator.create_error_embed( + embed=EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Invalid Emoji", description="Please use a single default Discord emoji.", - ctx=ctx, ), ) return if threshold < 1: await ctx.send( - embed=EmbedCreator.create_error_embed( + embed=EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Invalid Threshold", description="Threshold must be at least 1.", - ctx=ctx, ), ) return if not channel.permissions_for(ctx.guild.me).send_messages: await ctx.send( - embed=EmbedCreator.create_error_embed( + embed=EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Permission Denied", description=f"I don't have permission to send messages in {channel.mention}.", - ctx=ctx, ), ) return @@ -88,10 +97,13 @@ async def setup_starboard( try: await self.starboard_controller.create_or_update_starboard(ctx.guild.id, channel.id, emoji, threshold) - embed = EmbedCreator.create_success_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Starboard Setup", description="Starboard configured successfully.", - ctx=ctx, ) embed.add_field(name="Channel", value=channel.mention) embed.add_field(name="Emoji", value=emoji) @@ -120,16 +132,22 @@ async def remove_starboard(self, ctx: commands.Context[Tux]) -> None: result = await self.starboard_controller.delete_starboard_by_guild_id(ctx.guild.id) embed = ( - EmbedCreator.create_success_embed( + EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Starboard Removed", description="Starboard configuration removed successfully.", - ctx=ctx, ) if result - else EmbedCreator.create_error_embed( + else EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="No Starboard Found", description="No starboard configuration found for this server.", - ctx=ctx, ) ) diff --git a/tux/cogs/utility/ping.py b/tux/cogs/utility/ping.py index a04324031..a3e62ca49 100644 --- a/tux/cogs/utility/ping.py +++ b/tux/cogs/utility/ping.py @@ -2,7 +2,7 @@ from discord.ext import commands from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class Ping(commands.Cog): @@ -38,10 +38,13 @@ async def ping(self, ctx: commands.Context[Tux]) -> None: else: ram_amount_formatted = f"{round(ram_amount_in_mb)}MB" - embed = EmbedCreator.create_success_embed( + embed = EmbedCreator.create_embed( + embed_type=EmbedCreator.INFO, + bot=self.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Pong!", description="Here are some stats about the bot.", - ctx=ctx, ) embed.add_field(name="API Latency", value=f"{discord_ping}ms", inline=True) diff --git a/tux/cogs/utility/poll.py b/tux/cogs/utility/poll.py index 68c73188f..119d53e4b 100644 --- a/tux/cogs/utility/poll.py +++ b/tux/cogs/utility/poll.py @@ -4,7 +4,7 @@ from loguru import logger from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator # TODO: Create option inputs for the poll command instead of using a comma separated string @@ -74,10 +74,13 @@ async def poll(self, interaction: discord.Interaction, title: str, options: str) # Check if the options count is between 2-9 if len(options_list) < 2 or len(options_list) > 9: - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title="Invalid options count", description=f"Poll options count needs to be between 2-9, you provided {len(options_list)} options.", - interaction=interaction, ) await interaction.response.send_message(embed=embed, ephemeral=True, delete_after=30) @@ -88,10 +91,13 @@ async def poll(self, interaction: discord.Interaction, title: str, options: str) [f"{num + 1}\u20e3 {option}" for num, option in enumerate(options_list)], ) - embed = EmbedCreator.create_poll_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.POLL, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title=title, description=description, - interaction=interaction, ) await interaction.response.send_message(embed=embed) diff --git a/tux/cogs/utility/query.py b/tux/cogs/utility/query.py index a31f391a1..f84164dde 100644 --- a/tux/cogs/utility/query.py +++ b/tux/cogs/utility/query.py @@ -1,11 +1,10 @@ -import discord import httpx from discord.ext import commands from loguru import logger from tux.bot import Tux +from tux.ui.embeds import EmbedCreator from tux.utils.constants import Constants as CONST -from tux.utils.embeds import EmbedCreator class Query(commands.Cog): @@ -42,10 +41,12 @@ async def query(self, ctx: commands.Context[Tux], *, search_term: str) -> None: # Check if the request was successful if response.status_code != 200: - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="An error occurred while processing your request. (DDG Provided a non-200 status code)", - ctx=ctx, ) return @@ -78,28 +79,34 @@ async def query(self, ctx: commands.Context[Tux], *, search_term: str) -> None: logger.info(f"GET request to http://api.duckduckgo.com/ with params {params}") if response.status_code != 200: - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="An error occurred while processing your request. (DDG Provided a non-200 status code)", - ctx=ctx, ) return data = response.json() else: - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="No results found for the search term.", - ctx=ctx, ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return - embed = discord.Embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title=f'Answer to "{search_term}"', description=f"{data['Abstract']}\n\nData from **{data['AbstractURL']}**", - color=CONST.EMBED_COLORS["INFO"], - timestamp=EmbedCreator.get_timestamp(ctx, None), ) embed.set_author( diff --git a/tux/cogs/utility/remindme.py b/tux/cogs/utility/remindme.py index 794f71c07..6c84c74cf 100644 --- a/tux/cogs/utility/remindme.py +++ b/tux/cogs/utility/remindme.py @@ -10,7 +10,7 @@ from prisma.models import Reminder from tux.bot import Tux from tux.database.controllers import DatabaseController -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator from tux.utils.functions import convert_to_seconds @@ -51,14 +51,13 @@ async def send_reminders(self, reminder: Reminder) -> None: user = self.bot.get_user(reminder.reminder_user_id) if user is not None: - embed = EmbedCreator.custom_footer_embed( - ctx=None, - interaction=None, - state="SUCCESS", - user=user, - latency="N/A", - content=reminder.reminder_content, + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=user.name, + user_display_avatar=user.display_avatar.url, title="Reminder", + description=reminder.reminder_content, ) try: @@ -181,10 +180,13 @@ async def remindme(self, interaction: discord.Interaction, time: str, *, reminde guild_id=interaction.guild_id or 0, ) - embed = EmbedCreator.create_success_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.SUCCESS, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title="Reminder Set", description=f"Reminder set for .", - interaction=interaction, ) embed.add_field( @@ -193,10 +195,12 @@ async def remindme(self, interaction: discord.Interaction, time: str, *, reminde ) except Exception as e: - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, description="There was an error creating the reminder.", - interaction=interaction, ) logger.error(f"Error creating reminder: {e}") diff --git a/tux/cogs/utility/run.py b/tux/cogs/utility/run.py index 2bb83c9d6..89b30980b 100644 --- a/tux/cogs/utility/run.py +++ b/tux/cogs/utility/run.py @@ -3,7 +3,7 @@ from discord.ext import commands from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator from tux.wrappers import godbolt ansi_re = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])") @@ -109,10 +109,13 @@ async def generalized_code_executor( cleaned_code = "\n".join(cleaned_code.splitlines()[1:]) if normalized_lang not in compiler_map: - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Fatal exception occurred!", description="Bad Formatting", - ctx=ctx, ) await ctx.send(embed=embed) return ("", "", "") @@ -121,10 +124,13 @@ async def generalized_code_executor( output = godbolt.getoutput(cleaned_code, compiler_id, options) if output is None: - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Fatal exception occurred!", description="failed to get output from the compiler", - ctx=ctx, ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) return ("", "", "") @@ -167,10 +173,13 @@ async def generalized_code_constructor( cleaned_code = "\n".join(cleaned_code.splitlines()[1:]) if normalized_lang not in compiler_map: - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Fatal exception occurred!", description="Bad Formatting", - ctx=ctx, ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) return ("", "", "") @@ -179,10 +188,13 @@ async def generalized_code_constructor( output = godbolt.generateasm(cleaned_code, compiler_id, options) if output is None: - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Fatal exception occurred!", description="failed to get output from the compiler", - ctx=ctx, ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) return ("", "", "") @@ -222,10 +234,13 @@ async def send_embedded_reply( The language of the code. """ - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Compilation provided by https://godbolt.org/", description=f"```{lang}\n{output}\n```", - ctx=ctx, ) await ctx.send(embed=embed) @@ -292,10 +307,13 @@ async def run_error( if isinstance(error, commands.MissingRequiredArgument): desc = f"Missing required argument: `{error.param.name}`" - embed = EmbedCreator.create_error_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Fatal exception occurred!", description=str(desc), - ctx=ctx, ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) @@ -315,10 +333,13 @@ async def languages(self, ctx: commands.Context[Tux]) -> None: The context in which the command is invoked. """ - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Supported Languages", description=f"```{', '.join(compiler_map.keys())}```", - ctx=ctx, ) await ctx.send(embed=embed) diff --git a/tux/cogs/utility/snippets.py b/tux/cogs/utility/snippets.py index f308381cc..b3d7c12ca 100644 --- a/tux/cogs/utility/snippets.py +++ b/tux/cogs/utility/snippets.py @@ -12,9 +12,9 @@ from prisma.models import Snippet from tux.bot import Tux from tux.database.controllers import CaseController, DatabaseController +from tux.ui.embeds import EmbedCreator from tux.utils import checks from tux.utils.constants import Constants as CONST -from tux.utils.embeds import EmbedCreator, create_embed_footer, create_error_embed class Snippets(commands.Cog): @@ -58,10 +58,12 @@ async def list_snippets(self, ctx: commands.Context[Tux]) -> None: # If there are no snippets, send an error message if not snippets: - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="No snippets found.", - ctx=ctx, ) await ctx.send(embed=embed, delete_after=30) return @@ -96,7 +98,11 @@ def _create_snippets_list_embed( if ctx.guild: embed.set_author(name=ctx.guild.name, icon_url=ctx.guild.icon) - footer_text, footer_icon_url = create_embed_footer(ctx) + footer_text, footer_icon_url = EmbedCreator.get_footer( + bot=ctx.bot, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + ) embed.set_footer(text=footer_text, icon_url=footer_icon_url) embed.timestamp = ctx.message.created_at @@ -134,10 +140,12 @@ async def top_snippets(self, ctx: commands.Context[Tux]) -> None: # If there are no snippets, send an error message if not snippets: - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="No snippets found.", - ctx=ctx, ) await ctx.send(embed=embed, delete_after=30) return @@ -188,14 +196,24 @@ async def delete_snippet(self, ctx: commands.Context[Tux], name: str) -> None: snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id) if snippet is None: - embed = create_error_embed(error="Snippet not found.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return # check if the snippet is locked if snippet.locked: - embed = create_error_embed( - error="This snippet is locked and cannot be deleted. If you are a moderator you can use the `forcedeletesnippet` command.", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="This snippet is locked and cannot be deleted. If you are a moderator you can use the `forcedeletesnippet` command.", ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -203,7 +221,13 @@ async def delete_snippet(self, ctx: commands.Context[Tux], name: str) -> None: # Check if the author of the snippet is the same as the user who wants to delete it and if theres no author don't allow deletion author_id = snippet.snippet_user_id or 0 if author_id != ctx.author.id: - embed = create_error_embed(error="You can only delete your own snippets.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="You can only delete your own snippets.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -236,7 +260,13 @@ async def force_delete_snippet(self, ctx: commands.Context[Tux], name: str) -> N snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id) if snippet is None: - embed = create_error_embed(error="Snippet not found.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -270,13 +300,23 @@ async def get_snippet(self, ctx: commands.Context[Tux], name: str) -> None: if "_" in name: snippet = None # this is a bad fix, but it works for now if snippet is None and "_" in name: - embed = create_error_embed( - error="Snippet not found. Did you mean to use `-` instead of `_`? Due to a recent change, `_` is no longer allowed in snippet names.", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found. Did you mean to use `-` instead of `_`? Due to a recent change, `_` is no longer allowed in snippet names.", ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return if snippet is None: - embed = create_error_embed(error="Snippet not found.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -315,21 +355,24 @@ async def get_snippet_info(self, ctx: commands.Context[Tux], name: str) -> None: snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id) if snippet is None: - embed = create_error_embed(error="Snippet not found.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found.", + ) await ctx.send(embed=embed, delete_after=30) return author = self.bot.get_user(snippet.snippet_user_id) - latency = round(int(ctx.bot.latency * 1000)) - - embed: discord.Embed = EmbedCreator.custom_footer_embed( + embed: discord.Embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.DEFAULT, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title="Snippet Information", - ctx=ctx, - latency=f"{latency}ms", - interaction=None, - state="DEFAULT", - user=author or ctx.author, ) embed.add_field(name="Name", value=snippet.snippet_name, inline=False) @@ -375,7 +418,13 @@ async def create_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: args = arg.split(" ") if len(args) < 2: - embed = create_error_embed(error="Please provide a name and content for the snippet.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Please provide a name and content for the snippet.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -387,7 +436,13 @@ async def create_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: # Check if the snippet already exists if await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id) is not None: - embed = create_error_embed(error="Snippet already exists.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet already exists.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -395,10 +450,13 @@ async def create_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: rules = set(string.ascii_letters + string.digits + "-") if len(name) > 20 or any(char not in rules for char in name): - embed = create_error_embed( - error="Snippet name must be alphanumeric (allows dashes and underscores) and less than 20 characters.", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet name must be alphanumeric (allows dashes and underscores) and less than 20 characters.", ) - await ctx.send(embed=embed) return @@ -435,7 +493,13 @@ async def edit_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: args = arg.split(" ") if len(args) < 2: - embed = create_error_embed(error="Please provide a name and content for the snippet.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Please provide a name and content for the snippet.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -445,7 +509,13 @@ async def edit_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id) if snippet is None: - embed = create_error_embed(error="Snippet not found.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -462,8 +532,12 @@ async def edit_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: try: await checks.has_pl(2).predicate(ctx) except commands.CheckFailure: - embed = create_error_embed( - error="This snippet is locked and cannot be edited. If you are a moderator you can use the `forcedeletesnippet` command.", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="This snippet is locked and cannot be edited. If you are a moderator you can use the `forcedeletesnippet` command.", ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -472,7 +546,13 @@ async def edit_snippet(self, ctx: commands.Context[Tux], *, arg: str) -> None: # Check if the author of the snippet is the same as the user who wants to edit it and if theres no author don't allow editing author_id = snippet.snippet_user_id or 0 if author_id != ctx.author.id: - embed = create_error_embed(error="You can only edit your own snippets.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="You can only edit your own snippets.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return @@ -508,14 +588,26 @@ async def toggle_snippet_lock(self, ctx: commands.Context[Tux], name: str) -> No snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id) if snippet is None: - embed = create_error_embed(error="Snippet not found.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="Snippet not found.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return status = await self.db.toggle_snippet_lock_by_id(snippet.snippet_id) if status is None: - embed = create_error_embed(error="No return value from locking the snippet. It may still have been locked.") + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + description="No return value from locking the snippet. It may still have been locked.", + ) await ctx.send(embed=embed, delete_after=30, ephemeral=True) return diff --git a/tux/cogs/utility/tldr.py b/tux/cogs/utility/tldr.py index 8c5ed7524..5868bb1dd 100644 --- a/tux/cogs/utility/tldr.py +++ b/tux/cogs/utility/tldr.py @@ -5,7 +5,7 @@ from discord.ext import commands from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class Tldr(commands.Cog): @@ -60,10 +60,13 @@ async def slash_tldr(self, interaction: discord.Interaction, command: str) -> No tldr_page = self.get_tldr_page(command) - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title=f"TLDR for {command}", description=tldr_page, - interaction=interaction, ) await interaction.response.send_message(embed=embed) @@ -88,10 +91,13 @@ async def prefix_tldr(self, ctx: commands.Context[Tux], command: str) -> None: tldr_page = self.get_tldr_page(command) - embed = EmbedCreator.create_info_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, title=f"TLDR for {command}", description=tldr_page, - ctx=ctx, ) await ctx.send(embed=embed) diff --git a/tux/cogs/utility/wiki.py b/tux/cogs/utility/wiki.py index bf7afd1a4..c4fd7dddd 100644 --- a/tux/cogs/utility/wiki.py +++ b/tux/cogs/utility/wiki.py @@ -3,7 +3,7 @@ from loguru import logger from tux.bot import Tux -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class Wiki(commands.Cog): @@ -119,14 +119,23 @@ async def arch_wiki(self, ctx: commands.Context[Tux], query: str) -> None: title: tuple[str, str] = self.query_arch_wiki(query) if title[0] == "error": - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="No search results found.", - ctx=ctx, ) else: - embed = EmbedCreator.create_info_embed(title=title[0], description=title[1], ctx=ctx) + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + title=title[0], + description=title[1], + ) await ctx.send(embed=embed) @@ -149,14 +158,23 @@ async def atl_wiki(self, ctx: commands.Context[Tux], query: str) -> None: title: tuple[str, str] = self.query_atl_wiki(query) if title[0] == "error": - embed = EmbedCreator.create_error_embed( - title="Error", + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, description="No search results found.", - ctx=ctx, ) else: - embed = EmbedCreator.create_info_embed(title=title[0], description=title[1], ctx=ctx) + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=ctx.author.name, + user_display_avatar=ctx.author.display_avatar.url, + title=title[0], + description=title[1], + ) await ctx.send(embed=embed) diff --git a/tux/handlers/error.py b/tux/handlers/error.py index 1375253e2..d8132cbce 100644 --- a/tux/handlers/error.py +++ b/tux/handlers/error.py @@ -7,7 +7,7 @@ from loguru import logger from tux.bot import Tux -from tux.utils.embeds import create_error_embed +from tux.ui.embeds import EmbedCreator from tux.utils.exceptions import AppCommandPermissionLevelError, PermissionLevelError """ @@ -170,7 +170,11 @@ async def on_app_command_error( error_message = error_map.get(type(error), self.error_message).format(error=error) - embed = create_error_embed(error_message) + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + description=error_message, + ) if interaction.response.is_done(): await interaction.followup.send(embed=embed, ephemeral=True) @@ -212,7 +216,11 @@ async def on_command_error( if isinstance(error, commands.CheckFailure): message = error_map.get(type(error), self.error_message).format(error=error, ctx=ctx) # await ctx.send(content=message, ephemeral=True, delete_after=30) - embed = create_error_embed(message) + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + description=message, + ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) sentry_sdk.capture_exception(error) return @@ -232,7 +240,11 @@ async def on_command_error( # await ctx.send(content=message, ephemeral=True, delete_after=30) - embed = create_error_embed(message) + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.ERROR, + description=message, + ) await ctx.send(embed=embed, ephemeral=True, delete_after=30) # Log the error traceback if it's not in the error map diff --git a/tux/help.py b/tux/help.py index 3a55fbc33..0bbc9ec1d 100644 --- a/tux/help.py +++ b/tux/help.py @@ -11,8 +11,8 @@ from reactionmenu.abc import Page from reactionmenu.views_menu import ViewSelect +from tux.ui.embeds import EmbedCreator from tux.utils.constants import Constants as CONST -from tux.utils.embeds import EmbedCreator class TuxHelp(commands.HelpCommand): @@ -491,8 +491,10 @@ async def send_error_message(self, error: str) -> None: logger.error(f"An error occurred while sending a help message: {error}") - embed = EmbedCreator.create_error_embed( - title="An error occurred while sending help message.", + embed = EmbedCreator.create_embed( + EmbedCreator.ERROR, + user_name=self.context.author.name, + user_display_avatar=self.context.author.display_avatar.url, description=error, ) diff --git a/tux/main.py b/tux/main.py index d3f7480a0..a7aad94ca 100644 --- a/tux/main.py +++ b/tux/main.py @@ -9,6 +9,7 @@ from tux.bot import Tux from tux.database.controllers.guild_config import GuildConfigController +from tux.help import TuxHelp # from tux.utils.console import Console from tux.utils.constants import Constants as CONST @@ -48,6 +49,7 @@ async def main() -> None: intents=discord.Intents.all(), owner_ids=[*CONST.SYSADMIN_IDS, CONST.BOT_OWNER_ID], allowed_mentions=discord.AllowedMentions(everyone=False), + help_command=TuxHelp(), ) # Initialize the console and console task diff --git a/tux/ui/embeds.py b/tux/ui/embeds.py new file mode 100644 index 000000000..e52852c83 --- /dev/null +++ b/tux/ui/embeds.py @@ -0,0 +1,128 @@ +from datetime import datetime +from enum import Enum + +import discord +from loguru import logger + +from tux.bot import Tux +from tux.utils.constants import Constants as CONST + + +class EmbedType(Enum): + DEFAULT = 1 + INFO = 2 + ERROR = 3 + WARNING = 4 + SUCCESS = 5 + POLL = 6 + CASE = 7 + NOTE = 8 + + +class EmbedCreator: + DEFAULT: EmbedType = EmbedType.DEFAULT + INFO: EmbedType = EmbedType.INFO + ERROR: EmbedType = EmbedType.ERROR + WARNING: EmbedType = EmbedType.WARNING + SUCCESS: EmbedType = EmbedType.SUCCESS + POLL: EmbedType = EmbedType.POLL + CASE: EmbedType = EmbedType.CASE + NOTE: EmbedType = EmbedType.NOTE + + @staticmethod + def create_embed( + embed_type: EmbedType, + bot: Tux | None = None, + title: str | None = None, + description: str | None = None, + user_name: str | None = None, + user_display_avatar: str | None = None, + image_url: str | None = None, + thumbnail_url: str | None = None, + message_timestamp: datetime | None = None, + custom_footer_text: str | None = None, + custom_footer_icon_url: str | None = None, + custom_author_text: str | None = None, + custom_author_icon_url: str | None = None, + custom_color: int | None = None, + ) -> discord.Embed: + """ + Create a customized Discord embed based on the specified type and parameters. + + Args: + embed_type (EmbedType): Determines the default color and icon for the embed. + bot (Tux | None): If provided, used to display bot latency in the footer. + title (str | None): The embed's title. At least one of title or description should be provided. + description (str | None): The embed's main content. At least one of title or description should be provided. + user_name (str | None): Used in footer if provided, otherwise defaults to bot's username. + user_display_avatar (str | None): User's avatar URL for the footer icon. + image_url (str | None): URL for the embed's main image. + thumbnail_url (str | None): URL for the embed's thumbnail image. + message_timestamp (datetime | None): Custom timestamp for the embed. + custom_footer_text (str | None): Overrides default footer text if provided. + custom_footer_icon_url (str | None): Overrides default footer icon if provided. + custom_author_text (str | None): Overrides default author text if provided. + custom_author_icon_url (str | None): Overrides default author icon if provided. + custom_color (int | None): Overrides default color for the embed type if provided. + + Note: + Custom parameters (prefixed with 'custom_') override default values. + """ + try: + embed: discord.Embed = discord.Embed(title=title, description=description) + + type_settings: dict[EmbedType, tuple[int, str, str]] = { + EmbedType.DEFAULT: (CONST.EMBED_COLORS["DEFAULT"], CONST.EMBED_ICONS["DEFAULT"], "Default"), + EmbedType.INFO: (CONST.EMBED_COLORS["INFO"], CONST.EMBED_ICONS["INFO"], "Info"), + EmbedType.ERROR: (CONST.EMBED_COLORS["ERROR"], CONST.EMBED_ICONS["ERROR"], "Error"), + EmbedType.WARNING: (CONST.EMBED_COLORS["WARNING"], CONST.EMBED_ICONS["DEFAULT"], "Warning"), + EmbedType.SUCCESS: (CONST.EMBED_COLORS["SUCCESS"], CONST.EMBED_ICONS["SUCCESS"], "Success"), + EmbedType.POLL: (CONST.EMBED_COLORS["POLL"], CONST.EMBED_ICONS["POLL"], "Poll"), + EmbedType.CASE: (CONST.EMBED_COLORS["CASE"], CONST.EMBED_ICONS["CASE"], "Case"), + EmbedType.NOTE: (CONST.EMBED_COLORS["NOTE"], CONST.EMBED_ICONS["NOTE"], "Note"), + } + + embed.color = custom_color or type_settings[embed_type][0] + + embed.set_author( + name=custom_author_text or type_settings[embed_type][2], + icon_url=custom_author_icon_url or type_settings[embed_type][1], + ) + + if custom_footer_text: + embed.set_footer(text=custom_footer_text, icon_url=custom_footer_icon_url) + else: + footer: tuple[str, str | None] = EmbedCreator.get_footer(bot, user_name, user_display_avatar) + embed.set_footer(text=footer[0], icon_url=footer[1]) + + if image_url: + embed.set_image(url=image_url) + + if thumbnail_url: + embed.set_thumbnail(url=thumbnail_url) + + embed.timestamp = message_timestamp or discord.utils.utcnow() + + except Exception as e: + logger.debug("Error in create_embed", exc_info=e) + raise + + else: + return embed + + @staticmethod + def get_footer( + bot: Tux | None = None, + user_name: str | None = None, + user_display_avatar: str | None = None, + ) -> tuple[str, str | None]: + try: + text: str = f"{user_name}@atl $" if user_name else "tux@atl $" + text += f" {round(bot.latency * 1000)}ms" if bot else "" + + except Exception as e: + logger.debug("Error in get_footer", exc_info=e) + raise + + else: + return (text, user_display_avatar or "https://i.imgur.com/4sblrd0.png") diff --git a/tux/ui/modals/report.py b/tux/ui/modals/report.py index adf207cc5..6a084d29b 100644 --- a/tux/ui/modals/report.py +++ b/tux/ui/modals/report.py @@ -3,7 +3,7 @@ from tux.bot import Tux from tux.database.controllers import DatabaseController -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator class ReportModal(discord.ui.Modal): @@ -42,10 +42,13 @@ async def on_submit(self, interaction: discord.Interaction) -> None: logger.error("Guild is None") return - embed = EmbedCreator.create_log_embed( + embed = EmbedCreator.create_embed( + bot=self.bot, + embed_type=EmbedCreator.INFO, + user_name=interaction.user.name, + user_display_avatar=interaction.user.display_avatar.url, title=(f"Anonymous report for {self.short.value}"), # type: ignore description=self.long.value, # type: ignore - interaction=None, ) try: diff --git a/tux/utils/embeds.py b/tux/utils/embeds.py deleted file mode 100644 index 648fefdc2..000000000 --- a/tux/utils/embeds.py +++ /dev/null @@ -1,247 +0,0 @@ -from datetime import datetime - -import discord -from discord.ext import commands - -from tux.utils.constants import Constants as CONST - -# TODO: Refactor this to reduce code duplication - - -def create_embed_footer( - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - fallback_text: str = "tux@atl $", - fallback_icon_url: str = "https://i.imgur.com/4sblrd0.png", -) -> tuple[str, str | None]: - user: discord.User | discord.Member | None = None - latency = None - if ctx: - user = ctx.author - latency = round(ctx.bot.latency * 1000) - elif interaction: - user = interaction.user - latency = round(interaction.client.latency * 1000) - if isinstance(user, discord.User | discord.Member): - return ( - f"{user.name}@atl $ {latency}ms", - str(user.avatar.url) if user.avatar else fallback_icon_url, - ) - return (fallback_text, fallback_icon_url) - - -@staticmethod -def create_error_embed(error: str) -> discord.Embed: - embed = discord.Embed() - embed.color = CONST.EMBED_COLORS["ERROR"] - embed.description = f"<:tux_error:1273494919897681930> {error}" - return embed - - -class EmbedCreator: - @staticmethod - def get_timestamp( - ctx: commands.Context[commands.Bot] | None, - interaction: discord.Interaction | None, - ) -> datetime: - if ctx and ctx.message: - return ctx.message.created_at - return interaction.created_at if interaction else discord.utils.utcnow() - - @staticmethod - def get_footer( - ctx: commands.Context[commands.Bot] | None, - interaction: discord.Interaction | None, - ) -> tuple[str, str | None]: - user: discord.User | discord.Member | None = None - latency = None - - if ctx: - user = ctx.author - latency = round(ctx.bot.latency * 1000) - elif interaction: - user = interaction.user - latency = round(interaction.client.latency * 1000) - - if isinstance(user, discord.User | discord.Member): - return ( - f"{user.name}@atl $ {latency}ms", - str(user.avatar.url) if user.avatar else None, - ) - - if ctx is None and interaction is None: - return ("tux@atl $", "https://i.imgur.com/4sblrd0.png") - - return ("", None) - - @staticmethod - def add_author(embed: discord.Embed, name: str, icon_url: str) -> None: - embed.set_author(name=name, icon_url=icon_url) - - @staticmethod - def add_field(embed: discord.Embed, name: str, value: str, inline: bool = True) -> None: - embed.add_field(name=name, value=value, inline=inline) - - @staticmethod - def base_embed( - ctx: commands.Context[commands.Bot] | None, - interaction: discord.Interaction | None, - state: str, - ) -> discord.Embed: - footer: tuple[str, str | None] = EmbedCreator.get_footer(ctx, interaction) - timestamp: datetime = EmbedCreator.get_timestamp(ctx, interaction) - - embed = discord.Embed() - - embed.color = CONST.EMBED_COLORS[state] - - embed.set_author( - name=state.capitalize() if state else "Info", - icon_url=CONST.EMBED_ICONS[state] if state else CONST.EMBED_ICONS["DEFAULT"], - ) - - embed.set_footer(text=footer[0], icon_url=footer[1]) - - embed.timestamp = timestamp - - return embed - - # requests a custom user and latency for the footer - @staticmethod - def custom_footer_embed( - ctx: commands.Context[commands.Bot] | None, - interaction: discord.Interaction | None, - state: str, - user: discord.User | discord.Member, - latency: str, - content: str = "", - title: str = "", - ) -> discord.Embed: - timestamp: datetime = EmbedCreator.get_timestamp(ctx, interaction) - - embed = discord.Embed() - - embed.color = CONST.EMBED_COLORS[state] - - embed.description = content - - embed.title = title - - embed.set_author( - name=state.capitalize() if state else "Info", - icon_url=CONST.EMBED_ICONS[state] if state else CONST.EMBED_ICONS["DEFAULT"], - ) - - embed.set_footer( - text=f"{user.name}@atl $ {latency}", - icon_url=str(user.avatar.url) if user.avatar else None, - ) - - embed.timestamp = timestamp - - return embed - - @classmethod - def create_embed( - cls, - ctx: commands.Context[commands.Bot] | None, - interaction: discord.Interaction | None, - state: str, - title: str, - description: str = "", - ) -> discord.Embed: - embed = cls.base_embed(ctx, interaction, state) - embed.title = title - embed.description = description - - return embed - - @classmethod - def create_default_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "DEFAULT", title, description) - - @classmethod - def create_info_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "INFO", title, description) - - @classmethod - def create_error_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "ERROR", title, description) - - @classmethod - def create_warning_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "WARNING", title, description) - - @classmethod - def create_success_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "SUCCESS", title, description) - - @classmethod - def create_poll_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "POLL", title, description) - - @classmethod - def create_log_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "DEFAULT", title, description) - - @classmethod - def create_infraction_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "INFRACTION", title, description) - - @classmethod - def create_note_embed( - cls, - title: str, - description: str, - ctx: commands.Context[commands.Bot] | None = None, - interaction: discord.Interaction | None = None, - ) -> discord.Embed: - return cls.create_embed(ctx, interaction, "NOTE", title, description) diff --git a/tux/utils/exports.py b/tux/utils/exports.py index c45e70b0b..b02587de6 100644 --- a/tux/utils/exports.py +++ b/tux/utils/exports.py @@ -4,7 +4,7 @@ import discord -from tux.utils.embeds import EmbedCreator +from tux.ui.embeds import EmbedCreator _flags = { "user": "User", @@ -66,7 +66,8 @@ async def get_help_embed( """ valid_flags.sort() - return EmbedCreator.create_info_embed( + return EmbedCreator.create_embed( + embed_type=EmbedCreator.INFO, title=title, description="Use any combination of the following flags to " + f"export a list of {data_description} to a CSV file:"