From 2e92f36894cb37f4060a1a0c54e3afb457408708 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 12 Jun 2023 01:05:07 +0800 Subject: [PATCH 1/7] :rocket: fix docker build --- .github/workflows/build-docker-workflow.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-docker-workflow.yaml b/.github/workflows/build-docker-workflow.yaml index ee1f9d1..8079472 100644 --- a/.github/workflows/build-docker-workflow.yaml +++ b/.github/workflows/build-docker-workflow.yaml @@ -31,7 +31,7 @@ jobs: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - name: Build and push release - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 if: startsWith(github.ref, 'refs/tags/v') with: context: . @@ -39,9 +39,12 @@ jobs: tags: ceobecanteen/ceobe-canteen-bot:${{ env.TAG_NAME }} cache-from: type=gha cache-to: type=gha,mode=max + provenance: false + sbom: false + - name: Build and push latest - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 if: "!startsWith(github.ref, 'refs/tags/v') && github.event_name == 'push'" with: context: . @@ -49,9 +52,11 @@ jobs: tags: ceobecanteen/ceobe-canteen-bot cache-from: type=gha cache-to: type=gha,mode=max + provenance: false + sbom: false - name: Build and push debug - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 if: "github.event_name == 'pull_request'" with: context: . @@ -59,4 +64,6 @@ jobs: tags: ceobecanteen/ceobe-canteen-bot:${{ github.sha }} cache-from: type=gha cache-to: type=gha,mode=max + provenance: false + sbom: false From bbb64e462d2beed3bb7a17f9d103899eb527bd6a Mon Sep 17 00:00:00 2001 From: Bosheng0422 Date: Wed, 5 Jul 2023 08:48:57 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E4=B8=AAfin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client_test/main.go | 2 +- conf/maintainers.json | 1 + conf/maintainers.json.sample | 6 ++ go.mod | 28 +++++- grpc_impl/log_server.go | 23 ++++- initialize/bot.go | 52 +++++++++++ process/process.go | 171 +++++++++++++++++++++++++++++++++++ 7 files changed, 274 insertions(+), 9 deletions(-) create mode 100644 conf/maintainers.json create mode 100644 conf/maintainers.json.sample diff --git a/client_test/main.go b/client_test/main.go index a92622d..f149312 100644 --- a/client_test/main.go +++ b/client_test/main.go @@ -21,7 +21,7 @@ func main() { // 创建请求参数 request := pb.LogRequest{ - Server: *pb.LogRequest_SCHEDULER.Enum(), + Server: *pb.LogRequest_RUST.Enum(), Level: *pb.LogRequest_DEBUG.Enum(), Manual: false, Info: "假装是一堆日志信息", diff --git a/conf/maintainers.json b/conf/maintainers.json new file mode 100644 index 0000000..b71cd9c --- /dev/null +++ b/conf/maintainers.json @@ -0,0 +1 @@ +[{"RUST":[],"FETCHER":null,"ANALYZER":null,"SCHEDULER":null}] diff --git a/conf/maintainers.json.sample b/conf/maintainers.json.sample new file mode 100644 index 0000000..2e5f869 --- /dev/null +++ b/conf/maintainers.json.sample @@ -0,0 +1,6 @@ +{ + "RUST":[2813041268731273062], + "FETCHER":[], + "ANALYZER":[], + "SCHEDULER":[] +} \ No newline at end of file diff --git a/go.mod b/go.mod index 06a24ed..7b56171 100644 --- a/go.mod +++ b/go.mod @@ -10,24 +10,46 @@ require ( ) require ( + github.com/cilium/ebpf v0.10.0 // indirect + github.com/cosiner/argv v0.1.0 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/derekparker/trie v0.0.0-20221221181808-1424fce0c981 // indirect + github.com/go-delve/delve v1.20.2 // indirect + github.com/go-delve/liner v1.2.3-0.20220127212407-d32d89dd2a5d // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.11.1 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-dap v0.9.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect - github.com/kr/pretty v0.3.0 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/leodido/go-urn v1.2.1 // indirect - github.com/rogpeppe/go-internal v1.8.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/rivo/uniseg v0.4.4 // indirect + github.com/rogpeppe/go-internal v1.9.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/spf13/cobra v1.7.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.8.1 // indirect github.com/tidwall/gjson v1.9.3 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect + go.starlark.net v0.0.0-20230612165344-9532f5667272 // indirect + golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect golang.org/x/net v0.5.0 // indirect - golang.org/x/sys v0.4.0 // indirect + golang.org/x/sys v0.9.0 // indirect golang.org/x/text v0.6.0 // indirect google.golang.org/genproto v0.0.0-20230113154510-dbe35b8444a5 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/grpc_impl/log_server.go b/grpc_impl/log_server.go index ffb7e4d..a927f3c 100644 --- a/grpc_impl/log_server.go +++ b/grpc_impl/log_server.go @@ -4,6 +4,7 @@ import ( "ceobe-bot/Ceobe_Proto/code_gen/pb" "ceobe-bot/conf" "ceobe-bot/global" + "ceobe-bot/process" "context" "github.com/tencent-connect/botgo/dto" @@ -22,15 +23,27 @@ func (l *LogServer) PushLog(ctx context.Context, in *pb.LogRequest) (*pb.LogResp content := "" switch in.Server { case pb.LogRequest_RUST: - content += "服务端:rust端\n" + content += "服务端:rust端\n" + "负责人:" + for i := 0; i < len(process.Maintaininfo[0].RUST); i++ { + content += " <@" + process.Maintaininfo[0].RUST[i] + ">" + } case pb.LogRequest_FETCHER: - content += "服务端:蹲饼器\n" + content += "服务端:蹲饼器\n" + "负责人:" + for i := 0; i < len(process.Maintaininfo[0].FETCHER); i++ { + content += " <@" + process.Maintaininfo[0].FETCHER[i] + ">" + } case pb.LogRequest_ANALYZER: - content += "服务端:分析器\n" + content += "服务端:分析器\n" + "负责人:" + for i := 0; i < len(process.Maintaininfo[0].ANALYZER); i++ { + content += " <@" + process.Maintaininfo[0].ANALYZER[i] + ">" + } case pb.LogRequest_SCHEDULER: - content += "服务端:调度器\n" + content += "服务端:调度器\n" + "负责人:" + for i := 0; i < len(process.Maintaininfo[0].SCHEDULER); i++ { + content += " <@" + process.Maintaininfo[0].SCHEDULER[i] + ">" + } } - content += "日志等级:" + in.Level.String() + "\n" + content += "\n日志等级:" + in.Level.String() + "\n" if in.Manual { content += "是否人工介入:是\n" } else { diff --git a/initialize/bot.go b/initialize/bot.go index e6d4833..035d78b 100644 --- a/initialize/bot.go +++ b/initialize/bot.go @@ -5,8 +5,11 @@ import ( "ceobe-bot/global" "ceobe-bot/process" "context" + "encoding/json" "fmt" + "io/ioutil" "log" + "os" "strings" "time" @@ -19,6 +22,30 @@ import ( ) func InitBot() { + + //初始化缓存内的维护者数组 + filePath := "./conf/maintainers.json" + file, err := os.Open(filePath) + if err != nil { + fmt.Println("文件打开失败", err) + + } + //及时关闭file句柄 + defer file.Close() + data, err := ioutil.ReadAll(file) + if err != nil { + fmt.Println("Error reading file:", err) + + } + if len(data) > 0 { + err = json.Unmarshal(data, &process.Maintaininfo) + if err != nil { + fmt.Println("Error unmarshaling JSON:", err) + + } + } + fmt.Println(string(data)) + botToken := token.BotToken(uint64(conf.GetConfig().Bot.AppId), conf.GetConfig().Bot.Token) api := botgo.NewOpenAPI(botToken).WithTimeout(3 * time.Second) // 沙箱环境 @@ -58,6 +85,31 @@ func InitBot() { if err = botgo.NewSessionManager().Start(wsInfo, botToken, &intent); err != nil { log.Fatalln(err) } + + // //初始化缓存内的维护者数组 + // filePath := "./conf/maintainers.json" + // file, err := os.Open(filePath) + // if err != nil { + // fmt.Println("文件打开失败", err) + + // } + // //及时关闭file句柄 + // defer file.Close() + // data, err := ioutil.ReadAll(file) + // if err != nil { + // fmt.Println("Error reading file:", err) + + // } + // fmt.Println("33333333333333333333333333333") + // if len(data) > 0 { + // err = json.Unmarshal(data, &process.Maintaininfo[0]) + // if err != nil { + // fmt.Println("Error unmarshaling JSON:", err) + + // } + // } + // fmt.Println(data) + } // ReadyHandler 自定义 ReadyHandler 感知连接成功事件 diff --git a/process/process.go b/process/process.go index adacd4e..7f24ac0 100644 --- a/process/process.go +++ b/process/process.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "log" + "os" + "regexp" "time" "github.com/tencent-connect/botgo/dto" @@ -17,6 +19,18 @@ type Processor struct { Api openapi.OpenAPI } +// structure for json format +type MaintainerInfo struct { + RUST []string + FETCHER []string + ANALYZER []string + SCHEDULER []string +} + +// slices of four parts' maintainers +var RustMaintainers, FetcherMaintainers, AnalyzerMaintainers, SchedulerMaintainers []string +var Maintaininfo = []MaintainerInfo{{RustMaintainers, FetcherMaintainers, AnalyzerMaintainers, SchedulerMaintainers}} + // ProcessMessage is a function to process message func (p *Processor) ProcessMessage(input string, data *dto.WSATMessageData) error { ctx := context.Background() @@ -51,6 +65,32 @@ func (p *Processor) ProcessMessage(input string, data *dto.WSATMessageData) erro if data.MessageReference != nil { p.setEmoji(ctx, data.ChannelID, data.MessageReference.MessageID) } + case "添加负责人": + switch addMaintainer(data) { + case 1: + toCreate.Content = "添加成功" + case 0: + toCreate.Content = "添加失败,已存在" + case -1: + toCreate.Content = "error" + default: + } + p.sendReply(ctx, data.ChannelID, toCreate) + case "查询负责人": + toCreate.Content = "该端负责人为:" + searchMaintainer(data) + p.sendReply(ctx, data.ChannelID, toCreate) + case "删除负责人": + switch deleteMaintainer(data) { + case 1: + toCreate.Content = "删除成功" + case 0: + toCreate.Content = "不存在指定负责人" + case -1: + toCreate.Content = "error" + default: + } + p.sendReply(ctx, data.ChannelID, toCreate) + default: } @@ -176,3 +216,134 @@ func genReplyArk(data *dto.WSATMessageData) *dto.Ark { }, } } + +// 添加负责人语句format:@bot 添加负责人 端名 @负责人 +// eg. @小刻-测试中 添加负责人 RUST @薄生 +func addMaintainer(data *dto.WSATMessageData) int { + var maintainers []*(dto.User) = data.Mentions + var maintainpart *[]string + pattern := regexp.MustCompile(`添加负责人\s(\w+)\b`) + matches := pattern.FindStringSubmatch(data.Content) + part := "" + if len(matches) > 1 { + part = matches[1] + } + switch part { + case "RUST": + maintainpart = &Maintaininfo[0].RUST + case "FETCHER": + maintainpart = &Maintaininfo[0].FETCHER + case "ANALYZER": + maintainpart = &Maintaininfo[0].ANALYZER + case "SCHEDULER": + maintainpart = &Maintaininfo[0].SCHEDULER + default: + + } + filePath := "./conf/maintainers.json" + file, err := os.Open(filePath) + file, err = os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + fmt.Println("Error opening file:", err) + return -1 + } + defer file.Close() + for _, element := range maintainers[1:] { + for _, value := range *maintainpart { + if value == element.ID { + return 0 + } + } + (*maintainpart) = append((*maintainpart), element.ID) + } + encoder := json.NewEncoder(file) + err = encoder.Encode(Maintaininfo) + if err != nil { + fmt.Println("Error encoding JSON:", err) + return -1 + } + return 1 +} + +// 删除负责人语句format:@bot 删除负责人 端名 @负责人 +// eg. @小刻-测试中 删除负责人 RUST @薄生 +func deleteMaintainer(data *dto.WSATMessageData) int { + var maintainers []*(dto.User) = data.Mentions + var maintainpart *[]string + pattern := regexp.MustCompile(`删除负责人\s(\w+)\b`) + matches := pattern.FindStringSubmatch(data.Content) + part := "" + if len(matches) > 1 { + part = matches[1] + } + switch part { + case "RUST": + maintainpart = &Maintaininfo[0].RUST + case "FETCHER": + maintainpart = &Maintaininfo[0].FETCHER + case "ANALYZER": + maintainpart = &Maintaininfo[0].ANALYZER + case "SCHEDULER": + maintainpart = &Maintaininfo[0].SCHEDULER + default: + + } + filePath := "./conf/maintainers.json" + file, err := os.Open(filePath) + file, err = os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + fmt.Println("Error opening file:", err) + return -1 + } + defer file.Close() + j := 0 + flag := 0 + for _, element := range maintainers[1:] { + for _, value := range *maintainpart { + if value != element.ID { + (*maintainpart)[j] = value + j++ + + } else { + flag = 1 + } + } + } + *maintainpart = (*maintainpart)[:j] + encoder := json.NewEncoder(file) + err = encoder.Encode(Maintaininfo) + if err != nil { + fmt.Println("Error encoding JSON:", err) + return -1 + } + return flag +} + +// 查询负责人语句format:@bot 查询负责人 端名 @负责人 +// eg. @小刻-测试中 查询负责人 RUST +func searchMaintainer(data *dto.WSATMessageData) string { + var maintainpart *[]string + pattern := regexp.MustCompile(`查询负责人\s(\w+)\b`) + matches := pattern.FindStringSubmatch(data.Content) + part := "" + if len(matches) > 1 { + part = matches[1] + } + switch part { + case "RUST": + maintainpart = &Maintaininfo[0].RUST + case "FETCHER": + maintainpart = &Maintaininfo[0].FETCHER + case "ANALYZER": + maintainpart = &Maintaininfo[0].ANALYZER + case "SCHEDULER": + maintainpart = &Maintaininfo[0].SCHEDULER + default: + + } + content := "" + for _, value := range *maintainpart { + content += "<@" + value + "> " + } + return content +} From 594e343941a812352e18d7f8a5a33d4228f50286 Mon Sep 17 00:00:00 2001 From: Bosheng0422 Date: Wed, 5 Jul 2023 09:24:05 +0800 Subject: [PATCH 3/7] update mod --- go.mod | 31 ------------------------------- go.sum | 10 ++++++---- 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 7255e0f..bb97de0 100644 --- a/go.mod +++ b/go.mod @@ -11,52 +11,21 @@ require ( ) require ( - github.com/cilium/ebpf v0.10.0 // indirect - github.com/cosiner/argv v0.1.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/derekparker/trie v0.0.0-20221221181808-1424fce0c981 // indirect - github.com/go-delve/delve v1.20.2 // indirect - github.com/go-delve/liner v1.2.3-0.20220127212407-d32d89dd2a5d // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/google/go-dap v0.9.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect -<<<<<<< HEAD - github.com/leodido/go-urn v1.2.1 // indirect -======= - github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mattn/go-runewidth v0.0.14 // indirect - github.com/rivo/uniseg v0.4.4 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/cobra v1.7.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect ->>>>>>> master github.com/stretchr/testify v1.8.1 // indirect github.com/tidwall/gjson v1.9.3 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect - go.starlark.net v0.0.0-20230612165344-9532f5667272 // indirect - golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect golang.org/x/net v0.5.0 // indirect golang.org/x/sys v0.9.0 // indirect golang.org/x/text v0.6.0 // indirect google.golang.org/genproto v0.0.0-20230113154510-dbe35b8444a5 // indirect -<<<<<<< HEAD -======= - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect ->>>>>>> master gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 94e6422..09e7ee7 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,9 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -62,8 +63,9 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -116,8 +118,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= From e915f9675cda94e3d62e15906478b062e096f42c Mon Sep 17 00:00:00 2001 From: Bosheng0422 Date: Wed, 5 Jul 2023 09:59:15 +0800 Subject: [PATCH 4/7] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c6f1c03..4b7ef03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.vscode/ /conf/config.json +/conf/maintainers.json \ No newline at end of file From 84b04c889f31946c8779df5b4fb554ee5118013f Mon Sep 17 00:00:00 2001 From: Bosheng0422 Date: Fri, 7 Jul 2023 17:51:16 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=95=B4=E7=90=86=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- initialize/bot.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/initialize/bot.go b/initialize/bot.go index 035d78b..7b875d2 100644 --- a/initialize/bot.go +++ b/initialize/bot.go @@ -44,7 +44,6 @@ func InitBot() { } } - fmt.Println(string(data)) botToken := token.BotToken(uint64(conf.GetConfig().Bot.AppId), conf.GetConfig().Bot.Token) api := botgo.NewOpenAPI(botToken).WithTimeout(3 * time.Second) @@ -86,30 +85,6 @@ func InitBot() { log.Fatalln(err) } - // //初始化缓存内的维护者数组 - // filePath := "./conf/maintainers.json" - // file, err := os.Open(filePath) - // if err != nil { - // fmt.Println("文件打开失败", err) - - // } - // //及时关闭file句柄 - // defer file.Close() - // data, err := ioutil.ReadAll(file) - // if err != nil { - // fmt.Println("Error reading file:", err) - - // } - // fmt.Println("33333333333333333333333333333") - // if len(data) > 0 { - // err = json.Unmarshal(data, &process.Maintaininfo[0]) - // if err != nil { - // fmt.Println("Error unmarshaling JSON:", err) - - // } - // } - // fmt.Println(data) - } // ReadyHandler 自定义 ReadyHandler 感知连接成功事件 From 0f5f2f08b83f005b0a9fe81ee046a62349bb33aa Mon Sep 17 00:00:00 2001 From: Bosheng0422 Date: Fri, 7 Jul 2023 17:53:19 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=A0=E6=8E=89=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84sample?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/maintainers.json.sample | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 conf/maintainers.json.sample diff --git a/conf/maintainers.json.sample b/conf/maintainers.json.sample deleted file mode 100644 index 2e5f869..0000000 --- a/conf/maintainers.json.sample +++ /dev/null @@ -1,6 +0,0 @@ -{ - "RUST":[2813041268731273062], - "FETCHER":[], - "ANALYZER":[], - "SCHEDULER":[] -} \ No newline at end of file From 4ca7e876d6d2925bee2e04ef46ed15fc4c21639a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=84=E7=94=9F?= <67680641+Bosheng0422@users.noreply.github.com> Date: Fri, 7 Jul 2023 17:59:12 +0800 Subject: [PATCH 7/7] Revert "Bosheng" --- .gitignore | 1 - client_test/main.go | 2 +- conf/maintainers.json | 1 - go.mod | 3 +- go.sum | 10 +-- grpc_impl/log_server.go | 23 ++---- initialize/bot.go | 27 ------- process/process.go | 171 ---------------------------------------- 8 files changed, 11 insertions(+), 227 deletions(-) delete mode 100644 conf/maintainers.json diff --git a/.gitignore b/.gitignore index 4b7ef03..c6f1c03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /.vscode/ /conf/config.json -/conf/maintainers.json \ No newline at end of file diff --git a/client_test/main.go b/client_test/main.go index f149312..a92622d 100644 --- a/client_test/main.go +++ b/client_test/main.go @@ -21,7 +21,7 @@ func main() { // 创建请求参数 request := pb.LogRequest{ - Server: *pb.LogRequest_RUST.Enum(), + Server: *pb.LogRequest_SCHEDULER.Enum(), Level: *pb.LogRequest_DEBUG.Enum(), Manual: false, Info: "假装是一堆日志信息", diff --git a/conf/maintainers.json b/conf/maintainers.json deleted file mode 100644 index b71cd9c..0000000 --- a/conf/maintainers.json +++ /dev/null @@ -1 +0,0 @@ -[{"RUST":[],"FETCHER":null,"ANALYZER":null,"SCHEDULER":null}] diff --git a/go.mod b/go.mod index bb97de0..ae7d026 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/gorilla/websocket v1.4.2 // indirect - github.com/kr/pretty v0.3.1 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/stretchr/testify v1.8.1 // indirect github.com/tidwall/gjson v1.9.3 // indirect @@ -24,7 +23,7 @@ require ( github.com/tidwall/pretty v1.2.0 // indirect golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect golang.org/x/net v0.5.0 // indirect - golang.org/x/sys v0.9.0 // indirect + golang.org/x/sys v0.4.0 // indirect golang.org/x/text v0.6.0 // indirect google.golang.org/genproto v0.0.0-20230113154510-dbe35b8444a5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 09e7ee7..94e6422 100644 --- a/go.sum +++ b/go.sum @@ -42,9 +42,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -63,9 +62,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -118,8 +116,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/grpc_impl/log_server.go b/grpc_impl/log_server.go index a927f3c..ffb7e4d 100644 --- a/grpc_impl/log_server.go +++ b/grpc_impl/log_server.go @@ -4,7 +4,6 @@ import ( "ceobe-bot/Ceobe_Proto/code_gen/pb" "ceobe-bot/conf" "ceobe-bot/global" - "ceobe-bot/process" "context" "github.com/tencent-connect/botgo/dto" @@ -23,27 +22,15 @@ func (l *LogServer) PushLog(ctx context.Context, in *pb.LogRequest) (*pb.LogResp content := "" switch in.Server { case pb.LogRequest_RUST: - content += "服务端:rust端\n" + "负责人:" - for i := 0; i < len(process.Maintaininfo[0].RUST); i++ { - content += " <@" + process.Maintaininfo[0].RUST[i] + ">" - } + content += "服务端:rust端\n" case pb.LogRequest_FETCHER: - content += "服务端:蹲饼器\n" + "负责人:" - for i := 0; i < len(process.Maintaininfo[0].FETCHER); i++ { - content += " <@" + process.Maintaininfo[0].FETCHER[i] + ">" - } + content += "服务端:蹲饼器\n" case pb.LogRequest_ANALYZER: - content += "服务端:分析器\n" + "负责人:" - for i := 0; i < len(process.Maintaininfo[0].ANALYZER); i++ { - content += " <@" + process.Maintaininfo[0].ANALYZER[i] + ">" - } + content += "服务端:分析器\n" case pb.LogRequest_SCHEDULER: - content += "服务端:调度器\n" + "负责人:" - for i := 0; i < len(process.Maintaininfo[0].SCHEDULER); i++ { - content += " <@" + process.Maintaininfo[0].SCHEDULER[i] + ">" - } + content += "服务端:调度器\n" } - content += "\n日志等级:" + in.Level.String() + "\n" + content += "日志等级:" + in.Level.String() + "\n" if in.Manual { content += "是否人工介入:是\n" } else { diff --git a/initialize/bot.go b/initialize/bot.go index 7b875d2..e6d4833 100644 --- a/initialize/bot.go +++ b/initialize/bot.go @@ -5,11 +5,8 @@ import ( "ceobe-bot/global" "ceobe-bot/process" "context" - "encoding/json" "fmt" - "io/ioutil" "log" - "os" "strings" "time" @@ -22,29 +19,6 @@ import ( ) func InitBot() { - - //初始化缓存内的维护者数组 - filePath := "./conf/maintainers.json" - file, err := os.Open(filePath) - if err != nil { - fmt.Println("文件打开失败", err) - - } - //及时关闭file句柄 - defer file.Close() - data, err := ioutil.ReadAll(file) - if err != nil { - fmt.Println("Error reading file:", err) - - } - if len(data) > 0 { - err = json.Unmarshal(data, &process.Maintaininfo) - if err != nil { - fmt.Println("Error unmarshaling JSON:", err) - - } - } - botToken := token.BotToken(uint64(conf.GetConfig().Bot.AppId), conf.GetConfig().Bot.Token) api := botgo.NewOpenAPI(botToken).WithTimeout(3 * time.Second) // 沙箱环境 @@ -84,7 +58,6 @@ func InitBot() { if err = botgo.NewSessionManager().Start(wsInfo, botToken, &intent); err != nil { log.Fatalln(err) } - } // ReadyHandler 自定义 ReadyHandler 感知连接成功事件 diff --git a/process/process.go b/process/process.go index 7f24ac0..adacd4e 100644 --- a/process/process.go +++ b/process/process.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "log" - "os" - "regexp" "time" "github.com/tencent-connect/botgo/dto" @@ -19,18 +17,6 @@ type Processor struct { Api openapi.OpenAPI } -// structure for json format -type MaintainerInfo struct { - RUST []string - FETCHER []string - ANALYZER []string - SCHEDULER []string -} - -// slices of four parts' maintainers -var RustMaintainers, FetcherMaintainers, AnalyzerMaintainers, SchedulerMaintainers []string -var Maintaininfo = []MaintainerInfo{{RustMaintainers, FetcherMaintainers, AnalyzerMaintainers, SchedulerMaintainers}} - // ProcessMessage is a function to process message func (p *Processor) ProcessMessage(input string, data *dto.WSATMessageData) error { ctx := context.Background() @@ -65,32 +51,6 @@ func (p *Processor) ProcessMessage(input string, data *dto.WSATMessageData) erro if data.MessageReference != nil { p.setEmoji(ctx, data.ChannelID, data.MessageReference.MessageID) } - case "添加负责人": - switch addMaintainer(data) { - case 1: - toCreate.Content = "添加成功" - case 0: - toCreate.Content = "添加失败,已存在" - case -1: - toCreate.Content = "error" - default: - } - p.sendReply(ctx, data.ChannelID, toCreate) - case "查询负责人": - toCreate.Content = "该端负责人为:" + searchMaintainer(data) - p.sendReply(ctx, data.ChannelID, toCreate) - case "删除负责人": - switch deleteMaintainer(data) { - case 1: - toCreate.Content = "删除成功" - case 0: - toCreate.Content = "不存在指定负责人" - case -1: - toCreate.Content = "error" - default: - } - p.sendReply(ctx, data.ChannelID, toCreate) - default: } @@ -216,134 +176,3 @@ func genReplyArk(data *dto.WSATMessageData) *dto.Ark { }, } } - -// 添加负责人语句format:@bot 添加负责人 端名 @负责人 -// eg. @小刻-测试中 添加负责人 RUST @薄生 -func addMaintainer(data *dto.WSATMessageData) int { - var maintainers []*(dto.User) = data.Mentions - var maintainpart *[]string - pattern := regexp.MustCompile(`添加负责人\s(\w+)\b`) - matches := pattern.FindStringSubmatch(data.Content) - part := "" - if len(matches) > 1 { - part = matches[1] - } - switch part { - case "RUST": - maintainpart = &Maintaininfo[0].RUST - case "FETCHER": - maintainpart = &Maintaininfo[0].FETCHER - case "ANALYZER": - maintainpart = &Maintaininfo[0].ANALYZER - case "SCHEDULER": - maintainpart = &Maintaininfo[0].SCHEDULER - default: - - } - filePath := "./conf/maintainers.json" - file, err := os.Open(filePath) - file, err = os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0644) - if err != nil { - fmt.Println("Error opening file:", err) - return -1 - } - defer file.Close() - for _, element := range maintainers[1:] { - for _, value := range *maintainpart { - if value == element.ID { - return 0 - } - } - (*maintainpart) = append((*maintainpart), element.ID) - } - encoder := json.NewEncoder(file) - err = encoder.Encode(Maintaininfo) - if err != nil { - fmt.Println("Error encoding JSON:", err) - return -1 - } - return 1 -} - -// 删除负责人语句format:@bot 删除负责人 端名 @负责人 -// eg. @小刻-测试中 删除负责人 RUST @薄生 -func deleteMaintainer(data *dto.WSATMessageData) int { - var maintainers []*(dto.User) = data.Mentions - var maintainpart *[]string - pattern := regexp.MustCompile(`删除负责人\s(\w+)\b`) - matches := pattern.FindStringSubmatch(data.Content) - part := "" - if len(matches) > 1 { - part = matches[1] - } - switch part { - case "RUST": - maintainpart = &Maintaininfo[0].RUST - case "FETCHER": - maintainpart = &Maintaininfo[0].FETCHER - case "ANALYZER": - maintainpart = &Maintaininfo[0].ANALYZER - case "SCHEDULER": - maintainpart = &Maintaininfo[0].SCHEDULER - default: - - } - filePath := "./conf/maintainers.json" - file, err := os.Open(filePath) - file, err = os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0644) - if err != nil { - fmt.Println("Error opening file:", err) - return -1 - } - defer file.Close() - j := 0 - flag := 0 - for _, element := range maintainers[1:] { - for _, value := range *maintainpart { - if value != element.ID { - (*maintainpart)[j] = value - j++ - - } else { - flag = 1 - } - } - } - *maintainpart = (*maintainpart)[:j] - encoder := json.NewEncoder(file) - err = encoder.Encode(Maintaininfo) - if err != nil { - fmt.Println("Error encoding JSON:", err) - return -1 - } - return flag -} - -// 查询负责人语句format:@bot 查询负责人 端名 @负责人 -// eg. @小刻-测试中 查询负责人 RUST -func searchMaintainer(data *dto.WSATMessageData) string { - var maintainpart *[]string - pattern := regexp.MustCompile(`查询负责人\s(\w+)\b`) - matches := pattern.FindStringSubmatch(data.Content) - part := "" - if len(matches) > 1 { - part = matches[1] - } - switch part { - case "RUST": - maintainpart = &Maintaininfo[0].RUST - case "FETCHER": - maintainpart = &Maintaininfo[0].FETCHER - case "ANALYZER": - maintainpart = &Maintaininfo[0].ANALYZER - case "SCHEDULER": - maintainpart = &Maintaininfo[0].SCHEDULER - default: - - } - content := "" - for _, value := range *maintainpart { - content += "<@" + value + "> " - } - return content -}