SHOULD WORK NOW

This commit is contained in:
Hamcha 2017-08-07 15:33:58 +02:00
parent 9685fc3449
commit 8c09558922
1 changed files with 9 additions and 9 deletions

View File

@ -13,7 +13,6 @@ import (
) )
var orogen *mctext.MChain var orogen *mctext.MChain
var orocorpus *strings.Reader
func initoroscopo() { func initoroscopo() {
counter := 0 counter := 0
@ -34,25 +33,26 @@ func initoroscopo() {
return nil return nil
}) })
orocorpus = strings.NewReader(corpus) orogen = mctext.New()
orogen.Parse(strings.NewReader(corpus))
orogen := mctext.New()
orogen.Parse(orocorpus)
log.Printf("[oroscopo] Loaded corpus from %d files\n", counter) log.Printf("[oroscopo] Loaded corpus from %d files\n", counter)
} }
func oroscopo(broker *tg.Broker, update tg.APIMessage) { func oroscopo(broker *tg.Broker, update tg.APIMessage) {
if isCommand(update, "oroscopo") { if isCommand(update, "oroscopo") {
for { txt := ""
txt := orogen.Generate("", 100) tries := 0
for tries < 10 {
txt = orogen.Generate("", 100)
idx := strings.LastIndexByte(txt, '.') idx := strings.LastIndexByte(txt, '.')
if idx < 10 { if idx < 10 {
tries++
continue continue
} }
txt = txt[:idx] txt = txt[:idx]
broker.SendTextMessage(update.Chat, "<b>Ecco cosa dicono le stelle:</b>\n"+txt, &update.MessageID) break
return
} }
broker.SendTextMessage(update.Chat, "<b>Ecco cosa dicono le stelle:</b>\n"+txt+".", &update.MessageID)
} }
} }