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