From c97576b6353dfece27760fd03f1f5ca5882e4936 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Mon, 7 Aug 2017 15:39:48 +0200 Subject: [PATCH] fuck that mctext thing --- mods/oroscopo.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mods/oroscopo.go b/mods/oroscopo.go index e5e919a..dd94817 100644 --- a/mods/oroscopo.go +++ b/mods/oroscopo.go @@ -9,14 +9,14 @@ import ( "path/filepath" "github.com/hamcha/clessy/tg" - "github.com/zgiber/mctext" + gomarkov "github.com/simon-weber/gomarkov" ) -var orogen *mctext.MChain +var orogen *gomarkov.Chain func initoroscopo() { counter := 0 - corpus := "" + orogen = gomarkov.NewChain() filepath.Walk(*oropath, func(path string, info os.FileInfo, err error) error { if info.IsDir() { return nil @@ -27,24 +27,27 @@ func initoroscopo() { return err } - corpus += string(data) + orogen.Update(string(data)) counter++ return nil }) - 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") { - txt := "" + var err error + var txt string tries := 0 for tries < 10 { - txt = orogen.Generate("", 100) + txt, err = orogen.Respond("", 20, 100) + if err != nil { + txt = err.Error() + tries++ + continue + } idx := strings.LastIndexByte(txt, '.') if idx < 10 { tries++