Skip to content

Commit 3ab9523

Browse files
committed
feat:github插件初版
1 parent b89c585 commit 3ab9523

File tree

34 files changed

+275
-42
lines changed

34 files changed

+275
-42
lines changed

ZeroBot/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func (ctx *Ctx) GetMatcherMetadata() MatcherMetadata {
3030
meta := MatcherMetadata{
3131
MatcherName: ctx.ma.Mark,
3232
}
33-
if ctx.ma.Engine.MetaData == nil {
33+
if ctx.ma.Engine.Metadata == nil {
3434
meta.PluginName = "default"
3535
} else {
36-
meta.PluginName = ctx.ma.Engine.MetaData.Name
36+
meta.PluginName = ctx.ma.Engine.Metadata.Name
3737
}
3838
return meta
3939
}

ZeroBot/driver/wsclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (ws *WSClient) CallApi(req zero.APIRequest) (zero.APIResponse, error) {
157157

158158
return nullResponse, err
159159
}
160-
log.Debug().Str("name", "ws").Msgf("向服务器发送请求: %v", utils.BytesToString(data))
160+
log.Debug().Str("name", "ws").Msgf("向服务器发送请求: %v", gjson.ParseBytes(data).Raw)
161161

162162
select { // 等待数据返回
163163
case rsp, ok := <-ch:

ZeroBot/driver/wsserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (wssc *WSSCaller) CallApi(req zero.APIRequest) (zero.APIResponse, error) {
227227
log.Warn().Str("name", "wss").Err(err).Msg("向WebsocketServer发送API请求失败")
228228
return nullResponse, err
229229
}
230-
log.Debug().Str("name", "wss").Msgf("向服务器发送请求: %v", utils.BytesToString(data))
230+
log.Debug().Str("name", "wss").Msgf("向服务器发送请求: %v", gjson.ParseBytes(data).Raw)
231231

232232
select { // 等待数据返回
233233
case rsp, ok := <-ch:

ZeroBot/engine.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ func unew() *Engine {
1111
}
1212
}
1313

14-
type MetaData struct {
14+
type Metadata struct {
1515
Name string
1616
Help string
1717
Level uint
1818
}
1919

20-
func NewTemplate(metaData *MetaData) (e *Engine) {
20+
func NewTemplate(metaData *Metadata) (e *Engine) {
2121
if metaData.Name == "" {
2222
log.Fatal().Msg("禁止注册没有命名的插件")
2323
}
2424
e = &Engine{
25-
MetaData: metaData,
25+
Metadata: metaData,
2626
PreHandler: []Rule{},
2727
MidHandler: []Rule{},
2828
PostHandler: []Handler{},
@@ -40,7 +40,7 @@ var defaultEngine = unew()
4040

4141
// Engine is the pre_handler, post_handler manager
4242
type Engine struct {
43-
MetaData *MetaData
43+
Metadata *Metadata
4444
PreHandler []Rule
4545
MidHandler []Rule
4646
PostHandler []Handler
@@ -60,12 +60,12 @@ func (e *Engine) SetBlock(Block bool) *Engine {
6060
return e
6161
}
6262

63-
func (e *Engine) GetMetaDate(Block bool) *MetaData {
64-
return e.MetaData
63+
func (e *Engine) GetMetaDate(Block bool) *Metadata {
64+
return e.Metadata
6565
}
6666

67-
func (e *Engine) SetMetaDate(MetaData *MetaData) {
68-
e.MetaData = MetaData
67+
func (e *Engine) SetMetaDate(Metadata *Metadata) {
68+
e.Metadata = Metadata
6969
}
7070

7171
// UsePreHandler 向该 Engine 添加新 PreHandler(Rule),

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
github.com/gin-gonic/gin v1.10.0
3636
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
3737
github.com/google/generative-ai-go v0.17.0
38+
github.com/google/go-github/v65 v65.0.0
3839
github.com/gorilla/websocket v1.5.3
3940
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
4041
github.com/mattn/go-sqlite3 v1.14.15
@@ -97,6 +98,7 @@ require (
9798
github.com/gobwas/ws v1.4.0 // indirect
9899
github.com/goccy/go-json v0.10.2 // indirect
99100
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
101+
github.com/google/go-querystring v1.1.0 // indirect
100102
github.com/google/s2a-go v0.1.8 // indirect
101103
github.com/google/uuid v1.6.0 // indirect
102104
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
247247
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
248248
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
249249
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
250+
github.com/google/go-github/v65 v65.0.0 h1:pQ7BmO3DZivvFk92geC0jB0q2m3gyn8vnYPgV7GSLhQ=
251+
github.com/google/go-github/v65 v65.0.0/go.mod h1:DvrqWo5hvsdhJvHd4WyVF9ttANN3BniqjP8uTFMNb60=
252+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
253+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
250254
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
251255
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
252256
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
_ "MiniBot/plugin/eqa"
2626
_ "MiniBot/plugin/fortune"
2727
_ "MiniBot/plugin/genai"
28+
_ "MiniBot/plugin/github"
2829
_ "MiniBot/plugin/like"
2930
_ "MiniBot/plugin/meme"
3031
_ "MiniBot/plugin/monitor"

plugin/asill/asill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func init() {
4848
return
4949
}
5050

51-
engine := zero.NewTemplate(&zero.MetaData{
51+
engine := zero.NewTemplate(&zero.Metadata{
5252
Name: pluginName,
5353
Help: help,
5454
})

plugin/atri/atri.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func isAtriSleeping(*zero.Ctx) bool {
5353
}
5454

5555
func init() { // 插件主体
56-
metaData := zero.MetaData{
56+
metaData := zero.Metadata{
5757
Name: "atri",
5858
Help: "本插件基于 ATRI ,为 Golang 移植版\n" +
5959
"- ATRI醒醒\n- ATRI睡吧\n- 萝卜子\n- 喜欢 | 爱你 | 爱 | suki | daisuki | すき | 好き | 贴贴 | 老婆 | 亲一个 | mua\n" +

plugin/bilibili/bilibili.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var (
4848

4949
// 查成分的
5050
func init() {
51-
engine := zero.NewTemplate(&zero.MetaData{
51+
engine := zero.NewTemplate(&zero.Metadata{
5252
Name: "b站查成分查弹幕",
5353
Help: "- >vup info [xxx]\n" +
5454
"- >user info [xxx]\n" +
@@ -63,7 +63,7 @@ func init() {
6363
_ = os.MkdirAll(cachePath, 0755)
6464
vdb, err := initializeVup()
6565
if err != nil {
66-
log.Error().Err(err).Str("name", engine.MetaData.Name).Msg("")
66+
log.Error().Err(err).Str("name", engine.Metadata.Name).Msg("")
6767
}
6868
engine.OnRegex(`^>user info\s?(.{1,25})$`, getPara).SetBlock(true).
6969
Handle(func(ctx *zero.Ctx) {

0 commit comments

Comments
 (0)