mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-03 00:03:13 +00:00
Refactor all admin command outputs
This commit is contained in:
parent
1baa0fa6c8
commit
055c64243c
7 changed files with 96 additions and 43 deletions
|
@ -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}**.",
|
"bet_limit": "❌ | **{0}** you cannot place any bets above **${1}**.",
|
||||||
"case_case_field": "Case:",
|
"case_case_field": "Case:",
|
||||||
"case_case_field_value": "`{0}`",
|
"case_case_field_value": "`{0}`",
|
||||||
|
|
|
@ -23,6 +23,7 @@ class EmbedBuilder:
|
||||||
timestamp=None,
|
timestamp=None,
|
||||||
hide_author=False,
|
hide_author=False,
|
||||||
hide_author_icon=False,
|
hide_author_icon=False,
|
||||||
|
hide_timestamp=False,
|
||||||
):
|
):
|
||||||
if not hide_author:
|
if not hide_author:
|
||||||
if not author_text:
|
if not author_text:
|
||||||
|
@ -50,6 +51,7 @@ class EmbedBuilder:
|
||||||
url=author_url,
|
url=author_url,
|
||||||
)
|
)
|
||||||
embed.set_footer(text=footer_text, icon_url=footer_icon_url)
|
embed.set_footer(text=footer_text, icon_url=footer_icon_url)
|
||||||
|
if not hide_timestamp:
|
||||||
embed.timestamp = timestamp or datetime.datetime.now()
|
embed.timestamp = timestamp or datetime.datetime.now()
|
||||||
|
|
||||||
if image_url:
|
if image_url:
|
||||||
|
@ -74,6 +76,7 @@ class EmbedBuilder:
|
||||||
timestamp=None,
|
timestamp=None,
|
||||||
hide_author=False,
|
hide_author=False,
|
||||||
hide_author_icon=False,
|
hide_author_icon=False,
|
||||||
|
hide_timestamp=False,
|
||||||
):
|
):
|
||||||
return EmbedBuilder.create_embed(
|
return EmbedBuilder.create_embed(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -91,6 +94,7 @@ class EmbedBuilder:
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
hide_author=hide_author,
|
hide_author=hide_author,
|
||||||
hide_author_icon=hide_author_icon,
|
hide_author_icon=hide_author_icon,
|
||||||
|
hide_timestamp=hide_timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -108,6 +112,7 @@ class EmbedBuilder:
|
||||||
timestamp=None,
|
timestamp=None,
|
||||||
hide_author=False,
|
hide_author=False,
|
||||||
hide_author_icon=False,
|
hide_author_icon=False,
|
||||||
|
hide_timestamp=False,
|
||||||
):
|
):
|
||||||
return EmbedBuilder.create_embed(
|
return EmbedBuilder.create_embed(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -125,6 +130,7 @@ class EmbedBuilder:
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
hide_author=hide_author,
|
hide_author=hide_author,
|
||||||
hide_author_icon=hide_author_icon,
|
hide_author_icon=hide_author_icon,
|
||||||
|
hide_timestamp=hide_timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -142,6 +148,7 @@ class EmbedBuilder:
|
||||||
timestamp=None,
|
timestamp=None,
|
||||||
hide_author=False,
|
hide_author=False,
|
||||||
hide_author_icon=False,
|
hide_author_icon=False,
|
||||||
|
hide_timestamp=False,
|
||||||
):
|
):
|
||||||
return EmbedBuilder.create_embed(
|
return EmbedBuilder.create_embed(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -159,6 +166,7 @@ class EmbedBuilder:
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
hide_author=hide_author,
|
hide_author=hide_author,
|
||||||
hide_author_icon=hide_author_icon,
|
hide_author_icon=hide_author_icon,
|
||||||
|
hide_timestamp=hide_timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -176,6 +184,7 @@ class EmbedBuilder:
|
||||||
timestamp=None,
|
timestamp=None,
|
||||||
hide_author=False,
|
hide_author=False,
|
||||||
hide_author_icon=False,
|
hide_author_icon=False,
|
||||||
|
hide_timestamp=False,
|
||||||
):
|
):
|
||||||
return EmbedBuilder.create_embed(
|
return EmbedBuilder.create_embed(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -193,4 +202,5 @@ class EmbedBuilder:
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
hide_author=hide_author,
|
hide_author=hide_author,
|
||||||
hide_author_icon=hide_author_icon,
|
hide_author_icon=hide_author_icon,
|
||||||
|
hide_timestamp=hide_timestamp,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import discord
|
import discord
|
||||||
|
from lib.constants import CONST
|
||||||
|
from lib.embed_builder import EmbedBuilder
|
||||||
from services.currency_service import Currency
|
from services.currency_service import Currency
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,9 +10,13 @@ async def cmd(ctx, user: discord.User, amount: int):
|
||||||
curr.add_balance(amount)
|
curr.add_balance(amount)
|
||||||
curr.push()
|
curr.push()
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = EmbedBuilder.create_success_embed(
|
||||||
color=discord.Color.green(),
|
ctx,
|
||||||
description=f"Awarded **${Currency.format(amount)}** to {user.name}.",
|
author_text=CONST.STRINGS["admin_award_title"],
|
||||||
|
description=CONST.STRINGS["admin_award_description"].format(
|
||||||
|
Currency.format(amount),
|
||||||
|
user.name,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from lib.constants import CONST
|
||||||
from config.parser import JsonCache
|
|
||||||
from services.blacklist_service import BlacklistUserService
|
from services.blacklist_service import BlacklistUserService
|
||||||
|
from lib.embed_builder import EmbedBuilder
|
||||||
resources = JsonCache.read_json("art")
|
|
||||||
exclaim_icon = resources["icons"]["exclaim"]
|
|
||||||
hammer_icon = resources["icons"]["hammer"]
|
|
||||||
|
|
||||||
|
|
||||||
async def blacklist_user(
|
async def blacklist_user(
|
||||||
|
@ -15,24 +11,15 @@ async def blacklist_user(
|
||||||
user: discord.User,
|
user: discord.User,
|
||||||
reason: Optional[str] = None,
|
reason: Optional[str] = None,
|
||||||
) -> 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 = BlacklistUserService(user.id)
|
||||||
blacklist_service.add_to_blacklist(reason)
|
blacklist_service.add_to_blacklist(reason)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = EmbedBuilder.create_success_embed(
|
||||||
description=f"User `{user.name}` has been blacklisted from Luminara.",
|
ctx,
|
||||||
color=discord.Color.red(),
|
author_text=CONST.STRINGS["admin_blacklist_author"],
|
||||||
)
|
description=CONST.STRINGS["admin_blacklist_description"].format(user.name),
|
||||||
embed.set_author(name="User Blacklisted", icon_url=hammer_icon)
|
footer_text=CONST.STRINGS["admin_blacklist_footer"],
|
||||||
embed.set_footer(
|
hide_timestamp=True,
|
||||||
text="There is no process to reinstate a blacklisted user. Appeals are not considered.",
|
|
||||||
icon_url=exclaim_icon,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
|
@ -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
|
from db import database
|
||||||
|
|
||||||
|
@ -9,21 +12,49 @@ async def select_cmd(ctx, query: str):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = database.select_query(f"SELECT {query}")
|
results = database.select_query(f"SELECT {query}")
|
||||||
except sqlite3.Error as error:
|
embed = EmbedBuilder.create_success_embed(
|
||||||
results = error
|
ctx,
|
||||||
|
author_text=CONST.STRINGS["admin_sql_select_title"],
|
||||||
return await ctx.respond(
|
description=CONST.STRINGS["admin_sql_select_description"].format(
|
||||||
content=f"```SELECT {query}```\n```{results}```",
|
shorten(query, 200),
|
||||||
ephemeral=True,
|
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(embed=embed, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
async def inject_cmd(ctx, query: str):
|
async def inject_cmd(ctx, query: str):
|
||||||
try:
|
try:
|
||||||
database.execute_query(query)
|
database.execute_query(query)
|
||||||
await ctx.respond(content=f"That worked!\n```{query}```", ephemeral=True)
|
embed = EmbedBuilder.create_success_embed(
|
||||||
except sqlite3.Error as error:
|
ctx,
|
||||||
await ctx.respond(
|
author_text=CONST.STRINGS["admin_sql_inject_title"],
|
||||||
content=f"Query:\n```{query}```\nError message:\n```{error}```",
|
description=CONST.STRINGS["admin_sql_inject_description"].format(
|
||||||
ephemeral=True,
|
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)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import discord
|
import discord
|
||||||
from lib.embed_builder import EmbedBuilder
|
from lib.embed_builder import EmbedBuilder
|
||||||
from lib.exceptions.LumiExceptions import LumiException
|
from lib.exceptions.LumiExceptions import LumiException
|
||||||
|
from lib.constants import CONST
|
||||||
|
|
||||||
|
|
||||||
async def sync_commands(client, ctx):
|
async def sync_commands(client, ctx):
|
||||||
|
@ -8,9 +9,11 @@ async def sync_commands(client, ctx):
|
||||||
await client.sync_commands()
|
await client.sync_commands()
|
||||||
embed = EmbedBuilder.create_success_embed(
|
embed = EmbedBuilder.create_success_embed(
|
||||||
ctx,
|
ctx,
|
||||||
author_text="Sync Successful",
|
author_text=CONST.STRINGS["admin_sync_title"],
|
||||||
description="command tree synced successfully.",
|
description=CONST.STRINGS["admin_sync_description"],
|
||||||
)
|
)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
except discord.HTTPException as e:
|
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
|
||||||
|
|
|
@ -58,9 +58,9 @@ async def add_reaction(
|
||||||
is_emoji,
|
is_emoji,
|
||||||
is_full_match,
|
is_full_match,
|
||||||
)
|
)
|
||||||
await ctx.respond(embed=embed)
|
|
||||||
else:
|
else:
|
||||||
embed = create_failure_embed(trigger_text, is_emoji)
|
embed = create_failure_embed(trigger_text, is_emoji)
|
||||||
|
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue