From 42aa0232060906e1f343d83bae35f41b60883b00 Mon Sep 17 00:00:00 2001 From: julwrites Date: Fri, 28 Nov 2025 21:20:04 +0800 Subject: [PATCH 01/11] Removing unneeded helper functions --- pkg/app/passage.go | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index 4b4c957..c94009f 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -44,33 +44,6 @@ func GetReference(doc *html.Node) string { } - -// Helper functions for parsing -func isFormattingTag(tag string) bool { - return tag == "sup" || tag == "i" || tag == "b" -} - -func isHeaderTag(tag string) bool { - return tag == "h1" || tag == "h2" || tag == "h3" || tag == "h4" -} - -func wrapText(text, tag string) string { - if strings.TrimSpace(text) == "" { - return text - } - - if tag == "sup" { - return platform.TelegramSuperscript(strings.Trim(text, " ")) - } - if tag == "i" { - return platform.TelegramItalics(text) - } - if tag == "b" || isHeaderTag(tag) { - return platform.TelegramBold(text) - } - return text -} - func ParseNodesForPassage(node *html.Node) string { var text string var parts []string From a504203b918794ac848cce281a9a570aad6fceea Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:30:42 +0800 Subject: [PATCH 02/11] Fixing mismatched calls --- pkg/app/passage.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index c94009f..b2dd74e 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -12,7 +12,6 @@ import ( "golang.org/x/net/html" "github.com/julwrites/BotPlatform/pkg/def" - "github.com/julwrites/BotPlatform/pkg/platform" "github.com/julwrites/ScriptureBot/pkg/utils" ) @@ -97,7 +96,7 @@ func ParseNodesForPassage(node *html.Node) string { } func GetPassage(ref string, doc *html.Node, version string) string { - filtNodes := utils.FilterTree(passageNode, func(child *html.Node) bool { + filtNodes := utils.FilterTree(doc, func(child *html.Node) bool { switch tag := child.Data; tag { case "h1": fallthrough @@ -143,7 +142,11 @@ func ParsePassageFromHtml(rawHtml string) string { } func GetBiblePassageFallback(env def.SessionData) def.SessionData { + config := utils.DeserializeUserConfig(env.User.Config) + doc := GetPassageHTML(env.Msg.Message, config.Version) + ref := GetReference(doc) + if doc == nil { env.Res.Message = "Sorry, I couldn't retrieve that passage. Please check the reference or try again later." return env From 16c4d0264eeded94b811211d148daa7414a8a7a8 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:35:52 +0800 Subject: [PATCH 03/11] Fixing more mismatch --- pkg/app/passage.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index b2dd74e..2a80a32 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -130,7 +130,7 @@ func GetPassage(ref string, doc *html.Node, version string) string { return passage.String() } -func ParsePassageFromHtml(rawHtml string) string { +func ParsePassageFromHtml(ref string, rawHtml string, version string) string { doc, err := html.Parse(strings.NewReader(rawHtml)) if err != nil { @@ -138,7 +138,7 @@ func ParsePassageFromHtml(rawHtml string) string { return rawHtml } - return strings.TrimSpace(GetPassage(doc)) + return strings.TrimSpace(GetPassage(ref, doc, version)) } func GetBiblePassageFallback(env def.SessionData) def.SessionData { @@ -156,7 +156,7 @@ func GetBiblePassageFallback(env def.SessionData) def.SessionData { passageNode, startErr := utils.FindByClass(doc, "passage-text") if startErr != nil { log.Printf("Error parsing for passage: %v", startErr) - return "" + return env } // Attempt to get the passage @@ -199,7 +199,7 @@ func GetBiblePassage(env def.SessionData) def.SessionData { } if len(resp.Verse) > 0 { - env.Res.Message = ParsePassageFromHtml(resp.Verse) + env.Res.Message = ParsePassageFromHtml(ref. resp.Verse, config.Version) } } From 41594dd3e3377152c74929bfa482a9a2ddbe5fee Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:37:21 +0800 Subject: [PATCH 04/11] Fixing a typo --- pkg/app/passage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index 2a80a32..faa819f 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -199,7 +199,7 @@ func GetBiblePassage(env def.SessionData) def.SessionData { } if len(resp.Verse) > 0 { - env.Res.Message = ParsePassageFromHtml(ref. resp.Verse, config.Version) + env.Res.Message = ParsePassageFromHtml(ref, resp.Verse, config.Version) } } From b38e1aa5b6eef9551f223155c2beb5643e7ee277 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:44:29 +0800 Subject: [PATCH 05/11] Fixing tests --- pkg/app/passage_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index 8a1e85e..6285451 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -79,7 +79,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Valid HTML with superscript", func(t *testing.T) { html := `

12 But to all who did receive him, who believed in his name, he gave the right to become children of God,

` expected := `¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("John 1:12", html, "ESV"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -87,7 +87,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with italics", func(t *testing.T) { html := `

This is italic.

` expected := `_This is italic._` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestItalics", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -95,7 +95,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with bold", func(t *testing.T) { html := `

This is bold.

` expected := `*This is bold.*` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestBold", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -103,7 +103,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with line breaks", func(t *testing.T) { html := `

Line 1.
Line 2.

` expected := "Line 1.\nLine 2." - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestLB", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -111,7 +111,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Invalid HTML", func(t *testing.T) { html := `

This is malformed HTML` expected := `This is malformed HTML` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestNEG", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -119,7 +119,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Nested HTML tags", func(t *testing.T) { html := `

This is bold, and this is italic.

` expected := `*This is bold, *_and this is italic._` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestNest", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -131,7 +131,7 @@ func TestParsePassageFromHtml(t *testing.T) { // For now, we expect them to be returned raw. html := `

This has special characters: *_. [hello](world)!

` expected := `This has special characters: *_. [hello](world)!` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestMD", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -139,7 +139,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Backslash escaping", func(t *testing.T) { html := `added to you\.` expected := `added to you\.` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestESC", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -147,7 +147,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Dot escaping", func(t *testing.T) { html := `heaven.` expected := `heaven.` - if got := ParsePassageFromHtml(html); got != expected { + if got := ParsePassageFromHtml("TestDOT", html, "TEST"); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) From 4c243043455a455f15ac775b6d6132b26a35d82d Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:48:19 +0800 Subject: [PATCH 06/11] The test expects empty verse ref and version --- pkg/app/passage_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index 6285451..7e42062 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -79,7 +79,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Valid HTML with superscript", func(t *testing.T) { html := `

12 But to all who did receive him, who believed in his name, he gave the right to become children of God,

` expected := `¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` - if got := ParsePassageFromHtml("John 1:12", html, "ESV"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -87,7 +87,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with italics", func(t *testing.T) { html := `

This is italic.

` expected := `_This is italic._` - if got := ParsePassageFromHtml("TestItalics", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -95,7 +95,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with bold", func(t *testing.T) { html := `

This is bold.

` expected := `*This is bold.*` - if got := ParsePassageFromHtml("TestBold", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -103,7 +103,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with line breaks", func(t *testing.T) { html := `

Line 1.
Line 2.

` expected := "Line 1.\nLine 2." - if got := ParsePassageFromHtml("TestLB", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -111,7 +111,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Invalid HTML", func(t *testing.T) { html := `

This is malformed HTML` expected := `This is malformed HTML` - if got := ParsePassageFromHtml("TestNEG", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -119,7 +119,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Nested HTML tags", func(t *testing.T) { html := `

This is bold, and this is italic.

` expected := `*This is bold, *_and this is italic._` - if got := ParsePassageFromHtml("TestNest", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -131,7 +131,7 @@ func TestParsePassageFromHtml(t *testing.T) { // For now, we expect them to be returned raw. html := `

This has special characters: *_. [hello](world)!

` expected := `This has special characters: *_. [hello](world)!` - if got := ParsePassageFromHtml("TestMD", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -139,7 +139,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Backslash escaping", func(t *testing.T) { html := `added to you\.` expected := `added to you\.` - if got := ParsePassageFromHtml("TestESC", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) @@ -147,7 +147,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Dot escaping", func(t *testing.T) { html := `heaven.` expected := `heaven.` - if got := ParsePassageFromHtml("TestDOT", html, "TEST"); got != expected { + if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) From 6f5672a2f38155eabceb2bedd811513260767295 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:51:53 +0800 Subject: [PATCH 07/11] Trying to add the supposed empty refernce and version --- pkg/app/passage_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index 7e42062..81148e6 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -78,7 +78,7 @@ func TestGetBiblePassage(t *testing.T) { func TestParsePassageFromHtml(t *testing.T) { t.Run("Valid HTML with superscript", func(t *testing.T) { html := `

12 But to all who did receive him, who believed in his name, he gave the right to become children of God,

` - expected := `¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` + expected := `__ ()\n¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -86,7 +86,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with italics", func(t *testing.T) { html := `

This is italic.

` - expected := `_This is italic._` + expected := `__ ()\n_This is italic._` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -94,7 +94,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with bold", func(t *testing.T) { html := `

This is bold.

` - expected := `*This is bold.*` + expected := `__ ()\n*This is bold.*` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -102,7 +102,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with line breaks", func(t *testing.T) { html := `

Line 1.
Line 2.

` - expected := "Line 1.\nLine 2." + expected := "__ ()\nLine 1.\nLine 2." if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -110,7 +110,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Invalid HTML", func(t *testing.T) { html := `

This is malformed HTML` - expected := `This is malformed HTML` + expected := `__ ()\nThis is malformed HTML` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -118,7 +118,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Nested HTML tags", func(t *testing.T) { html := `

This is bold, and this is italic.

` - expected := `*This is bold, *_and this is italic._` + expected := `__ ()\n*This is bold, *_and this is italic._` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -130,7 +130,7 @@ func TestParsePassageFromHtml(t *testing.T) { // However, returning raw characters like * might cause issues if not handled by platform. // For now, we expect them to be returned raw. html := `

This has special characters: *_. [hello](world)!

` - expected := `This has special characters: *_. [hello](world)!` + expected := `__ ()\nThis has special characters: *_. [hello](world)!` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -138,7 +138,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Backslash escaping", func(t *testing.T) { html := `added to you\.` - expected := `added to you\.` + expected := `__ ()\nadded to you\.` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -146,7 +146,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Dot escaping", func(t *testing.T) { html := `heaven.` - expected := `heaven.` + expected := `__ ()\nheaven.` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } From 8dabe957bab5d8f83f3978e96b27a74cf6246968 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 00:56:45 +0800 Subject: [PATCH 08/11] Disabling the reference and version if empty reference --- pkg/app/passage.go | 6 ++++-- pkg/app/passage_test.go | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index faa819f..7722bba 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -119,8 +119,10 @@ func GetPassage(ref string, doc *html.Node, version string) string { var passage strings.Builder - refString := fmt.Sprintf("_%s_ (%s)", ref, version) - passage.WriteString(refString) + if len(ref) > 0 { + refString := fmt.Sprintf("_%s_ (%s)", ref, version) + passage.WriteString(refString) + } for _, block := range textBlocks { passage.WriteString("\n") diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index 81148e6..7e42062 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -78,7 +78,7 @@ func TestGetBiblePassage(t *testing.T) { func TestParsePassageFromHtml(t *testing.T) { t.Run("Valid HTML with superscript", func(t *testing.T) { html := `

12 But to all who did receive him, who believed in his name, he gave the right to become children of God,

` - expected := `__ ()\n¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` + expected := `¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -86,7 +86,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with italics", func(t *testing.T) { html := `

This is italic.

` - expected := `__ ()\n_This is italic._` + expected := `_This is italic._` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -94,7 +94,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with bold", func(t *testing.T) { html := `

This is bold.

` - expected := `__ ()\n*This is bold.*` + expected := `*This is bold.*` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -102,7 +102,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with line breaks", func(t *testing.T) { html := `

Line 1.
Line 2.

` - expected := "__ ()\nLine 1.\nLine 2." + expected := "Line 1.\nLine 2." if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -110,7 +110,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Invalid HTML", func(t *testing.T) { html := `

This is malformed HTML` - expected := `__ ()\nThis is malformed HTML` + expected := `This is malformed HTML` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -118,7 +118,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Nested HTML tags", func(t *testing.T) { html := `

This is bold, and this is italic.

` - expected := `__ ()\n*This is bold, *_and this is italic._` + expected := `*This is bold, *_and this is italic._` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -130,7 +130,7 @@ func TestParsePassageFromHtml(t *testing.T) { // However, returning raw characters like * might cause issues if not handled by platform. // For now, we expect them to be returned raw. html := `

This has special characters: *_. [hello](world)!

` - expected := `__ ()\nThis has special characters: *_. [hello](world)!` + expected := `This has special characters: *_. [hello](world)!` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -138,7 +138,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Backslash escaping", func(t *testing.T) { html := `added to you\.` - expected := `__ ()\nadded to you\.` + expected := `added to you\.` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -146,7 +146,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Dot escaping", func(t *testing.T) { html := `heaven.` - expected := `__ ()\nheaven.` + expected := `heaven.` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } From d06f80204152108f5a487532a18aecfaf573f611 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 01:04:52 +0800 Subject: [PATCH 09/11] Adding italics and bold based on telegram formatting --- pkg/app/passage.go | 7 ++++++- pkg/app/passage_test.go | 18 +----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index 7722bba..94fc5b7 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -12,6 +12,7 @@ import ( "golang.org/x/net/html" "github.com/julwrites/BotPlatform/pkg/def" + "github.com/julwrites/BotPlatform/pkg/platform" "github.com/julwrites/ScriptureBot/pkg/utils" ) @@ -76,9 +77,13 @@ func ParseNodesForPassage(node *html.Node) string { } break case "p": - case "i": parts = append(parts, ParseNodesForPassage(child)) break + case "b": + parts = append(parts, platform.TelegramBold(ParseNodesForPassage(child))) + case "i": + parts = append(parts, platform.TelegramItalics(ParseNodesForPassage(child))) + break case "br": parts = append(parts, "\n") break diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index 7e42062..e5588a2 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -78,7 +78,7 @@ func TestGetBiblePassage(t *testing.T) { func TestParsePassageFromHtml(t *testing.T) { t.Run("Valid HTML with superscript", func(t *testing.T) { html := `

12 But to all who did receive him, who believed in his name, he gave the right to become children of God,

` - expected := `¹²But to all who did receive him, who believed in his name, he gave the right to become children of God,` + expected := `^12^But to all who did receive him, who believed in his name, he gave the right to become children of God,` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } @@ -135,22 +135,6 @@ func TestParsePassageFromHtml(t *testing.T) { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } }) - - t.Run("Backslash escaping", func(t *testing.T) { - html := `added to you\.` - expected := `added to you\.` - if got := ParsePassageFromHtml("", html, ""); got != expected { - t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) - } - }) - - t.Run("Dot escaping", func(t *testing.T) { - html := `heaven.` - expected := `heaven.` - if got := ParsePassageFromHtml("", html, ""); got != expected { - t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) - } - }) } func TestCheckBibleReference(t *testing.T) { From bb98a17ad715f6920f5b6d3581c4ddaca02504c0 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 01:07:05 +0800 Subject: [PATCH 10/11] Fixing test data --- pkg/app/passage_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index e5588a2..085c6ca 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -118,7 +118,7 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("Nested HTML tags", func(t *testing.T) { html := `

This is bold, and this is italic.

` - expected := `*This is bold, *_and this is italic._` + expected := `*This is bold, _and this is italic._*` if got := ParsePassageFromHtml("", html, ""); got != expected { t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected) } From bcbfbdbca770d5c9694e168a68700af2ea741333 Mon Sep 17 00:00:00 2001 From: julwrites Date: Sat, 29 Nov 2025 01:11:13 +0800 Subject: [PATCH 11/11] Returning if bible passage is valid --- pkg/app/passage.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/app/passage.go b/pkg/app/passage.go index 94fc5b7..58bae8d 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -182,6 +182,7 @@ func GetBiblePassage(env def.SessionData) def.SessionData { // If indeed a reference, attempt to query if len(ref) > 0 { + log.Printf("%s", ref); // Attempt to retrieve from API req := QueryRequest{ @@ -207,6 +208,7 @@ func GetBiblePassage(env def.SessionData) def.SessionData { if len(resp.Verse) > 0 { env.Res.Message = ParsePassageFromHtml(ref, resp.Verse, config.Version) + return env } }