Temporary implementation of scripture send.
This commit is contained in:
parent
a459018095
commit
3dc73e3572
2 changed files with 68 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"go.destrealm.net/logging/v3"
|
||||
"go.destrealm.net/vfs"
|
||||
|
||||
"code.destrealm.net/zancarius/justusbot/internal/bible"
|
||||
"code.destrealm.net/zancarius/justusbot/internal/models"
|
||||
"code.destrealm.net/zancarius/justusbot/internal/settings"
|
||||
)
|
||||
|
|
@ -77,7 +78,62 @@ func (a *App) loadEnv() error {
|
|||
}
|
||||
|
||||
func (a *App) scripture() {
|
||||
fmt.Println("scripture send triggered")
|
||||
fmt.Println("sending to chats:")
|
||||
chats, err := a.db.Chats().ListChats()
|
||||
if err == nil {
|
||||
for _, chat := range chats {
|
||||
fmt.Println(chat)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(" !!! error !!!")
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, chat := range chats {
|
||||
vv, err := a.db.Verses().RandomVerseForChat(chat.ID)
|
||||
if err != nil {
|
||||
fmt.Println("error retrieving random verse:", err)
|
||||
fmt.Println("chat ID:", chat.ID)
|
||||
return
|
||||
}
|
||||
ref := bible.NewBibleRef()
|
||||
ref.Book = vv.Book
|
||||
ref.Chapter = vv.Chapter
|
||||
ref.Verses.Start = vv.VerseStart
|
||||
ref.Verses.Stop = vv.VerseStop
|
||||
|
||||
tnfs := a.fs.Clone()
|
||||
if err := tnfs.Chdir("data"); err != nil {
|
||||
fmt.Println("unable to change dir:", err)
|
||||
return
|
||||
}
|
||||
tns, err := bible.LoadTranslations(tnfs)
|
||||
if err != nil {
|
||||
fmt.Println("unable to load translations:", err)
|
||||
return
|
||||
}
|
||||
if !tns.HasTranslation(vv.Translation) {
|
||||
fmt.Println("no such translation:", vv.Translation)
|
||||
return
|
||||
}
|
||||
bbl, err := tns.OpenBible(vv.Translation)
|
||||
if err != nil {
|
||||
fmt.Println("unable to open Bible:", err)
|
||||
return
|
||||
}
|
||||
|
||||
verse, err := bbl.FromRef(ref)
|
||||
if err != nil {
|
||||
fmt.Println("error reading verses:", err)
|
||||
return
|
||||
}
|
||||
|
||||
verse.SkipLineBreaks = true
|
||||
verse.IncludeVerseNum = false
|
||||
fmt.Println(verse.String())
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) Start(ctx context.Context, cmd *cli.Command) error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue