pull/1/head
vilmibm 2023-02-21 03:56:19 +00:00
parent f579c811f3
commit cb83223ab8
2 changed files with 18 additions and 9 deletions

View File

@ -20,7 +20,7 @@ import (
const ( const (
maxInputLength = 10000 maxInputLength = 10000
logDir = "/town/var/signup" logDir = "/town/var/signups/log"
) )
type scene struct { type scene struct {
@ -260,8 +260,7 @@ func _main(l *log.Logger, db *signup.DB) error {
sceneIx := 0 sceneIx := 0
currentScene := scenes[sceneIx] currentScene := scenes[sceneIx]
inputBuff := []byte{} inputWriter := bytes.NewBuffer([]byte{})
inputWriter := bytes.NewBuffer(inputBuff)
advanceScene := func(fromScene, sorryMsg string) { advanceScene := func(fromScene, sorryMsg string) {
if currentScene.Name != fromScene { if currentScene.Name != fromScene {
@ -271,9 +270,10 @@ func _main(l *log.Logger, db *signup.DB) error {
fmt.Fprintln(msgScroll, currentScene.Host.Say(sorryMsg)) fmt.Fprintln(msgScroll, currentScene.Host.Say(sorryMsg))
return return
} }
currentScene.Write(inputBuff) l.Println("advancing scene")
inputBuff = []byte{}
inputWriter = bytes.NewBuffer(inputBuff) currentScene.Write(inputWriter.Bytes())
inputWriter = bytes.NewBuffer([]byte{})
sceneIx++ sceneIx++
currentScene = scenes[sceneIx] currentScene = scenes[sceneIx]
fmt.Fprintln(msgScroll, heredoc.Doc(` fmt.Fprintln(msgScroll, heredoc.Doc(`
@ -325,9 +325,10 @@ func _main(l *log.Logger, db *signup.DB) error {
defer func() { defer func() {
if currentScene.Name == "done" { if currentScene.Name == "done" {
currentScene.Write(inputBuff) currentScene.Write(inputWriter.Bytes())
db.UpdateSignup(su) db.UpdateSignup(su)
} }
db.Close()
}() }()
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {

View File

@ -2,8 +2,9 @@ package signup
import ( import (
"database/sql" "database/sql"
_ "github.com/mattn/go-sqlite3"
"time" "time"
_ "github.com/mattn/go-sqlite3"
) )
type AdminNote struct { type AdminNote struct {
@ -51,7 +52,7 @@ type DB struct {
} }
func NewDB() (*DB, error) { func NewDB() (*DB, error) {
db, err := sql.Open("sqlite3", "/town/var/signups.db") db, err := sql.Open("sqlite3", "/town/var/signups/signups.db?mode=rw")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,6 +77,8 @@ func (d *DB) InsertSignup(su *TownSignup) error {
return err return err
} }
defer stmt.Close()
liid, err := result.LastInsertId() liid, err := result.LastInsertId()
if err != nil { if err != nil {
return err return err
@ -103,6 +106,11 @@ func (d *DB) UpdateSignup(su *TownSignup) error {
if err != nil { if err != nil {
return err return err
} }
defer stmt.Close()
return nil return nil
} }
func (d *DB) Close() error {
return d.db.Close()
}