Changing API library to telego.

This commit is contained in:
Benjamin A. Shelton 2026-09-10 22:31:23 -06:00
commit 7234cb2668
Signed by: zancarius
GPG key ID: 8BD42DBD6C337E01
6 changed files with 189 additions and 37 deletions

View file

@ -1,21 +1,66 @@
package bible
type Bible struct {
import (
"encoding/json"
"os"
)
type Bible struct {
}
type Metadata struct {
}
type Book struct {
}
type Chapter struct {
}
type VerseSpec struct {
}
}
type Scripture struct {
Verse string
Translation string
Content string
}
type ScriptureStore struct {
Verses []*Scripture
Offset int
}
func (s *ScriptureStore) GetVerse() *Scripture {
if s.Offset < len(s.Verses) {
s.Offset++
return s.Verses[s.Offset]
}
if len(s.Verses) > 0 {
s.Offset = 1
return s.Verses[0]
}
return &Scripture{
Verse: "3 John 11",
Translation: "BSB",
Content: "Beloved, do not imitate what is evil, but what is good. The one who does good is of God; the one who does evil has not seen God.",
}
}
func OpenStore(name string) (*ScriptureStore, error) {
s := &ScriptureStore{}
buf, err := os.ReadFile(name)
if err != nil {
return nil, err
}
err = json.Unmarshal(buf, *s)
return s, err
}
func SaveStore(name string, s *ScriptureStore) error {
buf, err := json.Marshal(s)
if err != nil {
return err
}
return os.WriteFile(name, buf, 0o644)
}

View file

@ -1,10 +1,13 @@
package settings
import (
"bytes"
"io/fs"
"os"
"github.com/pelletier/go-toml"
"git.destrealm.net/go/cwrap"
)
type Settings struct {
@ -12,6 +15,7 @@ type Settings struct {
DailyScripture DailyScripture `toml:"daily_scripture"`
System System
Translations Translations
Chat Chat
}
type API struct {
@ -21,8 +25,15 @@ type API struct {
User string
}
type Chat struct {
Channels []string `toml:"channels"`
}
type DailyScripture struct {
UserSubmitted bool `toml:"user_submitted"`
Schedule string
Rotation string
User string
}
type System struct {
@ -34,6 +45,21 @@ type Translations struct {
Active []string `toml:"active"`
}
func (c *Settings) Marshal() ([]byte, error) {
buf := &bytes.Buffer{}
enc := toml.NewEncoder(cwrap.New(buf))
enc.ArraysWithOneElementPerLine(true)
enc.Indentation(" ")
enc.Order(toml.OrderPreserve)
enc.PromoteAnonymous(false)
if err := enc.Encode(c); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func LoadSettings(name string) (*Settings, error) {
conf := &Settings{}
@ -52,3 +78,11 @@ func LoadSettings(name string) (*Settings, error) {
return conf, nil
}
func SaveSettings(name string, settings *Settings) error {
buf, err := settings.Marshal()
if err != nil {
return err
}
return os.WriteFile(name, buf, 0o644)
}