From 0f8947618dd176e53ef3d85d96c8973de296771d Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Fri, 26 Jan 2018 20:18:45 +0000 Subject: [PATCH] adding fortunes and some wordage --- README.md | 4 ++-- main.go | 9 +++------ mux.go | 3 +++ x/mux/fortunes.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ x/mux/help.go | 3 +-- x/mux/mux.go | 4 ++-- 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 x/mux/fortunes.go diff --git a/README.md b/README.md index 52d78d712e030e79a071f5840c411b4af961030a..270af12281791457cf39e52291f45d7ba1eb9dca 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ go get github.com/bwmarrin/discordgo ### Usage ``` -cd $GOPATH/src/github.com/bwmarrin/disgord +cd $GOPATH/src/bitbucket.org/henesy/glenda go build -./disgord -t 'Bot BOT_AUTH_TOKEN' +./glenda -t 'Bot BOT_AUTH_TOKEN' ``` ## Documentation diff --git a/main.go b/main.go index f50867d285d89cec3393309c22df1ad07308f6fd..4d190fa965dedc6e3ab9fa696a51f6dd92bc5ab9 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,5 @@ -// Declare this file to be part of the main package so it can be compiled into -// an executable. package main -// Import all Go packages required for this file. import ( "flag" "fmt" @@ -10,12 +7,10 @@ import ( "os" "os/signal" "syscall" - "github.com/bwmarrin/discordgo" ) -// Version is a constant that stores the Disgord version information. -const Version = "v0.0.0-alpha" +const Version = "v0.1.0-alpha" // Session is declared in the global space so it can be easily used // throughout this program. @@ -27,6 +22,7 @@ var Session, _ = discordgo.New() func init() { // Discord Authentication Token + // Have to prefix "Bot [Token Here]" or 401 Forbidden Session.Token = os.Getenv("DG_TOKEN") if Session.Token == "" { flag.StringVar(&Session.Token, "t", "", "Discord Authentication Token") @@ -89,3 +85,4 @@ func main() { // Exit Normally. } + diff --git a/mux.go b/mux.go index 60a637086841b9a24e7abc667c614a95ee044e33..cadbbcc5b0de03317acfcdef01e535ec7dd97382 100644 --- a/mux.go +++ b/mux.go @@ -17,4 +17,7 @@ func init() { // Register the build-in help command. Router.Route("help", "Display this message.", Router.Help) + + Router.Route("fortune", "Display fortunes.", Router.Fortunes) } + diff --git a/x/mux/fortunes.go b/x/mux/fortunes.go new file mode 100644 index 0000000000000000000000000000000000000000..ecb27b17fce564d58d1a64c8cfce4a7093d25f9c --- /dev/null +++ b/x/mux/fortunes.go @@ -0,0 +1,48 @@ +package mux + +import ( + "github.com/bwmarrin/discordgo" + "strings" + "os/exec" + "fmt" +) + +// Display fortunes from various 9front /lib/ files +func (m *Mux) Fortunes(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { + resp := "```\n" + + // Read relevant file + path := "/usr/share/mirror/plan9front/lib/" + + f := "" + if strings.Contains(dm.Content, "theo") { + f = "theo" + } else if strings.Contains(dm.Content, "troll") { + f = "troll" + } else if strings.Contains(dm.Content, "rsc") { + f = "rsc" + } else if strings.Contains(dm.Content, "bullshit") { + f = "bullshit" + } else if strings.Contains(dm.Content, "terry") { + f = "terry" + } else if strings.Contains(dm.Content, "rob") { + f = "rob" + } else { + f = "../sys/games/lib/fortunes" + } + + // Linux solution + out, err := exec.Command("fortune", path + f).Output() + if err != nil { + fmt.Println("Error calling fortune(1), see: x/mux/fortunes.go") + fmt.Println("%s\n", err) + } + resp += string(out) + + resp += "```\n" + + ds.ChannelMessageSend(dm.ChannelID, resp) + + return +} + diff --git a/x/mux/help.go b/x/mux/help.go index 1c1da57f64a925219fbbaab10b37174715c8f438..6fb1f37a39f889cda53307ca4ccd3107c117225c 100644 --- a/x/mux/help.go +++ b/x/mux/help.go @@ -4,7 +4,6 @@ import ( "fmt" "sort" "strconv" - "github.com/bwmarrin/discordgo" ) @@ -54,7 +53,7 @@ func (m *Mux) Help(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { sort.Strings(keys) // TODO: Learn more link needs to be configurable - resp := "\n*Commands can be abbreviated and mixed with other text. Learn more at *\n" + resp := "\n*Commands can be abbreviated and mixed with other text.*\n" resp += "```autoit\n" v, ok := cmdmap["help"] diff --git a/x/mux/mux.go b/x/mux/mux.go index bf7d1adc563faee00e730b6db4bb3db5d9ac59b5..db44a16d32ca1b89aeea6d46173cbd86e356217b 100644 --- a/x/mux/mux.go +++ b/x/mux/mux.go @@ -46,7 +46,7 @@ type Mux struct { // New returns a new Discord message route mux func New() *Mux { m := &Mux{} - m.Prefix = "-dg " + m.Prefix = "!g " return m } @@ -62,7 +62,7 @@ func (m *Mux) Route(pattern, desc string, cb HandlerFunc) (*Route, error) { return &r, nil } -// FuzzyMatch attepts to find the best route match for a givin message. +// FuzzyMatch attepts to find the best route match for a given message. func (m *Mux) FuzzyMatch(msg string) (*Route, []string) { // Tokenize the msg string into a slice of words