~kris/9p

glenda

glenda/x/mux/oracle.go -rw-r--r-- 1.2 KiB
48661367 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package mux

import (
	"github.com/bwmarrin/discordgo"
	"strings"
	"os/exec"
	"fmt"
)

// Display conjured fortunes from the oracle
// g!oracle papers factotum is
func (m *Mux) Oracle(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
	resp := "```\n"

	// Read relevant file
	path := Config.Db["oracledbs"]

	fields := strings.Fields(dm.Content)
	fields = fields[1:]
	f := "papers"
	prompt := []string{}
	if len(fields) > 1 {
		prompt = fields[1:]
	}

	if strings.Contains(dm.Content, "papers") {
		f = "papers"
	} else if strings.Contains(dm.Content, "fqa") {
		f = "fqa"
	} else if strings.Contains(dm.Content, "pooh") {
		f = "pooh"
	} else if strings.Contains(dm.Content, "faust") {
		f = "faust"
	} else if strings.Contains(dm.Content, "fortunes") {
		f = "fortunes"
	} else if strings.Contains(dm.Content, "commie") {
		f = "commie"
	}

	// Linux solution
	var args []string
	args = append(args, "-db", path + f, "-len", "20")
	args = append(args, prompt...)
	//fmt.Println(args)
	out, err := exec.Command("oracle", args...).Output()
	if err != nil {
		fmt.Println("Error calling oracle(1), see: x/mux/oracle.go")
		fmt.Println("%s\n", err)
	}
	resp += string(out)

	resp += "```\n"

	ds.ChannelMessageSend(dm.ChannelID, resp)

	return
}