package main import ( "log" "os" "strings" "io/ioutil" "path/filepath" "github.com/hamcha/clessy/tg" "github.com/zgiber/mctext" ) var orogen *mctext.MChain var orocorpus *strings.Reader func initoroscopo() { counter := 0 corpus := "" filepath.Walk(*oropath, func(path string, info os.FileInfo, err error) error { if info.IsDir() { return nil } data, err := ioutil.ReadFile(path) if err != nil { return err } corpus += string(data) counter++ return nil }) orocorpus = strings.NewReader(corpus) orogen := mctext.New() orogen.Parse(orocorpus) 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) idx := strings.LastIndexByte(txt, '.') if idx < 10 { continue } txt = txt[:idx] broker.SendTextMessage(update.Chat, "Ecco cosa dicono le stelle:\n"+txt, &update.MessageID) return } } }