mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 20:23:12 +00:00
Refactor JSON and YAML file handling for improved readability and performance
This commit is contained in:
parent
67c423fc7e
commit
c1ac1c172c
4 changed files with 12 additions and 7 deletions
|
@ -30,4 +30,9 @@ repos:
|
|||
hooks:
|
||||
- id: clean-dotenv
|
||||
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.16.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
|
||||
exclude: ".archive/"
|
||||
|
|
|
@ -10,7 +10,7 @@ class JsonCache:
|
|||
def read_json(path):
|
||||
"""Read and cache the JSON data if not already cached."""
|
||||
if path not in JsonCache._cache:
|
||||
with open(f"config/JSON/{path}.json", "r") as file:
|
||||
with open(f"config/JSON/{path}.json") as file:
|
||||
JsonCache._cache[path] = json.load(file)
|
||||
logger.debug(f"{path}.json was loaded and cached.")
|
||||
|
||||
|
@ -25,7 +25,7 @@ class YamlCache:
|
|||
"""Read and cache the creds.yaml data if not already cached."""
|
||||
path = "creds"
|
||||
if path not in YamlCache._cache:
|
||||
with open(f"{path}.yaml", "r") as file:
|
||||
with open(f"{path}.yaml") as file:
|
||||
YamlCache._cache[path] = yaml.safe_load(file)
|
||||
logger.debug(f"{path}.yaml was loaded and cached.")
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class EventHandler(Cog):
|
|||
|
||||
@Cog.listener()
|
||||
async def on_command_completion(self, ctx) -> None:
|
||||
log_msg = "%s executed .%s" % (ctx.author.name, ctx.command.qualified_name)
|
||||
log_msg = "{} executed .{}".format(ctx.author.name, ctx.command.qualified_name)
|
||||
|
||||
if ctx.guild is not None:
|
||||
logger.debug(f"{log_msg} | guild: {ctx.guild.name} ")
|
||||
|
@ -76,7 +76,7 @@ class EventHandler(Cog):
|
|||
|
||||
@Cog.listener()
|
||||
async def on_application_command_completion(self, ctx) -> None:
|
||||
log_msg = "%s executed /%s" % (ctx.author.name, ctx.command.qualified_name)
|
||||
log_msg = "{} executed /{}".format(ctx.author.name, ctx.command.qualified_name)
|
||||
|
||||
if ctx.guild is not None:
|
||||
logger.debug(f"{log_msg} | guild: {ctx.guild.name} ")
|
||||
|
|
|
@ -19,7 +19,7 @@ class LumiHelp(commands.HelpCommand):
|
|||
}
|
||||
|
||||
def get_command_qualified_name(self, command):
|
||||
return "`%s%s`" % (self.context.clean_prefix, command.qualified_name)
|
||||
return "`{}{}`".format(self.context.clean_prefix, command.qualified_name)
|
||||
|
||||
async def send_bot_help(self, mapping):
|
||||
embed = discord.Embed(color=discord.Color.blurple())
|
||||
|
@ -52,13 +52,13 @@ class LumiHelp(commands.HelpCommand):
|
|||
description=command.help,
|
||||
)
|
||||
|
||||
usage_value = "`%s%s %s`" % (
|
||||
usage_value = "`{}{} {}`".format(
|
||||
self.context.clean_prefix,
|
||||
command.qualified_name,
|
||||
command.signature,
|
||||
)
|
||||
for alias in command.aliases:
|
||||
usage_value += "\n`%s%s %s`" % (
|
||||
usage_value += "\n`{}{} {}`".format(
|
||||
self.context.clean_prefix,
|
||||
alias,
|
||||
command.signature,
|
||||
|
|
Loading…
Reference in a new issue