From 616c058806fd7fbabe381b04cb2d402435eb629e Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Mon, 14 Oct 2019 15:14:42 +0000 Subject: [PATCH] Update dockerfile to be based off of alpine Add fortune function --- Makefile | 3 +++ deps/Dockerfile | 10 ++++++---- lorebot/lorebot.go | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3a38242..faa9bd0 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ all: lorebot depends: go get github.com/nlopes/slack + go get github.com/unixvoid/glogger + go get gopkg.in/gcfg.v1 + go get gopkg.in/redis.v5 lorebot: $(GOC) lorebot/lorebot.go diff --git a/deps/Dockerfile b/deps/Dockerfile index 33414de..001fa25 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -1,8 +1,10 @@ -FROM scratch +FROM alpine -#RUN apk --update add ca-certificates redis -#RUN mkdir /redisbackup/ -ADD rootfs.tar.gz / +RUN apk --update add ca-certificates redis fortune +RUN mkdir /redisbackup/ +#RUN apk --update add fortune + +#ADD rootfs.tar.gz / COPY redis.conf / COPY config.gcfg / COPY lorebot / diff --git a/lorebot/lorebot.go b/lorebot/lorebot.go index edc8b0e..e83a8c5 100644 --- a/lorebot/lorebot.go +++ b/lorebot/lorebot.go @@ -10,6 +10,7 @@ import ( "net/http" "net/textproto" "os" + "os/exec" "strconv" "strings" "time" @@ -238,6 +239,8 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r dicerollhandler(rtm, ev) case "ceelo": ceelorollhandler(rtm, ev) + case "fortune": + fortunehandler(rtm, ev) case "listen": rtm.SendMessage(rtm.NewOutgoingMessage("*it's what you hearin*", ev.Channel)) case "lorelist": @@ -375,6 +378,17 @@ func ceelorollhandler(rtm *slack.RTM, ev *slack.MessageEvent) { } } +func fortunehandler(rtm *slack.RTM, ev *slack.MessageEvent) { + fortune, err := exec.Command("fortune").CombinedOutput() + if err != nil { + fmt.Printf("%v\n", err) + rtm.SendMessage(rtm.NewOutgoingMessage("Fortune command is broken, contact HFIC", ev.Channel)) + return + } + + rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%s", fortune), ev.Channel)) +} + func rrhandler(rtm *slack.RTM, ev *slack.MessageEvent) { //fmt.Print(rand.Intn(100)) dice := []string{"*click*", "*BANG*", "*click*", "*click*", "*click*", "*click*"}