This repository has been archived on 2023-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
clessy/mods/oroscopo.go

56 lines
954 B
Go

package main
import (
"log"
"os"
"strings"
"io/ioutil"
"path/filepath"
"github.com/hamcha/clessy/tg"
"github.com/zgiber/mctext"
)
var orogen *mctext.MChain
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
})
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)
idx := strings.LastIndexByte(txt, '.')
if idx < 10 {
continue
}
txt = txt[:idx]
broker.SendTextMessage(update.Chat, "<b>Ecco cosa dicono le stelle:</b>\n"+txt, &update.MessageID)
return
}
}
}