Compare commits

..

No commits in common. "b48165fa0a79d624e8861b6557d39372bd79ffd5" and "c02e4a48dae3c985d9bb5519ef62754c4d168fe2" have entirely different histories.

4 changed files with 11 additions and 25 deletions

View File

@ -1,15 +1,12 @@
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 /go /goarchive
COPY --from=builder /build /archive/build
WORKDIR /app
CMD ["./main"]

View File

@ -1,5 +1,4 @@
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')
@ -13,7 +12,6 @@ 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?!

View File

@ -24,7 +24,6 @@ type Bot struct {
DebuggingChannelName string
TeamName string
Version string
Commit string
WebsocketURL string
StartupUnixTime int64
client *model.Client4
@ -71,8 +70,7 @@ func (b *Bot) Main() int {
// Lets create a bot channel for logging debug messages into
b.CreateBotDebuggingChannelIfNeeded()
msg := fmt.Sprintf("_**%s** has started up_\n\nrunning on version %s", b.BotName, b.Version)
b.SendMsgToDebuggingChannel(msg, "")
b.SendMsgToDebuggingChannel("_"+b.BotName+" has **started** running_", "")
// Lets start listening to some channels via the websocket!
var err *model.AppError
@ -225,10 +223,6 @@ 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)))
@ -244,13 +238,14 @@ 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/src/commit/%s", b.Version, b.Commit)
msg := fmt.Sprintf("I am running version `%s` from git: https://git.eeqj.de/sneak/sco", b.Version)
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
return
}
if matched, _ := regexp.MatchString(`(?:^|\W)uptime(?:$|\W)`, post.Message); matched {
msg := fmt.Sprintf("running: uptime %d seconds", b.Uptime())
uptime := time.Now().Unix() - b.StartupUnixTime
msg := fmt.Sprintf("running: uptime %d seconds", uptime)
b.SendMsgToChannel(msg, post.Id, post.ChannelId)
return
}
@ -259,10 +254,6 @@ 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")
@ -271,7 +262,8 @@ func (b *Bot) HandleMsgFromDebuggingChannel(event *model.WebSocketEvent) {
// ignore my events
if matched, _ := regexp.MatchString(`(?:^|\W)shutdown(?:$|\W)`, post.Message); matched {
b.Shutdown()
b.SendMsgToDebuggingChannel("i will now exit", post.Id)
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
return
}
@ -301,6 +293,7 @@ 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) {
@ -315,11 +308,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)
}
}()

View File

@ -4,14 +4,12 @@ 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")