forked from blizzthewolf/SeaCogs
fix(bible): do not use fums on routes that don't support it (part 2)
This commit is contained in:
parent
83edd36d6b
commit
09e91da62f
1 changed files with 9 additions and 32 deletions
|
@ -35,15 +35,13 @@ class Bible(commands.Cog):
|
|||
self.config.register_global(bible="de4e12af7f28f599-02")
|
||||
self.config.register_user(bible=None)
|
||||
|
||||
async def translate_book_name(
|
||||
self, ctx: commands.Context, bible_id: str, book_name: str
|
||||
) -> str:
|
||||
async def translate_book_name(self, bible_id: str, book_name: str) -> str:
|
||||
"""Translate a book name to a book ID."""
|
||||
book_name_list = [
|
||||
w.lower() if w.lower() == "of" else w.title() for w in book_name.split()
|
||||
]
|
||||
book_name = " ".join(book_name_list)
|
||||
books = await self._get_books(ctx, bible_id)
|
||||
books = await self._get_books(bible_id)
|
||||
for book in books:
|
||||
if book_name in (book["abbreviation"], book["name"]):
|
||||
return book["id"]
|
||||
|
@ -103,7 +101,7 @@ class Bible(commands.Cog):
|
|||
)
|
||||
return data["data"]
|
||||
|
||||
async def _get_books(self, ctx: commands.Context, bible_id: str) -> dict:
|
||||
async def _get_books(self, bible_id: str) -> dict:
|
||||
"""Get the books of the Bible from the API.bible API."""
|
||||
url = f"https://api.scripture.api.bible/v1/bibles/{bible_id}/books"
|
||||
headers = await self.bot.get_shared_api_tokens("api.bible")
|
||||
|
@ -123,17 +121,12 @@ class Bible(commands.Cog):
|
|||
raise bible.errors.ServiceUnavailable()
|
||||
return data["data"]
|
||||
|
||||
async def _get_chapters(
|
||||
self, ctx: commands.Context, bible_id: str, book_id: str
|
||||
) -> dict:
|
||||
async def _get_chapters(self, bible_id: str, book_id: str) -> dict:
|
||||
"""Get the chapters of a book from the API.bible API."""
|
||||
url = f"https://api.scripture.api.bible/v1/bibles/{bible_id}/books/{book_id}/chapters"
|
||||
headers = await self.bot.get_shared_api_tokens("api.bible")
|
||||
params = {
|
||||
"fums-version": "3",
|
||||
}
|
||||
|
||||
async with self.session.get(url, headers=headers, params=params) as response:
|
||||
async with self.session.get(url, headers=headers) as response:
|
||||
data = await response.json()
|
||||
self.logger.debug(
|
||||
"_get_chapters executed with a response code of: %s\n%s",
|
||||
|
@ -146,23 +139,7 @@ class Bible(commands.Cog):
|
|||
raise bible.errors.BibleAccessError()
|
||||
if response.status == 503:
|
||||
raise bible.errors.ServiceUnavailable()
|
||||
|
||||
fums_url = "https://fums.api.bible/f3"
|
||||
fums_params = {
|
||||
"t": data["meta"]["fumsToken"],
|
||||
"dId": "discord-" + str(self.bot.user.id),
|
||||
"sId": "discord-" + str(ctx.message.created_at.timestamp()),
|
||||
"uId": ctx.author.id,
|
||||
}
|
||||
|
||||
async with self.session.get(fums_url, params=fums_params) as response:
|
||||
fums_data = await response.json()
|
||||
self.logger.debug(
|
||||
"_get_chapters FUMS executed with a response code of: %s\n%s",
|
||||
response.status,
|
||||
json.dumps(fums_data),
|
||||
)
|
||||
return data["data"]
|
||||
return data["data"]
|
||||
|
||||
async def _get_verses(
|
||||
self, ctx: commands.Context, bible_id: str, book_id: str, chapter: int
|
||||
|
@ -219,7 +196,7 @@ class Bible(commands.Cog):
|
|||
bible_id = await self.config.bible()
|
||||
|
||||
try:
|
||||
book_id = await self.translate_book_name(ctx, bible_id, book)
|
||||
book_id = await self.translate_book_name(bible_id, book)
|
||||
except ValueError as e:
|
||||
await ctx.send(str(e))
|
||||
return
|
||||
|
@ -266,10 +243,10 @@ class Bible(commands.Cog):
|
|||
bible_id = await self.config.bible()
|
||||
|
||||
try:
|
||||
books = await self._get_books(ctx, bible_id)
|
||||
books = await self._get_books(bible_id)
|
||||
book = random.choice(books)
|
||||
|
||||
chapters = await self._get_chapters(ctx, bible_id, book["id"])
|
||||
chapters = await self._get_chapters(bible_id, book["id"])
|
||||
chapter = random.choice(chapters)
|
||||
|
||||
verses = await self._get_verses(
|
||||
|
|
Loading…
Reference in a new issue