Skip to content

Commit 7240a98

Browse files
authored
Create bible.lua
1 parent e70a26e commit 7240a98

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

bible.lua

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
--// Services
2+
local HttpService = game:GetService("HttpService")
3+
4+
local Bible = {
5+
Translation= "eng_kjv"
6+
}
7+
8+
export type reference = {
9+
chapter: number,
10+
verse: number
11+
}
12+
export type verse = {
13+
number: number,
14+
type: string,
15+
content: string
16+
}
17+
export type footnote = {
18+
caller: string,
19+
noteId: number,
20+
reference: reference,
21+
text: string
22+
}
23+
export type chapter = {
24+
content: verses,
25+
footnotes: {
26+
[number]: footnote
27+
},
28+
number: number
29+
}
30+
export type book = {
31+
id: string,
32+
name: string,
33+
commonName: string,
34+
title: string,
35+
order: number,
36+
numberOfChapters: number,
37+
totalNumberOfVerses: number
38+
}
39+
export type translation = {
40+
id: string,
41+
name: string,
42+
website: string,
43+
shortName: string,
44+
englishName: string,
45+
textDirection: string,
46+
numberOfBooks: number,
47+
totalNumberOfChapters: number,
48+
totalNumberOfVerses: number,
49+
languageName: string,
50+
languageEnglishName: string
51+
}
52+
53+
type TranslationId = string
54+
type verses = {
55+
[number]: verse
56+
}
57+
type books = {
58+
[number]: book
59+
}
60+
type translations = {
61+
[number]: translation
62+
}
63+
64+
function Bible:Fetch(Url): string
65+
return HttpService:GetAsync(Url, false)
66+
end
67+
68+
local function JsonGet(Url: string): SharedTable
69+
local Raw = Bible:Fetch(Url)
70+
local Json = HttpService:JSONDecode(Raw)
71+
72+
return Json
73+
end
74+
75+
function Bible:SetTranslation(NewTranslation: Translation)
76+
self.Translation = NewTranslation
77+
end
78+
79+
function Bible:GetTranslations(): translations
80+
local API = "https://bible.helloao.org/api/available_translations.json"
81+
local Json = JsonGet(API)
82+
local Translations = Json.translations
83+
84+
return Translations
85+
end
86+
87+
function Bible:GetBooks(TranslationId: TranslationId?): books
88+
local Translation = TranslationId or self.Translation
89+
local API = `https://bible.helloao.org/api/{Translation}/books.json`
90+
local Json = JsonGet(API)
91+
92+
return Json.books
93+
end
94+
95+
type Default = {
96+
BookId: string,
97+
Chapter: number
98+
}
99+
100+
function Bible:GetChapter<Default>(BookId, ChapterNum, TranslationId: TranslationId?): chapter
101+
local ChapterNum = ChapterNum or 1
102+
local Translation = TranslationId or self.Translation
103+
local API = `https://bible.helloao.org/api/{Translation}/{BookId}/{ChapterNum}.json`
104+
local Json = JsonGet(API)
105+
106+
return Json.chapter
107+
end
108+
109+
function Bible:GetVerses<Default>(BookId, ChapterNum, TranslationId: TranslationId?): verses
110+
local ChapterNum = ChapterNum or 1
111+
local Translation = TranslationId or self.Translation
112+
113+
local Chapter = self:GetChapter(BookId, ChapterNum, TranslationId)
114+
local Verses = Chapter.content
115+
116+
return Verses
117+
end
118+
119+
function Bible:GetVerse<Default>(BookId, ChapterNum, Verse: number, TranslationId: TranslationId?): verse
120+
local Verses: verses = Bible:GetVerses(BookId, ChapterNum)
121+
return Verses[Verse]
122+
end
123+
124+
function Bible:UnpackVerse(Verse: verse): string
125+
local Content = Verse.content
126+
return table.concat(Content, " ")
127+
end
128+
129+
return Bible

0 commit comments

Comments
 (0)