Merge pull request #87 from velour/fix_babbler_table

babbler: create tables no matter what
This commit is contained in:
Chris Sexton 2017-10-25 18:47:10 -04:00 committed by GitHub
commit ef1c3010c3
1 changed files with 33 additions and 35 deletions

View File

@ -56,7 +56,6 @@ type BabblerArc struct {
func New(bot bot.Bot) *BabblerPlugin { func New(bot bot.Bot) *BabblerPlugin {
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
if bot.DBVersion() == 1 {
if _, err := bot.DB().Exec(`create table if not exists babblers ( if _, err := bot.DB().Exec(`create table if not exists babblers (
id integer primary key, id integer primary key,
babbler string babbler string
@ -89,7 +88,6 @@ func New(bot bot.Bot) *BabblerPlugin {
);`); err != nil { );`); err != nil {
log.Fatal(err) log.Fatal(err)
} }
}
plugin := &BabblerPlugin{ plugin := &BabblerPlugin{
Bot: bot, Bot: bot,
@ -792,8 +790,8 @@ func (p *BabblerPlugin) babbleSeedSuffix(babblerName string, seed []string) (str
} }
} }
for i := 0; i < len(words) / 2; i++ { for i := 0; i < len(words)/2; i++ {
index := len(words)-(i+1) index := len(words) - (i + 1)
words[i], words[index] = words[index], words[i] words[i], words[index] = words[index], words[i]
} }
@ -864,8 +862,8 @@ func (p *BabblerPlugin) babbleSeedBookends(babblerName string, start, end []stri
previous *searchNode previous *searchNode
} }
open := []*searchNode{ &searchNode{startWordNode.NodeId, nil} } open := []*searchNode{&searchNode{startWordNode.NodeId, nil}}
closed := map[int64]*searchNode{ startWordNode.NodeId : open[0] } closed := map[int64]*searchNode{startWordNode.NodeId: open[0]}
goalNodeId := int64(-1) goalNodeId := int64(-1)
for i := 0; i < len(open) && i < 1000; i++ { for i := 0; i < len(open) && i < 1000; i++ {
@ -927,8 +925,8 @@ func (p *BabblerPlugin) babbleSeedBookends(babblerName string, start, end []stri
} }
} }
for i := 0; i < len(words) / 2; i++ { for i := 0; i < len(words)/2; i++ {
index := len(words)-(i+1) index := len(words) - (i + 1)
words[i], words[index] = words[index], words[i] words[i], words[index] = words[index], words[i]
} }