Documentation
¶
Index ¶
- Constants
- Variables
- func AcronymizeDevo(msg string) (string, error)
- func CheckBibleReference(ref string) bool
- func CleanPassageText(text string) string
- func CloseAction(env def.SessionData) def.SessionData
- func DumpUserList(env def.SessionData) def.SessionData
- func ExpandDevo(msg string) (string, error)
- func ExtractBibleReferences(input string) []string
- func FormatQuery(query string, t TMSQueryType) string
- func GetBibleAsk(env def.SessionData) def.SessionData
- func GetBibleAskWithContext(env def.SessionData, contextVerses []string) def.SessionData
- func GetBiblePassage(env def.SessionData) def.SessionData
- func GetBiblePassageFallback(env def.SessionData) def.SessionData
- func GetBibleSearch(env def.SessionData) def.SessionData
- func GetDailyNewTestamentReadingReferences(env def.SessionData) string
- func GetDesiringGodArticles() []def.Option
- func GetDevo(env def.SessionData, bot platform.Platform) def.SessionData
- func GetDevotionalData(env def.SessionData, devo string) def.ResponseData
- func GetDevotionalDispatchMethod(devo string) string
- func GetDevotionalText(devo string) string
- func GetDiscipleshipJournalReferences(env def.SessionData) []def.Option
- func GetMCheyneHtml() *html.Node
- func GetMCheyneReferences() []def.Option
- func GetNavigators5xReferences(env def.SessionData) string
- func GetNavigators5xRestDayPrompt(env def.SessionData) (string, []def.Option)
- func GetPassage(ref string, doc *html.Node, version string) string
- func GetRandomTMSVerse(env def.SessionData) string
- func GetReference(doc *html.Node) string
- func GetTMSVerse(env def.SessionData) def.SessionData
- func GetUtmostForHisHighestArticles() []def.Option
- func Migrate(env def.SessionData) def.SessionData
- func MockSubmitQuery(t HelperT, callback func(QueryRequest)) func(QueryRequest, interface{}) error
- func ParseBibleReference(input string) (string, bool)
- func ParseBibleReferenceFromStart(input string) (string, int, bool)
- func ParseNodesForPassage(node *html.Node) string
- func ParsePassageFromHtml(ref string, rawHtml string, version string) string
- func ProcessCommand(env def.SessionData, bot platform.Platform) def.SessionData
- func ProcessNaturalLanguage(env def.SessionData) def.SessionData
- func QueryTMSPack(db TMSDatabase, p PackSelector) (TMSPack, TMSVerse, error)
- func QueryTMSSeries(db TMSDatabase, s SeriesSelector) (TMSPack, TMSVerse, error)
- func QueryTMSVerse(db TMSDatabase, v VerseSelector) (TMSPack, TMSVerse, error)
- func ResetAPIConfigCache()
- func SanitizeVersion(msg string) (string, error)
- func SetAPIConfigOverride(url, key string)
- func SetEnv(key, value string) func()
- func SetVersion(env def.SessionData) def.SessionData
- func UnsetEnv(key string) func()
- func UpdateSubscription(env def.SessionData) def.SessionData
- type BibleReadingPlanChapter
- type BibleReadingPlanDevo
- type DailyBRP
- type DailyChapterBRP
- type ErrorDetails
- type ErrorResponse
- type HelperT
- type MockBot
- type OQueryResponse
- type PackSelector
- type QueryContext
- type QueryObject
- type QueryRequest
- type SearchResult
- type SeriesSelector
- type TMSDatabase
- type TMSPack
- type TMSQueryType
- type TMSSeries
- type TMSVerse
- type UserContext
- type VerseResponse
- type VerseSelector
- type WordSearchResponse
Constants ¶
const ( MCBRP string = "MCBRP" DJBRP string = "DJBRP" DNTBRP string = "DNTBRP" N5XBRP string = "N5XBRP" DGORG string = "DGORG" DTMSV string = "DTMSV" MUFHH string = "MUFHH" )
const ( Keyboard string = "Keyboard" Passage string = "Passage" MemoryVerse string = "MemoryVerse" )
const ADM_CMD_DUMP = "admin_dump"
const ADM_MIGRATE = "admin_migrate"
const CMD_ASK = "ask"
const CMD_CLOSE = "close"
const CMD_DEVO = "devo"
const CMD_PASSAGE = "passage"
const CMD_SEARCH = "search"
const CMD_SUBSCRIBE = "subscribe"
const CMD_TMS = "tms"
const CMD_VERSION = "version"
Variables ¶
var BibleBooks = map[string]string{}/* 272 elements not displayed */
var CLOSEMSGS = []string{
"Okay %s",
"Got it, %s!",
"As you wish, %s",
"Because you said so, %s",
"I hear and obey, %s",
}
var DEVOS = map[string]string{ "M'Cheyne Bible Reading Plan": MCBRP, "Discipleship Journal Bible Reading Plan": DJBRP, "Daily New Testament Reading Plan": DNTBRP, "Navigators 5x5x5 New Testament Reading Plan": N5XBRP, "Desiring God Articles": DGORG, "Daily Topical Memory System Verse": DTMSV, "My Utmost For His Highest Articles": MUFHH, }
var DEVO_NAMES = map[string]string{ MCBRP: "M'Cheyne Bible Reading Plan", DJBRP: "Discipleship Journal Bible Reading Plan", DNTBRP: "Daily New Testament Reading Plan", N5XBRP: "Navigators 5x5x5 New Testament Reading Plan", DGORG: "Desiring God Articles", DTMSV: "Daily Topical Memory System Verse", MUFHH: "My Utmost For His Highest Articles", }
var GetPassageHTML = func(ref, ver string) *html.Node { ref = url.QueryEscape(ref) ver = url.QueryEscape(ver) query := fmt.Sprintf("https://classic.biblegateway.com/passage/?search=%s&version=%s&interface=print", ref, ver) return utils.QueryHtml(query) }
var SingleChapterBooks = map[string]bool{ "Obadiah": true, "Philemon": true, "2 John": true, "3 John": true, "Jude": true, }
var SubmitQuery = func(req QueryRequest, result interface{}) error { apiURL, apiKey := getAPIConfig() if apiURL == "" { return fmt.Errorf("BIBLE_API_URL environment variable is not set") } if apiURL == "https://example.com" { switch r := result.(type) { case *WordSearchResponse: *r = WordSearchResponse{ {Verse: "John 3:16", URL: "https://example.com/John3:16"}, } case *OQueryResponse: *r = OQueryResponse{ Text: "This is a mock response.", References: []SearchResult{ {Verse: "John 3:16", URL: "https://example.com/John3:16"}, }, } case *VerseResponse: *r = VerseResponse{ Verse: "For God so loved the world...", } } return nil } jsonData, err := json.Marshal(req) if err != nil { return fmt.Errorf("failed to marshal request: %v", err) } client := &http.Client{} httpReq, err := http.NewRequest("POST", apiURL+"/query", bytes.NewBuffer(jsonData)) if err != nil { return fmt.Errorf("failed to create request: %v", err) } httpReq.Header.Set("Content-Type", "application/json") if apiKey != "" { httpReq.Header.Set("X-API-KEY", apiKey) } resp, err := client.Do(httpReq) if err != nil { return fmt.Errorf("request failed: %v", err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("failed to read response body: %v", err) } if resp.StatusCode != http.StatusOK { // Try to parse error response var errResp ErrorResponse if jsonErr := json.Unmarshal(body, &errResp); jsonErr == nil && errResp.Error.Message != "" { return fmt.Errorf("api error (%d): %s", errResp.Error.Code, errResp.Error.Message) } return fmt.Errorf("api request failed with status %d: %s", resp.StatusCode, string(body)) } if err := json.Unmarshal(body, result); err != nil { return fmt.Errorf("failed to unmarshal response: %v", err) } return nil }
SubmitQuery sends the QueryRequest to the Bible API and unmarshals the response into result. result should be a pointer to the expected response struct.
var VERSIONS = map[string]string{
"NIV": "NIV",
"ESV": "ESV",
"KJV": "KJV",
"NASB": "NASB",
"NLT": "NLT",
"AMP": "AMP",
}
Functions ¶
func AcronymizeDevo ¶
func CheckBibleReference ¶
CheckBibleReference validates if the string is a valid Bible reference using local logic.
func CleanPassageText ¶
func CloseAction ¶
func CloseAction(env def.SessionData) def.SessionData
func DumpUserList ¶
func DumpUserList(env def.SessionData) def.SessionData
func ExpandDevo ¶
func ExtractBibleReferences ¶
ExtractBibleReferences extracts all valid Bible references from a text.
func FormatQuery ¶
func FormatQuery(query string, t TMSQueryType) string
func GetBibleAsk ¶
func GetBibleAsk(env def.SessionData) def.SessionData
func GetBibleAskWithContext ¶
func GetBibleAskWithContext(env def.SessionData, contextVerses []string) def.SessionData
func GetBiblePassage ¶
func GetBiblePassage(env def.SessionData) def.SessionData
func GetBiblePassageFallback ¶
func GetBiblePassageFallback(env def.SessionData) def.SessionData
func GetBibleSearch ¶
func GetBibleSearch(env def.SessionData) def.SessionData
func GetDailyNewTestamentReadingReferences ¶
func GetDailyNewTestamentReadingReferences(env def.SessionData) string
func GetDesiringGodArticles ¶
func GetDevo ¶
func GetDevo(env def.SessionData, bot platform.Platform) def.SessionData
func GetDevotionalData ¶
func GetDevotionalData(env def.SessionData, devo string) def.ResponseData
func GetDevotionalText ¶
func GetDiscipleshipJournalReferences ¶
func GetDiscipleshipJournalReferences(env def.SessionData) []def.Option
func GetMCheyneHtml ¶
func GetMCheyneReferences ¶
func GetNavigators5xReferences ¶
func GetNavigators5xReferences(env def.SessionData) string
func GetNavigators5xRestDayPrompt ¶
func GetNavigators5xRestDayPrompt(env def.SessionData) (string, []def.Option)
func GetRandomTMSVerse ¶
func GetRandomTMSVerse(env def.SessionData) string
func GetReference ¶
func GetTMSVerse ¶
func GetTMSVerse(env def.SessionData) def.SessionData
func Migrate ¶
func Migrate(env def.SessionData) def.SessionData
func MockSubmitQuery ¶
func MockSubmitQuery(t HelperT, callback func(QueryRequest)) func(QueryRequest, interface{}) error
MockSubmitQuery is a helper to mock SubmitQuery for testing purposes. It captures the request in a closure and allows verifying it.
func ParseBibleReference ¶
ParseBibleReference parses a string to identify and normalize a Bible reference. It returns the normalized reference string and a boolean indicating validity.
func ParseBibleReferenceFromStart ¶
ParseBibleReferenceFromStart attempts to parse a Bible reference at the beginning of the string. Returns the normalized reference, the length of text consumed from input, and whether a match was found.
func ParseNodesForPassage ¶
func ParsePassageFromHtml ¶
func ProcessCommand ¶
func ProcessCommand(env def.SessionData, bot platform.Platform) def.SessionData
func ProcessNaturalLanguage ¶
func ProcessNaturalLanguage(env def.SessionData) def.SessionData
func QueryTMSPack ¶
func QueryTMSPack(db TMSDatabase, p PackSelector) (TMSPack, TMSVerse, error)
func QueryTMSSeries ¶
func QueryTMSSeries(db TMSDatabase, s SeriesSelector) (TMSPack, TMSVerse, error)
func QueryTMSVerse ¶
func QueryTMSVerse(db TMSDatabase, v VerseSelector) (TMSPack, TMSVerse, error)
func ResetAPIConfigCache ¶
func ResetAPIConfigCache()
ResetAPIConfigCache invalidates the cache, forcing a reload on next call. This is primarily for testing purposes.
func SanitizeVersion ¶
func SetAPIConfigOverride ¶
func SetAPIConfigOverride(url, key string)
SetAPIConfigOverride forces the configuration to use the provided values. This is intended for testing or manual configuration.
func SetEnv ¶
func SetEnv(key, value string) func()
SetEnv is a helper function to temporarily set an environment variable and return a function to restore it.
func SetVersion ¶
func SetVersion(env def.SessionData) def.SessionData
func UnsetEnv ¶
func UnsetEnv(key string) func()
UnsetEnv is a helper function to temporarily unset an environment variable and return a function to restore it.
func UpdateSubscription ¶
func UpdateSubscription(env def.SessionData) def.SessionData
Types ¶
type BibleReadingPlanChapter ¶
type BibleReadingPlanChapter struct {
Verses string `yaml:"Verses,flow"`
}
type BibleReadingPlanDevo ¶
type BibleReadingPlanDevo struct {
Verses []string `yaml:"Verses,flow"`
}
type DailyBRP ¶
type DailyBRP struct {
BibleReadingPlan []BibleReadingPlanDevo `yaml:"BibleReadingPlan"`
}
type DailyChapterBRP ¶
type DailyChapterBRP struct {
BibleReadingPlan []BibleReadingPlanChapter `yaml:"BibleReadingPlan"`
}
func GetDailyNewTestamentDatabase ¶
func GetDailyNewTestamentDatabase(dataPath string) DailyChapterBRP
func GetNavigators5xDatabase ¶
func GetNavigators5xDatabase(dataPath string) DailyChapterBRP
type ErrorDetails ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetails `json:"error"`
}
type HelperT ¶
type HelperT interface {
Helper()
Errorf(format string, args ...interface{})
}
HelperT is an interface to allow passing *testing.T
type OQueryResponse ¶
type OQueryResponse struct {
Text string `json:"text"`
References []SearchResult `json:"references"`
}
type PackSelector ¶
type QueryContext ¶
type QueryContext struct {
History []string `json:"history,omitempty"`
Schema string `json:"schema,omitempty"`
Verses []string `json:"verses,omitempty"`
Words []string `json:"words,omitempty"`
User UserContext `json:"user,omitempty"`
}
type QueryObject ¶
type QueryRequest ¶
type QueryRequest struct {
Query QueryObject `json:"query"`
Context QueryContext `json:"context,omitempty"`
}
type SearchResult ¶
type SeriesSelector ¶
type TMSDatabase ¶
type TMSDatabase struct {
Series []TMSSeries `yaml:"Series"`
}
func GetTMSData ¶
func GetTMSData(dataPath string) TMSDatabase
type TMSQueryType ¶
type TMSQueryType string
const ( ID TMSQueryType = "ID" Tag TMSQueryType = "Tag" Reference TMSQueryType = "Reference" Null TMSQueryType = "0" )
func IdentifyQuery ¶
func IdentifyQuery(db TMSDatabase, query string) TMSQueryType
type UserContext ¶
type UserContext struct {
Version string `json:"version,omitempty"`
}
type VerseResponse ¶
type VerseResponse struct {
Verse string `json:"verse"`
}
type VerseSelector ¶
type WordSearchResponse ¶
type WordSearchResponse []SearchResult
WordSearchResponse is a list of SearchResults