Skip to content

Commit

Permalink
Merge pull request #3 from Enraged-Dun-Cookie-Development-Team/revert…
Browse files Browse the repository at this point in the history
…-2-bosheng

Revert "Bosheng"
  • Loading branch information
phidiaLam authored Jul 7, 2023
2 parents 537ea00 + 4ca7e87 commit 2c18bfc
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 227 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/.vscode/
/conf/config.json
/conf/maintainers.json
2 changes: 1 addition & 1 deletion client_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "假装是一堆日志信息",
Expand Down
1 change: 0 additions & 1 deletion conf/maintainers.json

This file was deleted.

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ 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
github.com/tidwall/match v1.1.1 // indirect
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
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
23 changes: 5 additions & 18 deletions grpc_impl/log_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
27 changes: 0 additions & 27 deletions initialize/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import (
"ceobe-bot/global"
"ceobe-bot/process"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"

Expand All @@ -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)
// 沙箱环境
Expand Down Expand Up @@ -84,7 +58,6 @@ func InitBot() {
if err = botgo.NewSessionManager().Start(wsInfo, botToken, &intent); err != nil {
log.Fatalln(err)
}

}

// ReadyHandler 自定义 ReadyHandler 感知连接成功事件
Expand Down
171 changes: 0 additions & 171 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"encoding/json"
"fmt"
"log"
"os"
"regexp"
"time"

"github.com/tencent-connect/botgo/dto"
Expand All @@ -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()
Expand Down Expand Up @@ -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:
}

Expand Down Expand Up @@ -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
}

0 comments on commit 2c18bfc

Please sign in to comment.