forked from 0x263b/Porygon2
/
lean.go
44 lines (39 loc) · 803 Bytes
/
lean.go
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
39
40
41
42
43
44
package lean
import (
"fmt"
"github.com/Seventy-Two/Cara"
"math/rand"
"time"
"os"
"bufio"
"github.com/kardianos/osext"
)
const (
leanPath = "\\leanlines"
)
func random(min, max int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(max-min) + min
}
func leandoer(command *bot.Cmd, matches []string) (msg string, err error) {
dir, _ := osext.ExecutableFolder()
quotePath := fmt.Sprintf("%s%s", dir, leanPath)
file, err := os.Open(quotePath)
if err != nil {
return "", nil
}
defer file.Close()
var choices []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
choices = append(choices, scanner.Text())
}
chosen := random(0, len(choices))
msg = fmt.Sprintf("%s", choices[chosen])
return
}
func init() {
bot.RegisterCommand(
"^lean$",
leandoer)
}