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/proverbio.go

47 lines
1.1 KiB
Go
Raw Normal View History

2017-03-15 20:21:39 +00:00
package main
import (
"math/rand"
"strings"
"io/ioutil"
"log"
2018-11-08 18:55:34 +00:00
"git.fromouter.space/hamcha/tg"
2017-03-15 20:21:39 +00:00
)
type ProverbioData struct {
Inizio []string
Fine []string
}
var proverbipairs ProverbioData
2018-05-24 15:48:35 +00:00
func proverbio_init() {
2017-03-15 20:21:39 +00:00
data, err := ioutil.ReadFile(*proverbi)
assert(err)
lines := strings.Split(string(data), "\n")
for i, line := range lines {
pair := strings.SplitN(line, "/", 2)
if len(pair) < 2 {
log.Printf("[proverbio] Found line without separator (#%d), skipping\n", i)
continue
}
proverbipairs.Inizio = append(proverbipairs.Inizio, strings.TrimSpace(pair[0]))
proverbipairs.Fine = append(proverbipairs.Fine, strings.TrimSpace(pair[1]))
}
log.Printf("[proverbio] Loaded %d pairs (%d combinations!)\n", len(proverbipairs.Inizio), len(proverbipairs.Inizio)*len(proverbipairs.Fine))
}
2018-05-24 15:48:35 +00:00
func proverbio_message(broker *tg.Broker, update tg.APIMessage) {
2017-03-15 20:21:39 +00:00
if isCommand(update, "proverbio") {
n := rand.Intn(len(proverbipairs.Inizio))
m := rand.Intn(len(proverbipairs.Fine))
broker.SendTextMessage(update.Chat, "<b>Dice il saggio:</b>\n"+proverbipairs.Inizio[n]+" "+proverbipairs.Fine[m], nil)
return
}
}