fix(bible): fixing some things

This commit is contained in:
Seaswimmer 2024-02-02 01:45:51 -05:00
parent e71fc9f154
commit acc883af20
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -35,13 +35,15 @@ class Bible(commands.Cog):
self.config.register_global(bible="de4e12af7f28f599-02") self.config.register_global(bible="de4e12af7f28f599-02")
self.config.register_user(bible=None) self.config.register_user(bible=None)
async def translate_book_name(self, bible_id: str, book_name: str) -> str: async def translate_book_name(
self, ctx: commands.Context, bible_id: str, book_name: str
) -> str:
"""Translate a book name to a book ID.""" """Translate a book name to a book ID."""
book_name_list = [ book_name_list = [
w.lower() if w.lower() == "of" else w.title() for w in book_name.split() w.lower() if w.lower() == "of" else w.title() for w in book_name.split()
] ]
book_name = " ".join(book_name_list) book_name = " ".join(book_name_list)
books = await self._get_books(bible_id) books = await self._get_books(ctx, bible_id)
for book in books: for book in books:
if book_name in (book["abbreviation"], book["name"]): if book_name in (book["abbreviation"], book["name"]):
return book["id"] return book["id"]
@ -58,6 +60,7 @@ class Bible(commands.Cog):
url = f"https://api.scripture.api.bible/v1/bibles/{bible_id}/passages/{passage_id}" url = f"https://api.scripture.api.bible/v1/bibles/{bible_id}/passages/{passage_id}"
headers = await self.bot.get_shared_api_tokens("api.bible") headers = await self.bot.get_shared_api_tokens("api.bible")
params = { params = {
"fums-version": "3",
"content-type": "text", "content-type": "text",
"include-notes": "false", "include-notes": "false",
"include-titles": "false", "include-titles": "false",
@ -65,7 +68,6 @@ class Bible(commands.Cog):
"include-verse-numbers": str(include_verse_numbers).lower(), "include-verse-numbers": str(include_verse_numbers).lower(),
"include-verse-spans": "false", "include-verse-spans": "false",
"use-org-id": "false", "use-org-id": "false",
"fums-version": "3",
} }
async with self.session.get(url, headers=headers, params=params) as response: async with self.session.get(url, headers=headers, params=params) as response:
@ -236,7 +238,7 @@ class Bible(commands.Cog):
bible_id = await self.config.bible() bible_id = await self.config.bible()
try: try:
book_id = await self.translate_book_name(bible_id, book) book_id = await self.translate_book_name(ctx, bible_id, book)
except ValueError as e: except ValueError as e:
await ctx.send(str(e)) await ctx.send(str(e))
return return