Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
845b4832
Commit
845b4832
authored
Sep 07, 2020
by
Mrs4s
Committed by
GitHub
Sep 07, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #244 from wdvxdr1123/master
add: api _get_vip_info
parents
3c73769d
3dc436b5
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
202 additions
and
31 deletions
+202
-31
coolq/api.go
coolq/api.go
+26
-0
docs/EventFilter.md
docs/EventFilter.md
+132
-0
go.mod
go.mod
+3
-5
go.sum
go.sum
+19
-26
server/http.go
server/http.go
+16
-0
server/websocket.go
server/websocket.go
+6
-0
No files found.
coolq/api.go
View file @
845b4832
...
...
@@ -304,6 +304,14 @@ func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
return
Failed
(
100
)
}
func
(
bot
*
CQBot
)
CQSetGroupMemo
(
groupId
int64
,
msg
string
)
MSG
{
if
g
:=
bot
.
Client
.
FindGroup
(
groupId
);
g
!=
nil
{
g
.
UpdateMemo
(
msg
)
return
OK
(
nil
)
}
return
Failed
(
100
)
}
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA
func
(
bot
*
CQBot
)
CQSetGroupKick
(
groupId
,
userId
int64
,
msg
string
)
MSG
{
if
g
:=
bot
.
Client
.
FindGroup
(
groupId
);
g
!=
nil
{
...
...
@@ -396,6 +404,24 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
return
OK
(
nil
)
}
func
(
bot
*
CQBot
)
CQGetVipInfo
(
userId
int64
)
MSG
{
msg
:=
MSG
{}
vip
,
err
:=
bot
.
Client
.
GetVipInfo
(
userId
)
if
err
!=
nil
{
return
Failed
(
100
)
}
msg
=
MSG
{
"user_id"
:
vip
.
Uin
,
"nickname"
:
vip
.
Name
,
"level"
:
vip
.
Level
,
"level_speed"
:
vip
.
LevelSpeed
,
"vip_level"
:
vip
.
VipLevel
,
"vip_growth_speed"
:
vip
.
VipGrowthSpeed
,
"vip_growth_total"
:
vip
.
VipGrowthTotal
,
}
return
OK
(
msg
)
}
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF
func
(
bot
*
CQBot
)
CQGetGroupHonorInfo
(
groupId
int64
,
t
string
)
MSG
{
msg
:=
MSG
{
"group_id"
:
groupId
}
...
...
docs/EventFilter.md
0 → 100644
View file @
845b4832
# 事件过滤器
在go-cqhttp同级目录下新建
`filter.json`
文件即可开启事件过滤器,启动时会读取该文件中定义的过滤规则(使用 JSON 编写),若文件不存在,或过滤规则语法错误,则会暂停所有上报。
事件过滤器会处理所有事件(包括心跳事件在内的元事件),请谨慎使用!!
## 示例
这节首先给出一些示例,演示过滤器的基本用法,下一节将给出具体语法说明。
### 只上报以「!!」开头的消息
```
json
{
"raw_message"
:
{
".regex"
:
"^!!"
}
}
```
### 只上报群组的非匿名消息
```
json
{
"message_type"
:
"group"
,
"anonymous"
:
{
".eq"
:
null
}
}
```
### 只上报私聊或特定群组的非匿名消息
```
json
{
".or"
:
[
{
"message_type"
:
"private"
},
{
"message_type"
:
"group"
,
"group_id"
:
{
".in"
:
[
123456
]
},
"anonymous"
:
{
".eq"
:
null
}
}
]
}
```
### 只上报群组 11111、22222、33333 中不是用户 12345 发送的消息,以及用户 66666 发送的所有消息
```
json
{
".or"
:
[
{
"group_id"
:
{
".in"
:
[
11111
,
22222
,
33333
]
},
"user_id"
:
{
".neq"
:
12345
}
},
{
"user_id"
:
66666
}
]
}
```
### 一个更复杂的例子
```
json
{
".or"
:
[
{
"message_type"
:
"private"
,
"user_id"
:
{
".not"
:
{
".in"
:
[
11111
,
22222
,
33333
]
},
".neq"
:
44444
}
},
{
"message_type"
:
{
".regex"
:
"group|discuss"
},
".or"
:
[
{
"group_id"
:
12345
},
{
"raw_message"
:
{
".contains"
:
"通知"
}
}
]
}
]
}
```
## 语法说明
过滤规则最外层是一个 JSON 对象,其中的键,如果以
`.`
(点号)开头,则表示运算符,其值为运算符的参数,如果不以
`.`
开头,则表示对事件数据对象中相应键的过滤。过滤规则中任何一个对象,只有在它的所有项都匹配的情况下,才会让事件通过(等价于一个
`and`
运算);其中,不以
`.`
开头的键,若其值不是对象,则只有在这个值和事件数据相应值相等的情况下,才会通过(等价于一个
`eq`
运算符)。
下面列出所有运算符(「要求的参数类型」是指运算符的键所对应的值的类型,「可作用于的类型」是指在过滤时事件对象相应值的类型):
| 运算符 | 要求的参数类型 | 可作用于的类型 |
| ----- | ------------ | ----------- |
|
`.not`
| object | 任何 |
|
`.and`
| object | 若参数中全为运算符,则任何;若不全为运算符,则 object |
|
`.or`
| array(数组元素为 object) | 任何 |
|
`.eq`
| 任何 | 任何 |
|
`.neq`
| 任何 | 任何 |
|
`.in`
| string/array | 若参数为 string,则 string;若参数为 array,则任何 |
|
`.contains`
| string | string |
|
`.regex`
| string | string |
## 过滤时的事件数据对象
过滤器在go-cqhttp构建好事件数据后运行,各事件的数据字段见
[
OneBot标准
](
https://github.com/howmanybots/onebot/blob/master/v11/specs/event/README.md
)
。
这里有几点需要注意:
-
`message`
字段在运行过滤器时是消息段数组的形式(见
[
消息格式
](
https://github.com/howmanybots/onebot/blob/master/v11/specs/message/array.md
)
)
-
`raw_message`
字段为未经
**CQ码**
处理的原始消息字符串,这意味着其中可能会出现形如
`[CQ:face,id=123]`
的 CQ 码
go.mod
View file @
845b4832
...
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-2020090
2072401-56d3e65e98b5
github.com/Mrs4s/MiraiGo v0.0.0-2020090
6025848-23750bb59124
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect
...
...
@@ -18,15 +18,13 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff
github.com/sirupsen/logrus v1.6.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tebeka/strftime v0.1.5 // indirect
github.com/tidwall/gjson v1.6.1
github.com/xujiajun/nutsdb v0.5.0
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
go.sum
View file @
845b4832
This diff is collapsed.
Click to expand it.
server/http.go
View file @
845b4832
...
...
@@ -131,6 +131,9 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
s
.
engine
.
Any
(
"/set_group_name"
,
s
.
SetGroupName
)
s
.
engine
.
Any
(
"/set_group_name_async"
,
s
.
SetGroupName
)
s
.
engine
.
Any
(
"/_send_group_notice"
,
s
.
SendGroupNotice
)
s
.
engine
.
Any
(
"/_send_group_notice_async"
,
s
.
SendGroupNotice
)
s
.
engine
.
Any
(
"/set_group_leave"
,
s
.
SetGroupLeave
)
s
.
engine
.
Any
(
"/set_group_leave_async"
,
s
.
SetGroupLeave
)
...
...
@@ -154,6 +157,9 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
s
.
engine
.
Any
(
"/get_version_info"
,
s
.
GetVersionInfo
)
s
.
engine
.
Any
(
"/get_version_info_async"
,
s
.
GetVersionInfo
)
s
.
engine
.
Any
(
"/_get_vip_info"
,
s
.
GetVipInfo
)
s
.
engine
.
Any
(
"/_get_vip_info_async"
,
s
.
GetVipInfo
)
s
.
engine
.
Any
(
"/.handle_quick_operation"
,
s
.
HandleQuickOperation
)
go
func
()
{
...
...
@@ -350,6 +356,11 @@ func (s *httpServer) SetGroupName(c *gin.Context) {
c
.
JSON
(
200
,
s
.
bot
.
CQSetGroupName
(
gid
,
getParam
(
c
,
"group_name"
)))
}
func
(
s
*
httpServer
)
SendGroupNotice
(
c
*
gin
.
Context
)
{
gid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"group_id"
),
10
,
64
)
c
.
JSON
(
200
,
s
.
bot
.
CQSetGroupMemo
(
gid
,
getParam
(
c
,
"content"
)))
}
func
(
s
*
httpServer
)
SetGroupLeave
(
c
*
gin
.
Context
)
{
gid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"group_id"
),
10
,
64
)
c
.
JSON
(
200
,
s
.
bot
.
CQSetGroupLeave
(
gid
))
...
...
@@ -381,6 +392,11 @@ func (s *httpServer) GetVersionInfo(c *gin.Context) {
c
.
JSON
(
200
,
s
.
bot
.
CQGetVersionInfo
())
}
func
(
s
*
httpServer
)
GetVipInfo
(
c
*
gin
.
Context
)
{
uid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"user_id"
),
10
,
64
)
c
.
JSON
(
200
,
s
.
bot
.
CQGetVipInfo
(
uid
))
}
func
(
s
*
httpServer
)
HandleQuickOperation
(
c
*
gin
.
Context
)
{
if
c
.
Request
.
Method
!=
"POST"
{
c
.
AbortWithStatus
(
404
)
...
...
server/websocket.go
View file @
845b4832
...
...
@@ -479,6 +479,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"set_group_name"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupName
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"group_name"
)
.
Str
)
},
"_send_group_notice"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupMemo
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"content"
)
.
Str
)
},
"set_group_leave"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupLeave
(
p
.
Get
(
"group_id"
)
.
Int
())
},
...
...
@@ -506,6 +509,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_version_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetVersionInfo
()
},
"_get_vip_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetVipInfo
(
p
.
Get
(
"user_id"
)
.
Int
())
},
".handle_quick_operation"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQHandleQuickOperation
(
p
.
Get
(
"context"
),
p
.
Get
(
"operation"
))
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment