forked from blizzthewolf/SeaCogs
fix(bible): do not use fums on routes that don't support it (part 3)
This commit is contained in:
parent
09e91da62f
commit
08b3553c2c
1 changed files with 4 additions and 27 deletions
|
@ -141,17 +141,12 @@ class Bible(commands.Cog):
|
||||||
raise bible.errors.ServiceUnavailable()
|
raise bible.errors.ServiceUnavailable()
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
async def _get_verses(
|
async def _get_verses(self, bible_id: str, book_id: str, chapter: int) -> dict:
|
||||||
self, ctx: commands.Context, bible_id: str, book_id: str, chapter: int
|
|
||||||
) -> dict:
|
|
||||||
"""Get the verses of a chapter from the API.bible API."""
|
"""Get the verses of a chapter from the API.bible API."""
|
||||||
url = f"https://api.scripture.api.bible/v1/bibles/{bible_id}/chapters/{book_id}.{chapter}/verses"
|
url = f"https://api.scripture.api.bible/v1/bibles/{bible_id}/chapters/{book_id}.{chapter}/verses"
|
||||||
headers = await self.bot.get_shared_api_tokens("api.bible")
|
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()
|
data = await response.json()
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
"_get_verses executed with a response code of: %s\n%s",
|
"_get_verses executed with a response code of: %s\n%s",
|
||||||
|
@ -164,22 +159,6 @@ class Bible(commands.Cog):
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError()
|
||||||
if response.status == 503:
|
if response.status == 503:
|
||||||
raise bible.errors.ServiceUnavailable()
|
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_verses FUMS executed with a response code of: %s\n%s",
|
|
||||||
response.status,
|
|
||||||
json.dumps(fums_data),
|
|
||||||
)
|
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
@commands.group(autohelp=True)
|
@commands.group(autohelp=True)
|
||||||
|
@ -249,9 +228,7 @@ class Bible(commands.Cog):
|
||||||
chapters = await self._get_chapters(bible_id, book["id"])
|
chapters = await self._get_chapters(bible_id, book["id"])
|
||||||
chapter = random.choice(chapters)
|
chapter = random.choice(chapters)
|
||||||
|
|
||||||
verses = await self._get_verses(
|
verses = await self._get_verses(bible_id, book["id"], chapter["number"])
|
||||||
ctx, bible_id, book["id"], chapter["number"]
|
|
||||||
)
|
|
||||||
verse = random.choice(verses)["id"]
|
verse = random.choice(verses)["id"]
|
||||||
|
|
||||||
passage = await self._get_passage(ctx, bible_id, verse, False)
|
passage = await self._get_passage(ctx, bible_id, verse, False)
|
||||||
|
|
Loading…
Reference in a new issue