1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
Former-commit-id: c3352889ee26c1497fae42710f5882bf433a1287 [formerly 6a2773cd3d65d7432e44df1f1f5152efae0730ae] [formerly 9a4189905703e691b3fd77af03f6628f722983f7 [formerly 17fa769f45fa3256274dccdeb852fa117c808122 [formerly 7e3423c12e]]]
Former-commit-id: 216a85e7fe40818bc67b031b6f03096e34ae3dea [formerly 2742f11d5436272ef272fda6161c40c366962618]
Former-commit-id: c008c65959d8e2cb62048665b69ff716da8b5813
Former-commit-id: 6d5b3e45c9
This commit is contained in:
Zack Scholl 2016-02-14 09:14:01 -05:00
parent 3b6086e083
commit 18839fe67b
4 changed files with 16042 additions and 7 deletions

18
db.go
View File

@ -179,12 +179,18 @@ func (p *WikiData) save(newText string) error {
} }
return err return err
}) })
err = db.Update(func(tx *bolt.Tx) error { // Add the new name to the programdata so its not randomly generated
b := tx.Bucket([]byte("programdata")) if err == nil {
id, _ := b.NextSequence() err2 := db.Update(func(tx *bolt.Tx) error {
idInt := int(id) b := tx.Bucket([]byte("programdata"))
return b.Put(itob(idInt), []byte(p.Title)) id, _ := b.NextSequence()
}) idInt := int(id)
return b.Put(itob(idInt), []byte(p.Title))
})
if err2 != nil {
return fmt.Errorf("could not add to programdata: %s", err)
}
}
return err return err
} }

16027
static/text/adjectives Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
ca5be314eff78cb57716e81faadb591fb9dc7f5e

View File

@ -44,6 +44,7 @@ func randomAdjective() string {
func randomAlliterateCombo() (combo string) { func randomAlliterateCombo() (combo string) {
combo = "" combo = ""
// first determine which names are taken from program data
takenNames := []string{} takenNames := []string{}
err := db.View(func(tx *bolt.Tx) error { err := db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys // Assume bucket exists and has keys
@ -57,6 +58,7 @@ func randomAlliterateCombo() (combo string) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
// generate random alliteration thats not been used
for { for {
animal := randomAnimal() animal := randomAnimal()
adjective := randomAdjective() adjective := randomAdjective()
@ -68,6 +70,7 @@ func randomAlliterateCombo() (combo string) {
return return
} }
// is there a string in a slice?
func stringInSlice(s string, strings []string) bool { func stringInSlice(s string, strings []string) bool {
for _, k := range strings { for _, k := range strings {
if s == k { if s == k {