diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 1ee4238..0000000 --- a/.drone.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -kind: pipeline -name: default - -workspace: - base: /go - path: src/github.com/lxbot/script-debug - -steps: - - name: docker - image: plugins/docker - settings: - repo: lxbot/script-debug - username: - from_secret: dockerhub_username - password: - from_secret: dockerhub_password - when: - branch: - - master \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3089168 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,35 @@ +name: 'build' + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest + type=sha,prefix=,suffix=,format=short + - uses: docker/build-push-action@v5 + with: + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index c1b05f1..4709ccb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13.6-alpine3.11 as builder +FROM golang:1.22.5-alpine3.20 as builder ARG GOLANG_NAMESPACE="github.com/lxbot/script-debug" ENV GOLANG_NAMESPACE="$GOLANG_NAMESPACE" @@ -10,13 +10,13 @@ ADD ./go.* /go/src/$GOLANG_NAMESPACE/ ENV GO111MODULE=on RUN go mod download ADD . /go/src/$GOLANG_NAMESPACE/ -RUN make build +RUN go build . RUN mkdir -p /lxbot/scripts -RUN mv /go/src/$GOLANG_NAMESPACE/script-debug.so /lxbot/scripts/ +RUN mv /go/src/$GOLANG_NAMESPACE/script-debug /lxbot/scripts/ # ==================================================================================== -FROM alpine +FROM alpine:3.20 RUN apk --no-cache add ca-certificates COPY --from=builder /etc/localtime /etc/localtime diff --git a/Makefile b/Makefile deleted file mode 100644 index 72d5146..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -.PHONY: build debug - -build: - go build -buildmode=plugin -o script-debug.so script.go - -debug: - go build -gcflags="all=-N -l" -buildmode=plugin -o script-debug.so script.go diff --git a/go.mod b/go.mod index 969c03b..7dfd6ca 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,8 @@ module github.com/lxbot/script-debug go 1.13 -require github.com/lxbot/lxlib/v2 v2.0.0-alpha.18 +require ( + github.com/lxbot/lxlib/v2 v2.0.0-beta.9 + github.com/mitchellh/mapstructure v1.4.3 // indirect + github.com/rs/xid v1.4.0 // indirect +) diff --git a/go.sum b/go.sum index 448c235..c0631fb 100644 --- a/go.sum +++ b/go.sum @@ -30,5 +30,15 @@ github.com/lxbot/lxlib/v2 v2.0.0-alpha.17 h1:APuNdz2nXmBXMRxQSbiSvAFAqWT418uYAtx github.com/lxbot/lxlib/v2 v2.0.0-alpha.17/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= github.com/lxbot/lxlib/v2 v2.0.0-alpha.18 h1:QAgONx8vxbE+04czogxqDd0g6wV6oPeOorJJcz26igE= github.com/lxbot/lxlib/v2 v2.0.0-alpha.18/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-beta.7 h1:xTOpNg9L1gsoUhHHdALj5kfW9N9pxvWwhMkW1hWG1Eo= +github.com/lxbot/lxlib/v2 v2.0.0-beta.7/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-beta.8 h1:r6I8YgdfoXa0lbmf2oorxtyycYTJW7QpL597rYRfsts= +github.com/lxbot/lxlib/v2 v2.0.0-beta.8/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-beta.9 h1:dUv1TmqtT+1WZS9CHhCgaGLp7fcH8OS1RdCw8l6LvTw= +github.com/lxbot/lxlib/v2 v2.0.0-beta.9/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= diff --git a/script.go b/script.go index 7f26156..41a2917 100644 --- a/script.go +++ b/script.go @@ -5,16 +5,30 @@ import ( "github.com/lxbot/lxlib/v2/common" ) +type M = map[string]interface{} + func main() { script, messageCh := lxlib.NewScript() for { message := <-*messageCh + + common.TraceLog("(script)", "lxlib.listen()", "event received", "message:", message) + response, err := message.Copy() if err != nil { common.ErrorLog("message copy error:", err) continue } - script.SendMessage(response.Reply().AddContent("script-debug")) + + key := "last_msg_" + message.User.ID + + lastMessage := script.GetStorage(key) + if lastMessage == nil { + lastMessage = "" + } + script.SetStorage(key, message.Contents[0].Text) + + script.SendMessage(response.Reply().ResetContents().AddContent("last message: '" + lastMessage.(string) + "'")) } }