Skip to content

Commit

Permalink
regex replace
Browse files Browse the repository at this point in the history
  • Loading branch information
lz1998 committed Feb 8, 2021
1 parent 7a6db78 commit d46b8a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
12 changes: 7 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"encoding/json"

"github.com/pkg/errors"
)

Expand Down Expand Up @@ -29,11 +30,12 @@ type GmcConfig struct {
}

type ServerGroup struct {
Name string `json:"name"` // 功能名称
Disabled bool `json:"disabled"` // 不填false默认启用
Urls []string `json:"urls"` // 服务器列表
EventFilter []int32 `json:"event_filter"` // 事件过滤
RegexFilter string `json:"regex_filter"` // 正则过滤
Name string `json:"name"` // 功能名称
Disabled bool `json:"disabled"` // 不填false默认启用
Urls []string `json:"urls"` // 服务器列表
EventFilter []int32 `json:"event_filter"` // 事件过滤
RegexFilter string `json:"regex_filter"` // 正则过滤
RegexReplace string `json:"regex_replace"` // 正则替换
// TODO event filter, msg filter, regex filter, prefix filter, suffix filter
}

Expand Down
14 changes: 4 additions & 10 deletions service/bot/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,13 @@ func HandleEventFrame(cli *client.QQClient, eventFrame *onebot.Frame) {

if ws.regexp != nil { // 有prefix filter
if e, ok := eventFrame.Data.(*onebot.Frame_PrivateMessageEvent); ok {
b := ws.regexp.Find([]byte(e.PrivateMessageEvent.RawMessage))
if b == nil {
report = false
} else {
e.PrivateMessageEvent.RawMessage = string(b)
if report = ws.regexp.MatchString(e.PrivateMessageEvent.RawMessage); report && ws.RegexReplace != "" {
e.PrivateMessageEvent.RawMessage = ws.regexp.ReplaceAllString(e.PrivateMessageEvent.RawMessage, ws.RegexReplace)
}
}
if e, ok := eventFrame.Data.(*onebot.Frame_GroupMessageEvent); ok {
b := ws.regexp.Find([]byte(e.GroupMessageEvent.RawMessage))
if b == nil {
report = false
} else {
e.GroupMessageEvent.RawMessage = string(b)
if report = ws.regexp.MatchString(e.GroupMessageEvent.RawMessage); report && ws.RegexReplace != "" {
e.GroupMessageEvent.RawMessage = ws.regexp.ReplaceAllString(e.GroupMessageEvent.RawMessage, ws.RegexReplace)
}
}
}
Expand Down

0 comments on commit d46b8a9

Please sign in to comment.