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