summaryrefslogtreecommitdiffstats
path: root/bot/papiez.go
blob: 1f028b8cccd990a143404b2ed6fa203ef6c0c8c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package bot

import (
	"log"
	"math/rand"
	"strings"
	"time"

	"github.com/arachnist/gorepost/irc"
)

var adverbs []string

func papiez(output func(irc.Message), msg irc.Message) {
	args := strings.Split(msg.Trailing, " ")
	if args[0] != ":papiez" && args[0] != ":papież" {
		return
	}

	choice := "Papież " + adverbs[rand.Intn(len(adverbs))]

	output(reply(msg, choice))
}

func init() {
	var err error
	rand.Seed(time.Now().UnixNano())
	adverbs, err = readLines("/home/repost/przymiotniki")
	if err != nil {
		log.Println("failed to read adverbs", err)
		return
	}
	addCallback("PRIVMSG", "papiez", papiez)
}