From 2d91f0f60fc5b52d2428c31608de19bdda8f59e3 Mon Sep 17 00:00:00 2001 From: Henesy Date: Thu, 31 Mar 2022 03:24:46 +0000 Subject: [PATCH] oracle --- .gitignore | 1 + mux.go | 4 +++- x/mux/config.go | 2 +- x/mux/oracle.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 x/mux/oracle.go diff --git a/.gitignore b/.gitignore index 7598f4563b64e4a1b2c6da1c371617728ef7ee20..c1643b856153e59711202a239ecb5a434e486d90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ glenda cfg*/ *.log +oracledbs/ diff --git a/mux.go b/mux.go index 63615801d8a22b08cf93cb4038c063d148f6317d..3c4a15f1d3989e2c569fff7add5da050c3e2bfdf 100644 --- a/mux.go +++ b/mux.go @@ -62,7 +62,9 @@ func init() { Router.Route("uptime", "Current bot uptime", Router.Uptime) - Router.Route("gridlink", "Convert griddisk paths to 'incoming' URL's", Router.GridLink) + Router.Route("gridlink", "Convert griddisk paths to incoming URLs", Router.GridLink) Router.Route("roll", "Roll dice in the form XdY", Router.Roll) + + Router.Route("oracle", "Display oracle readings. Files are (papers fortunes fqa faust pooh).", Router.Oracle) } diff --git a/x/mux/config.go b/x/mux/config.go index d37d1f5e45eb9436bba56198ebeb413b41e19566..079a12aad653eb26f296364e96c59098c15d05ae 100644 --- a/x/mux/config.go +++ b/x/mux/config.go @@ -59,7 +59,7 @@ func (c *Configuration) Init(s *discordgo.Session) { "extrafortunes": "../sys/games/lib/fortunes", // Unix "fortunes": "/usr/share/mirror/plan9front/lib/", // Plan 9 - + "oracledbs": "./oracledbs/", // Vendored if you want it } // Regularly dump the config diff --git a/x/mux/oracle.go b/x/mux/oracle.go new file mode 100644 index 0000000000000000000000000000000000000000..f213fe8aef7171b830ddeee97c67c40470d7d015 --- /dev/null +++ b/x/mux/oracle.go @@ -0,0 +1,57 @@ +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" + } + + // Linux solution + var args []string + args = append(args, "-db", path + f, "-len", "30") + 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 +} + +