Compare commits
2 Commits
c02e4a48da
...
b48165fa0a
Author | SHA1 | Date | |
---|---|---|---|
b48165fa0a | |||
a35f0cd39a |
@ -1,12 +1,15 @@
|
||||
FROM golang:1.15 as builder
|
||||
|
||||
RUN mkdir /build
|
||||
ADD . /build/
|
||||
WORKDIR /build
|
||||
RUN find /
|
||||
RUN make build
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=builder /build/sco /app/main
|
||||
COPY --from=builder /build /archive/build
|
||||
COPY --from=builder /go /goarchive
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["./main"]
|
||||
|
2
Makefile
2
Makefile
@ -1,4 +1,5 @@
|
||||
VERSION := $(shell git rev-parse --short HEAD)
|
||||
COMMIT := $(shell git log --pretty=format:"%H" -1)
|
||||
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
|
||||
BUILDTIMEFILENAME := $(shell date -u '+%Y%m%d-%H%M%SZ')
|
||||
BUILDTIMETAG := $(shell date -u '+%Y%m%d%H%M%S')
|
||||
@ -12,6 +13,7 @@ IMAGENAME := sneak/$(FN)
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
GOLDFLAGS += -X main.Version=$(VERSION)
|
||||
GOLDFLAGS += -X main.Commit=$(COMMIT)
|
||||
GOLDFLAGS += -X main.Buildarch=$(BUILDARCH)
|
||||
|
||||
# osx can't statically link apparently?!
|
||||
|
25
bot/bot.go
25
bot/bot.go
@ -24,6 +24,7 @@ type Bot struct {
|
||||
DebuggingChannelName string
|
||||
TeamName string
|
||||
Version string
|
||||
Commit string
|
||||
WebsocketURL string
|
||||
StartupUnixTime int64
|
||||
client *model.Client4
|
||||
@ -70,7 +71,8 @@ func (b *Bot) Main() int {
|
||||
|
||||
// Lets create a bot channel for logging debug messages into
|
||||
b.CreateBotDebuggingChannelIfNeeded()
|
||||
b.SendMsgToDebuggingChannel("_"+b.BotName+" has **started** running_", "")
|
||||
msg := fmt.Sprintf("_**%s** has started up_\n\nrunning on version %s", b.BotName, b.Version)
|
||||
b.SendMsgToDebuggingChannel(msg, "")
|
||||
|
||||
// Lets start listening to some channels via the websocket!
|
||||
var err *model.AppError
|
||||
@ -223,6 +225,10 @@ func (b *Bot) HandleWebSocketResponse(event *model.WebSocketEvent) {
|
||||
|
||||
}
|
||||
|
||||
func (b *Bot) Shutdown() {
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
||||
}
|
||||
|
||||
func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
|
||||
|
||||
post := model.PostFromJson(strings.NewReader(event.Data["post"].(string)))
|
||||
@ -238,14 +244,13 @@ func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
|
||||
}
|
||||
|
||||
if matched, _ := regexp.MatchString(`(?:^|\W)version(?:$|\W)`, post.Message); matched {
|
||||
msg := fmt.Sprintf("I am running version `%s` from git: https://git.eeqj.de/sneak/sco", b.Version)
|
||||
msg := fmt.Sprintf("I am running version `%s` from git: https://git.eeqj.de/sneak/sco/src/commit/%s", b.Version, b.Commit)
|
||||
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
|
||||
return
|
||||
}
|
||||
|
||||
if matched, _ := regexp.MatchString(`(?:^|\W)uptime(?:$|\W)`, post.Message); matched {
|
||||
uptime := time.Now().Unix() - b.StartupUnixTime
|
||||
msg := fmt.Sprintf("running: uptime %d seconds", uptime)
|
||||
msg := fmt.Sprintf("running: uptime %d seconds", b.Uptime())
|
||||
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
|
||||
return
|
||||
}
|
||||
@ -254,6 +259,10 @@ func (b *Bot) HandleMsgFromChannel(event *model.WebSocketEvent) {
|
||||
|
||||
}
|
||||
|
||||
func (b *Bot) Uptime() int64 {
|
||||
return (time.Now().Unix() - b.StartupUnixTime)
|
||||
}
|
||||
|
||||
func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
|
||||
println("responding to debugging channel msg")
|
||||
|
||||
@ -262,8 +271,7 @@ func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
|
||||
|
||||
// ignore my events
|
||||
if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched {
|
||||
b.SendMsgToDebuggingChannel("i will now exit", post.Id)
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
||||
b.Shutdown()
|
||||
return
|
||||
}
|
||||
|
||||
@ -293,7 +301,6 @@ func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
|
||||
}
|
||||
|
||||
b.SendMsgToChannel("I did not understand your command, sorry", post.Id, post.ChannelId)
|
||||
//b.SendMsgToDebuggingChannel("I did not understand you!", post.Id)
|
||||
}
|
||||
|
||||
func PrintError(err *model.AppError) {
|
||||
@ -308,11 +315,11 @@ func (b *Bot) SetupGracefulShutdown() {
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for _ = range c {
|
||||
msg := fmt.Sprintf("_**%s** (version `%s`) is now shutting down_\n\nuptime was %d secs", b.BotName, b.Version, b.Uptime())
|
||||
b.SendMsgToDebuggingChannel(msg, "")
|
||||
if b.webSocketClient != nil {
|
||||
b.webSocketClient.Close()
|
||||
}
|
||||
|
||||
b.SendMsgToDebuggingChannel("_"+b.BotName+" has **stopped** running_", "")
|
||||
os.Exit(0)
|
||||
}
|
||||
}()
|
||||
|
@ -4,12 +4,14 @@ import "os"
|
||||
import "git.eeqj.de/sneak/sco/bot"
|
||||
|
||||
var Version string
|
||||
var Commit string
|
||||
var Buildarch string
|
||||
|
||||
func main() {
|
||||
mybot := bot.New(func(b *bot.Bot) {
|
||||
b.BotName = "lsvsco"
|
||||
b.Version = Version
|
||||
b.Commit = Commit
|
||||
b.Buildarch = Buildarch
|
||||
b.APIURL = os.Getenv("SCO_API_URL")
|
||||
b.TeamName = os.Getenv("SCO_TEAM_NAME")
|
||||
|
Loading…
Reference in New Issue
Block a user