Skip to content

Commit

Permalink
Create bible.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
depthso authored Nov 1, 2024
1 parent e70a26e commit 7240a98
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions bible.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
--// Services
local HttpService = game:GetService("HttpService")

local Bible = {
Translation= "eng_kjv"
}

export type reference = {
chapter: number,
verse: number
}
export type verse = {
number: number,
type: string,
content: string
}
export type footnote = {
caller: string,
noteId: number,
reference: reference,
text: string
}
export type chapter = {
content: verses,
footnotes: {
[number]: footnote
},
number: number
}
export type book = {
id: string,
name: string,
commonName: string,
title: string,
order: number,
numberOfChapters: number,
totalNumberOfVerses: number
}
export type translation = {
id: string,
name: string,
website: string,
shortName: string,
englishName: string,
textDirection: string,
numberOfBooks: number,
totalNumberOfChapters: number,
totalNumberOfVerses: number,
languageName: string,
languageEnglishName: string
}

type TranslationId = string
type verses = {
[number]: verse
}
type books = {
[number]: book
}
type translations = {
[number]: translation
}

function Bible:Fetch(Url): string
return HttpService:GetAsync(Url, false)
end

local function JsonGet(Url: string): SharedTable
local Raw = Bible:Fetch(Url)
local Json = HttpService:JSONDecode(Raw)

return Json
end

function Bible:SetTranslation(NewTranslation: Translation)
self.Translation = NewTranslation
end

function Bible:GetTranslations(): translations
local API = "https://bible.helloao.org/api/available_translations.json"
local Json = JsonGet(API)
local Translations = Json.translations

return Translations
end

function Bible:GetBooks(TranslationId: TranslationId?): books
local Translation = TranslationId or self.Translation
local API = `https://bible.helloao.org/api/{Translation}/books.json`
local Json = JsonGet(API)

return Json.books
end

type Default = {
BookId: string,
Chapter: number
}

function Bible:GetChapter<Default>(BookId, ChapterNum, TranslationId: TranslationId?): chapter
local ChapterNum = ChapterNum or 1
local Translation = TranslationId or self.Translation
local API = `https://bible.helloao.org/api/{Translation}/{BookId}/{ChapterNum}.json`
local Json = JsonGet(API)

return Json.chapter
end

function Bible:GetVerses<Default>(BookId, ChapterNum, TranslationId: TranslationId?): verses
local ChapterNum = ChapterNum or 1
local Translation = TranslationId or self.Translation

local Chapter = self:GetChapter(BookId, ChapterNum, TranslationId)
local Verses = Chapter.content

return Verses
end

function Bible:GetVerse<Default>(BookId, ChapterNum, Verse: number, TranslationId: TranslationId?): verse
local Verses: verses = Bible:GetVerses(BookId, ChapterNum)
return Verses[Verse]
end

function Bible:UnpackVerse(Verse: verse): string
local Content = Verse.content
return table.concat(Content, " ")
end

return Bible

0 comments on commit 7240a98

Please sign in to comment.