Skip to content

Commit 0f6f85c

Browse files
Bible
1 parent 5388bc9 commit 0f6f85c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎main.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44

55
import aiosqlite
6+
import httpx
67
import discord
78
from discord.ext import commands
89

@@ -311,6 +312,13 @@ async def bottle(ctx: commands.Context):
311312
await ctx.reply("The !bottle command is now called !choose. Use that instead.")
312313

313314

315+
@TBotD.command()
316+
async def bible(ctx: commands.Context):
317+
bl.log(bible, ctx)
318+
verse = await fetch_random_verse()
319+
ctx.reply(verse)
320+
321+
314322
@TBotD.command()
315323
async def when(ctx: commands.Context, *, post: str = ""):
316324
"""Parse a date!"""
@@ -359,6 +367,23 @@ async def on_command_error(ctx: commands.Context, error: commands.CommandError):
359367
await ctx.message.add_reaction(DENIED)
360368

361369

370+
async def fetch_random_verse() -> str:
371+
answer = "(1 Kings 2:23) And he went up from thence unto Bethel: and as he was going up by the way, there came forth little children out of the city, and mocked him, and said unto him, Go up, thou bald head; go up, thou bald head."
372+
async with httpx.AsyncClient() as client:
373+
try:
374+
response = await client.get("https://bible-api.com/data/web/random")
375+
response.raise_for_status()
376+
data = response.json().get("random_verse", {})
377+
book = data.get("book", "Unknown Book")
378+
chapter = data.get("chapter", 0)
379+
verse = data.get("verse", 0)
380+
text = data.get("text", "The industrial revolution and its consequences have been a disaster for the human race.")
381+
answer = f"({book} {chapter}:{verse}) \"{text}\""
382+
except httpx.HTTPError as exc:
383+
bl.error_log(exc)
384+
return answer
385+
386+
362387
if __name__ == "__main__":
363388
print("Running bot now...")
364389
TBotD.run(KEY)

0 commit comments

Comments
 (0)