fix(bible): fixed error handling for bible commands

This commit is contained in:
Seaswimmer 2024-02-01 19:37:47 -05:00
parent 44179ad42d
commit c37a58d687
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -34,23 +34,6 @@ class Bible(commands.Cog):
self.config.register_global(bible="de4e12af7f28f599-01")
self.config.register_user(bible=None)
async def on_command_error(self, ctx: commands.Context, err):
if isinstance(err, bible.errors.Unauthorized):
await ctx.send(
error(
"""The API key for API.bible is missing or invalid. Please report this to the bot owner.
If you are the bot owner, please check the documentation [here](https://seacogs.coastalcommits.com/bible/#setup)."""
)
)
if isinstance(err, bible.errors.BibleAccessError):
await ctx.send(
error(
"The provided API key cannot retrieve sections from the configured Bible. Please report this to the bot owner."
)
)
if isinstance(err, bible.errors.NotFound):
await ctx.send(error("The requested passage was not found."))
async def translate_book_name(self, bible_id: str, book_name: str) -> str:
"""Translate a book name to a book ID."""
book_name_list = book_name.split()
@ -216,3 +199,25 @@ class Bible(commands.Cog):
)
embed.set_footer(text=f"{ctx.prefix}bible random - Powered by API.bible")
await ctx.send(embed=embed)
@bible_passage.error
@bible_random.error
async def error_handler(self, ctx: commands.Context, err):
if isinstance(err, bible.errors.Unauthorized):
await ctx.send(
error(
"""The API key for API.bible is missing or invalid. Please report this to the bot owner.
If you are the bot owner, please check the documentation [here](https://seacogs.coastalcommits.com/bible/#setup)."""
)
)
return
elif isinstance(err, bible.errors.BibleAccessError):
await ctx.send(
error(
"The provided API key cannot retrieve sections from the configured Bible. Please report this to the bot owner."
)
)
return
elif isinstance(err, bible.errors.NotFound):
await ctx.send(error("The requested passage was not found."))
return