I FORGOT THE MOD, SORRY SORRY

This commit is contained in:
Hamcha 2017-03-15 21:21:39 +01:00
parent 701b87a5d2
commit 523523f0b3

46
mods/proverbio.go Normal file
View file

@ -0,0 +1,46 @@
package main
import (
"math/rand"
"strings"
"io/ioutil"
"log"
"github.com/hamcha/clessy/tg"
)
type ProverbioData struct {
Inizio []string
Fine []string
}
var proverbipairs ProverbioData
func initproverbio() {
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))
}
func proverbio(broker *tg.Broker, update tg.APIMessage) {
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
}
}