oroscopo: DOES THIS WORK? GEE I WONDER
This commit is contained in:
parent
48ff3fe479
commit
44d3a4d18f
2 changed files with 61 additions and 0 deletions
|
@ -60,6 +60,10 @@ var mods = map[string]Mod{
|
||||||
OnInit: initsearch,
|
OnInit: initsearch,
|
||||||
OnMessage: search,
|
OnMessage: search,
|
||||||
},
|
},
|
||||||
|
"oroscopo": {
|
||||||
|
OnInit: initoroscopo,
|
||||||
|
OnMessage: oroscopo,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func initmods() {
|
func initmods() {
|
||||||
|
@ -104,6 +108,7 @@ var talktoken *string
|
||||||
var gapifile *string
|
var gapifile *string
|
||||||
var gapikey *string
|
var gapikey *string
|
||||||
var gapiCtx context.Context
|
var gapiCtx context.Context
|
||||||
|
var oropath *string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port")
|
brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port")
|
||||||
|
@ -117,6 +122,7 @@ func main() {
|
||||||
talktoken = flag.String("apiai", "@apiai.token", "api.ai token")
|
talktoken = flag.String("apiai", "@apiai.token", "api.ai token")
|
||||||
gapifile = flag.String("gapifile", "gapi.json", "Google API Service Credentials file (for STT)")
|
gapifile = flag.String("gapifile", "gapi.json", "Google API Service Credentials file (for STT)")
|
||||||
gapikey = flag.String("gapikey", "@gapi.key", "Google API key (for search/KG)")
|
gapikey = flag.String("gapikey", "@gapi.key", "Google API key (for search/KG)")
|
||||||
|
oropath = flag.String("oropath", "/astri", "Path to oroscopo corpus directory")
|
||||||
disable := flag.String("disable", "", "Blacklist mods (separated by comma)")
|
disable := flag.String("disable", "", "Blacklist mods (separated by comma)")
|
||||||
enable := flag.String("enable", "", "Whitelist mods (separated by comma)")
|
enable := flag.String("enable", "", "Whitelist mods (separated by comma)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
55
mods/oroscopo.go
Normal file
55
mods/oroscopo.go
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue