From 523523f0b357e45b397c6fed9ebc574efc61ed06 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Wed, 15 Mar 2017 21:21:39 +0100 Subject: [PATCH] I FORGOT THE MOD, SORRY SORRY --- mods/proverbio.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 mods/proverbio.go diff --git a/mods/proverbio.go b/mods/proverbio.go new file mode 100644 index 0000000..c027276 --- /dev/null +++ b/mods/proverbio.go @@ -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, "Dice il saggio:\n"+proverbipairs.Inizio[n]+" "+proverbipairs.Fine[m], nil) + return + } +}