forked from tildetown/town
working
parent
f579c811f3
commit
cb83223ab8
|
@ -20,7 +20,7 @@ import (
|
|||
|
||||
const (
|
||||
maxInputLength = 10000
|
||||
logDir = "/town/var/signup"
|
||||
logDir = "/town/var/signups/log"
|
||||
)
|
||||
|
||||
type scene struct {
|
||||
|
@ -260,8 +260,7 @@ func _main(l *log.Logger, db *signup.DB) error {
|
|||
sceneIx := 0
|
||||
currentScene := scenes[sceneIx]
|
||||
|
||||
inputBuff := []byte{}
|
||||
inputWriter := bytes.NewBuffer(inputBuff)
|
||||
inputWriter := bytes.NewBuffer([]byte{})
|
||||
|
||||
advanceScene := func(fromScene, sorryMsg string) {
|
||||
if currentScene.Name != fromScene {
|
||||
|
@ -271,9 +270,10 @@ func _main(l *log.Logger, db *signup.DB) error {
|
|||
fmt.Fprintln(msgScroll, currentScene.Host.Say(sorryMsg))
|
||||
return
|
||||
}
|
||||
currentScene.Write(inputBuff)
|
||||
inputBuff = []byte{}
|
||||
inputWriter = bytes.NewBuffer(inputBuff)
|
||||
l.Println("advancing scene")
|
||||
|
||||
currentScene.Write(inputWriter.Bytes())
|
||||
inputWriter = bytes.NewBuffer([]byte{})
|
||||
sceneIx++
|
||||
currentScene = scenes[sceneIx]
|
||||
fmt.Fprintln(msgScroll, heredoc.Doc(`
|
||||
|
@ -325,9 +325,10 @@ func _main(l *log.Logger, db *signup.DB) error {
|
|||
|
||||
defer func() {
|
||||
if currentScene.Name == "done" {
|
||||
currentScene.Write(inputBuff)
|
||||
currentScene.Write(inputWriter.Bytes())
|
||||
db.UpdateSignup(su)
|
||||
}
|
||||
db.Close()
|
||||
}()
|
||||
|
||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
|
|
|
@ -2,8 +2,9 @@ package signup
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type AdminNote struct {
|
||||
|
@ -51,7 +52,7 @@ type DB struct {
|
|||
}
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -76,6 +77,8 @@ func (d *DB) InsertSignup(su *TownSignup) error {
|
|||
return err
|
||||
}
|
||||
|
||||
defer stmt.Close()
|
||||
|
||||
liid, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -103,6 +106,11 @@ func (d *DB) UpdateSignup(su *TownSignup) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DB) Close() error {
|
||||
return d.db.Close()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue