|
3 | 3 | import time |
4 | 4 |
|
5 | 5 | import aiosqlite |
| 6 | +import httpx |
6 | 7 | import discord |
7 | 8 | from discord.ext import commands |
8 | 9 |
|
@@ -311,6 +312,13 @@ async def bottle(ctx: commands.Context): |
311 | 312 | await ctx.reply("The !bottle command is now called !choose. Use that instead.") |
312 | 313 |
|
313 | 314 |
|
| 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 | + |
314 | 322 | @TBotD.command() |
315 | 323 | async def when(ctx: commands.Context, *, post: str = ""): |
316 | 324 | """Parse a date!""" |
@@ -359,6 +367,23 @@ async def on_command_error(ctx: commands.Context, error: commands.CommandError): |
359 | 367 | await ctx.message.add_reaction(DENIED) |
360 | 368 |
|
361 | 369 |
|
| 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 | + |
362 | 387 | if __name__ == "__main__": |
363 | 388 | print("Running bot now...") |
364 | 389 | TBotD.run(KEY) |
|
0 commit comments