1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

Refactor all admin command outputs

This commit is contained in:
wlinator 2024-08-14 04:02:47 -04:00
parent 1baa0fa6c8
commit 055c64243c
7 changed files with 96 additions and 43 deletions

View file

@ -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}`",

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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