diff --git a/config/JSON/strings.json b/config/JSON/strings.json index f9cbeb7..bb527bc 100644 --- a/config/JSON/strings.json +++ b/config/JSON/strings.json @@ -1,4 +1,21 @@ { + "admin_award_title": "Awarded Currency", + "admin_award_description": "awarded **${0}** to {1}.", + "admin_blacklist_description": "user `{0}` has been blacklisted from Luminara.", + "admin_blacklist_author": "User Blacklisted", + "admin_blacklist_footer": "There is no process to reinstate a blacklisted user. Appeals are not considered.", + "admin_sql_select_title": "SQL Select Query", + "admin_sql_select_description": "```sql\nSELECT {0}\n```\n```\n{1}\n```", + "admin_sql_select_error_title": "SQL Select Query Error", + "admin_sql_select_error_description": "```sql\nSELECT {0}\n```\n```\n{1}\n```", + "admin_sql_inject_title": "SQL Query Executed", + "admin_sql_inject_description": "```sql\n{0}\n```", + "admin_sql_inject_error_title": "SQL Query Error", + "admin_sql_inject_error_description": "```sql\n{0}\n```\n```\n{1}\n```", + "admin_sync_title": "Sync Successful", + "admin_sync_description": "command tree synced successfully.", + "admin_sync_error_title": "Sync Error", + "admin_sync_error_description": "An error occurred while syncing: {0}", "bet_limit": "❌ | **{0}** you cannot place any bets above **${1}**.", "case_case_field": "Case:", "case_case_field_value": "`{0}`", diff --git a/lib/embed_builder.py b/lib/embed_builder.py index ad9bfc6..1470daa 100644 --- a/lib/embed_builder.py +++ b/lib/embed_builder.py @@ -23,6 +23,7 @@ class EmbedBuilder: timestamp=None, hide_author=False, hide_author_icon=False, + hide_timestamp=False, ): if not hide_author: if not author_text: @@ -50,7 +51,8 @@ class EmbedBuilder: url=author_url, ) embed.set_footer(text=footer_text, icon_url=footer_icon_url) - embed.timestamp = timestamp or datetime.datetime.now() + if not hide_timestamp: + embed.timestamp = timestamp or datetime.datetime.now() if image_url: embed.set_image(url=image_url) @@ -74,6 +76,7 @@ class EmbedBuilder: timestamp=None, hide_author=False, hide_author_icon=False, + hide_timestamp=False, ): return EmbedBuilder.create_embed( ctx, @@ -91,6 +94,7 @@ class EmbedBuilder: timestamp=timestamp, hide_author=hide_author, hide_author_icon=hide_author_icon, + hide_timestamp=hide_timestamp, ) @staticmethod @@ -108,6 +112,7 @@ class EmbedBuilder: timestamp=None, hide_author=False, hide_author_icon=False, + hide_timestamp=False, ): return EmbedBuilder.create_embed( ctx, @@ -125,6 +130,7 @@ class EmbedBuilder: timestamp=timestamp, hide_author=hide_author, hide_author_icon=hide_author_icon, + hide_timestamp=hide_timestamp, ) @staticmethod @@ -142,6 +148,7 @@ class EmbedBuilder: timestamp=None, hide_author=False, hide_author_icon=False, + hide_timestamp=False, ): return EmbedBuilder.create_embed( ctx, @@ -159,6 +166,7 @@ class EmbedBuilder: timestamp=timestamp, hide_author=hide_author, hide_author_icon=hide_author_icon, + hide_timestamp=hide_timestamp, ) @staticmethod @@ -176,6 +184,7 @@ class EmbedBuilder: timestamp=None, hide_author=False, hide_author_icon=False, + hide_timestamp=False, ): return EmbedBuilder.create_embed( ctx, @@ -193,4 +202,5 @@ class EmbedBuilder: timestamp=timestamp, hide_author=hide_author, hide_author_icon=hide_author_icon, + hide_timestamp=hide_timestamp, ) diff --git a/modules/admin/award.py b/modules/admin/award.py index 6f6c23d..979afab 100644 --- a/modules/admin/award.py +++ b/modules/admin/award.py @@ -1,5 +1,6 @@ import discord - +from lib.constants import CONST +from lib.embed_builder import EmbedBuilder from services.currency_service import Currency @@ -9,9 +10,13 @@ async def cmd(ctx, user: discord.User, amount: int): curr.add_balance(amount) curr.push() - embed = discord.Embed( - color=discord.Color.green(), - description=f"Awarded **${Currency.format(amount)}** to {user.name}.", + embed = EmbedBuilder.create_success_embed( + ctx, + author_text=CONST.STRINGS["admin_award_title"], + description=CONST.STRINGS["admin_award_description"].format( + Currency.format(amount), + user.name, + ), ) await ctx.respond(embed=embed) diff --git a/modules/admin/blacklist.py b/modules/admin/blacklist.py index e3c3537..7333491 100644 --- a/modules/admin/blacklist.py +++ b/modules/admin/blacklist.py @@ -1,13 +1,9 @@ from typing import Optional import discord - -from config.parser import JsonCache +from lib.constants import CONST from services.blacklist_service import BlacklistUserService - -resources = JsonCache.read_json("art") -exclaim_icon = resources["icons"]["exclaim"] -hammer_icon = resources["icons"]["hammer"] +from lib.embed_builder import EmbedBuilder async def blacklist_user( @@ -15,24 +11,15 @@ async def blacklist_user( user: discord.User, reason: Optional[str] = None, ) -> None: - """ - Blacklists a user with an optional reason. - - Args: - user_id (int): The ID of the user to blacklist. - reason (str, optional): The reason for blacklisting the user. Defaults to "No reason was given". - """ blacklist_service = BlacklistUserService(user.id) blacklist_service.add_to_blacklist(reason) - embed = discord.Embed( - description=f"User `{user.name}` has been blacklisted from Luminara.", - color=discord.Color.red(), - ) - embed.set_author(name="User Blacklisted", icon_url=hammer_icon) - embed.set_footer( - text="There is no process to reinstate a blacklisted user. Appeals are not considered.", - icon_url=exclaim_icon, + embed = EmbedBuilder.create_success_embed( + ctx, + author_text=CONST.STRINGS["admin_blacklist_author"], + description=CONST.STRINGS["admin_blacklist_description"].format(user.name), + footer_text=CONST.STRINGS["admin_blacklist_footer"], + hide_timestamp=True, ) await ctx.send(embed=embed) diff --git a/modules/admin/sql.py b/modules/admin/sql.py index f24f295..f1f179a 100644 --- a/modules/admin/sql.py +++ b/modules/admin/sql.py @@ -1,4 +1,7 @@ -import sqlite3 +import mysql.connector +from lib.constants import CONST +from lib.embed_builder import EmbedBuilder +from lib.formatter import shorten from db import database @@ -9,21 +12,49 @@ async def select_cmd(ctx, query: str): try: results = database.select_query(f"SELECT {query}") - except sqlite3.Error as error: - results = error + embed = EmbedBuilder.create_success_embed( + ctx, + author_text=CONST.STRINGS["admin_sql_select_title"], + description=CONST.STRINGS["admin_sql_select_description"].format( + shorten(query, 200), + shorten(str(results), 200), + ), + show_name=False, + ) + except mysql.connector.Error as error: + embed = EmbedBuilder.create_error_embed( + ctx, + author_text=CONST.STRINGS["admin_sql_select_error_title"], + description=CONST.STRINGS["admin_sql_select_error_description"].format( + shorten(query, 200), + shorten(str(error), 200), + ), + show_name=False, + ) - return await ctx.respond( - content=f"```SELECT {query}```\n```{results}```", - ephemeral=True, - ) + return await ctx.respond(embed=embed, ephemeral=True) async def inject_cmd(ctx, query: str): try: database.execute_query(query) - await ctx.respond(content=f"That worked!\n```{query}```", ephemeral=True) - except sqlite3.Error as error: - await ctx.respond( - content=f"Query:\n```{query}```\nError message:\n```{error}```", - ephemeral=True, + embed = EmbedBuilder.create_success_embed( + ctx, + author_text=CONST.STRINGS["admin_sql_inject_title"], + description=CONST.STRINGS["admin_sql_inject_description"].format( + shorten(query, 200), + ), + show_name=False, ) + except mysql.connector.Error as error: + embed = EmbedBuilder.create_error_embed( + ctx, + author_text=CONST.STRINGS["admin_sql_inject_error_title"], + description=CONST.STRINGS["admin_sql_inject_error_description"].format( + shorten(query, 200), + shorten(str(error), 200), + ), + show_name=False, + ) + + await ctx.respond(embed=embed, ephemeral=True) diff --git a/modules/admin/sync.py b/modules/admin/sync.py index 3436ba2..0b722fd 100644 --- a/modules/admin/sync.py +++ b/modules/admin/sync.py @@ -1,6 +1,7 @@ import discord from lib.embed_builder import EmbedBuilder from lib.exceptions.LumiExceptions import LumiException +from lib.constants import CONST async def sync_commands(client, ctx): @@ -8,9 +9,11 @@ async def sync_commands(client, ctx): await client.sync_commands() embed = EmbedBuilder.create_success_embed( ctx, - author_text="Sync Successful", - description="command tree synced successfully.", + author_text=CONST.STRINGS["admin_sync_title"], + description=CONST.STRINGS["admin_sync_description"], ) await ctx.send(embed=embed) except discord.HTTPException as e: - raise LumiException(f"An error occurred while syncing: {e}") from e + raise LumiException( + CONST.STRINGS["admin_sync_error_description"].format(e), + ) from e diff --git a/modules/triggers/add.py b/modules/triggers/add.py index e8e0cf5..4a34ffc 100644 --- a/modules/triggers/add.py +++ b/modules/triggers/add.py @@ -58,10 +58,10 @@ async def add_reaction( is_emoji, is_full_match, ) - await ctx.respond(embed=embed) else: embed = create_failure_embed(trigger_text, is_emoji) - await ctx.respond(embed=embed) + + await ctx.respond(embed=embed) async def check_reaction_limit(