Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bible verse cog for Red-Discordbot
import discord
import requests
import json
import urllib
from discord.ext import commands
class Bible:
def __init__(self, bot):
self.bot = bot
self.URL = "http://labs.bible.org"
async def api_request(self, arg, mode='json', formatting='plain'):
geturl = "{U}/api?passage={a}&formatting={f}&type={m}".format(
U=self.URL,
a=arg,
f=formatting,
m=mode
)
r = requests.get(geturl)
if r.status_code is not 200:
await self.bot.say("Error accessing {U}, error {E}. Please notify a minister.".format(
U=URL,
E=r.status_code
)
)
return r
@commands.command()
async def bible(self, ref1, ref2, ref3=None):
"""
Access a bible verse by it's direct reference
reference: Scripture reference (E.g '1 Cor 2:2, John 3:16-17')
"""
# Work around bot quoting rules, we don't want users to need to
# enclose scripture references in quotes.
# Example: 1 John 5:19
# John 3:16
if ref3:
ref = " ".join((ref1,ref2,ref3))
else:
ref = " ".join((ref1,ref2))
verseref = urllib.parse.quote_plus(ref)
r = await self.api_request(verseref)
js_response = json.loads(r.text)
for passage in js_response:
await self.bot.say(passage['text'])
def setup(bot):
bot.add_cog(Bible(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment