forked from blizzthewolf/SeaCogs
fix(bible): working on the bible random command
This commit is contained in:
parent
95cd7fdcb5
commit
52a440ff3e
1 changed files with 7 additions and 32 deletions
|
@ -73,7 +73,7 @@ class Bible(commands.Cog):
|
||||||
|
|
||||||
async def _get_verses(self, bible_id: str, book_id: str, chapter: int) -> dict:
|
async def _get_verses(self, 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}/books/{book_id}/chapters/{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")
|
||||||
async with self.session.get(url, headers=headers) as response:
|
async with self.session.get(url, headers=headers) as response:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
@ -82,35 +82,12 @@ class Bible(commands.Cog):
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
@commands.group(autohelp=True)
|
@commands.group(autohelp=True)
|
||||||
async def bible(self, ctx: commands.Context):
|
async def bible(self, ctx: commands.Context, book: str, passage: str):
|
||||||
"""Core command for the Bible cog."""
|
|
||||||
|
|
||||||
@bible.command(name="verse")
|
|
||||||
async def bible_verse(
|
|
||||||
self, ctx: commands.Context, book: str, chapter: int, verse: int
|
|
||||||
) -> str:
|
|
||||||
"""Get a Bible verse."""
|
|
||||||
bible_id = await self.config.bible()
|
|
||||||
try:
|
|
||||||
book_id = await self.translate_book_name(bible_id, book)
|
|
||||||
except ValueError as e:
|
|
||||||
await ctx.send(str(e))
|
|
||||||
return
|
|
||||||
passage = await self._get_passage(bible_id, f"{book_id}.{chapter}.{verse}")
|
|
||||||
embed = Embed(
|
|
||||||
title=f"{passage['reference']}",
|
|
||||||
description=passage["content"].replace("¶ ", ""),
|
|
||||||
color=await self.bot.get_embed_color(ctx.channel),
|
|
||||||
)
|
|
||||||
embed.set_footer(text=f"{ctx.prefix}bible verse - Powered by API.bible")
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@bible.command(name="passage")
|
|
||||||
async def bible_passage(self, ctx: commands.Context, book: str, passage: str):
|
|
||||||
"""Get a Bible passage.
|
"""Get a Bible passage.
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
`[p]bible passage John 3:16-3:17`"""
|
`[p]bible Genesis 1:1`
|
||||||
|
`[p]bible John 3:16-3:17`"""
|
||||||
bible_id = await self.config.bible()
|
bible_id = await self.config.bible()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -140,7 +117,7 @@ class Bible(commands.Cog):
|
||||||
description=passage["content"].replace("¶ ", ""),
|
description=passage["content"].replace("¶ ", ""),
|
||||||
color=await self.bot.get_embed_color(ctx.channel),
|
color=await self.bot.get_embed_color(ctx.channel),
|
||||||
)
|
)
|
||||||
embed.set_footer(text=f"{ctx.prefix}bible passage - Powered by API.bible")
|
embed.set_footer(text=f"{ctx.prefix}bible - Powered by API.bible")
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@bible.command(name="random")
|
@bible.command(name="random")
|
||||||
|
@ -152,10 +129,8 @@ 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(bible_id, book["id"], chapter["number"])
|
verses = await self._get_verses(bible_id, book["id"], chapter["number"])
|
||||||
verse = random.choice(verses)
|
verse = random.choice(verses)["id"]
|
||||||
passage = await self._get_passage(
|
passage = await self._get_passage(bible_id, verse)
|
||||||
bible_id, f"{book['id']}.{chapter['number']}.{verse['number']}"
|
|
||||||
)
|
|
||||||
embed = Embed(
|
embed = Embed(
|
||||||
title=f"{passage['reference']}",
|
title=f"{passage['reference']}",
|
||||||
description=passage["content"].replace("¶ ", ""),
|
description=passage["content"].replace("¶ ", ""),
|
||||||
|
|
Loading…
Reference in a new issue