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
eeb0defc
Commit
eeb0defc
authored
Sep 21, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Mrs4s/go-cqhttp
parents
3f9829fe
65811d4e
Pipeline
#768
passed with stages
in 4 minutes and 51 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
175 additions
and
29 deletions
+175
-29
README.md
README.md
+1
-1
coolq/api.go
coolq/api.go
+33
-0
coolq/bot.go
coolq/bot.go
+8
-0
coolq/cqcode.go
coolq/cqcode.go
+16
-0
coolq/event.go
coolq/event.go
+34
-11
docs/cqhttp.md
docs/cqhttp.md
+39
-6
go.mod
go.mod
+1
-1
go.sum
go.sum
+4
-2
main.go
main.go
+28
-8
server/http.go
server/http.go
+8
-0
server/websocket.go
server/websocket.go
+3
-0
No files found.
README.md
View file @
eeb0defc
...
...
@@ -82,7 +82,7 @@
|
[
群消息
](
https://cqhttp.cc/docs/4.15/#/Post?id=群消息
)
|
|
[
群消息撤回(拓展Event)
](
docs/cqhttp.md#群消息撤回
)
|
|
[
好友消息撤回(拓展Event)
](
docs/cqhttp.md#好友消息撤回
)
|
|
群内提示事件(拓展Event)
(docs/cqhttp.md#群内戳一戳) |
|
[
群内提示事件(拓展Event)(龙王等事件)
]
(
docs/cqhttp.md#群内戳一戳
)
|
|
[
群管理员变动
](
https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动
)
|
|
[
群成员减少
](
https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少
)
|
|
[
群成员增加
](
https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加
)
|
...
...
coolq/api.go
View file @
eeb0defc
...
...
@@ -497,6 +497,27 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
return
OK
(
msg
)
}
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF
func
(
bot
*
CQBot
)
CQGetStrangerInfo
(
userId
int64
)
MSG
{
info
,
err
:=
bot
.
Client
.
GetSummaryInfo
(
userId
)
if
err
!=
nil
{
return
Failed
(
100
)
}
return
OK
(
MSG
{
"user_id"
:
info
.
Uin
,
"nickname"
:
info
.
Nickname
,
"sex"
:
func
()
string
{
if
info
.
Sex
==
1
{
return
"female"
}
return
"male"
}(),
"age"
:
info
.
Age
,
"level"
:
info
.
Level
,
"login_days"
:
info
.
LoginDays
,
})
}
// https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
// https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376
func
(
bot
*
CQBot
)
CQHandleQuickOperation
(
context
,
operation
gjson
.
Result
)
MSG
{
...
...
@@ -655,6 +676,18 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
"runtime_version"
:
runtime
.
Version
(),
"runtime_os"
:
runtime
.
GOOS
,
"version"
:
Version
,
"protocol"
:
func
()
int
{
switch
client
.
SystemDeviceInfo
.
Protocol
{
case
client
.
AndroidPad
:
return
0
case
client
.
AndroidPhone
:
return
1
case
client
.
AndroidWatch
:
return
2
default
:
return
-
1
}
}(),
})
}
...
...
coolq/bot.go
View file @
eeb0defc
...
...
@@ -139,6 +139,14 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
newElem
=
append
(
newElem
,
gv
)
continue
}
if
i
,
ok
:=
elem
.
(
*
PokeElement
);
ok
{
if
group
:=
bot
.
Client
.
FindGroup
(
groupId
);
group
!=
nil
{
if
mem
:=
group
.
FindMember
(
i
.
Target
);
mem
!=
nil
{
mem
.
Poke
()
return
0
}
}
}
newElem
=
append
(
newElem
,
elem
)
}
m
.
Elements
=
newElem
...
...
coolq/cqcode.go
View file @
eeb0defc
...
...
@@ -26,6 +26,14 @@ var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
var
IgnoreInvalidCQCode
=
false
type
PokeElement
struct
{
Target
int64
}
func
(
e
*
PokeElement
)
Type
()
message
.
ElementType
{
return
message
.
At
}
func
ToArrayMessage
(
e
[]
message
.
IMessageElement
,
code
int64
,
raw
...
bool
)
(
r
[]
MSG
)
{
ur
:=
false
if
len
(
raw
)
!=
0
{
...
...
@@ -50,6 +58,8 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
"type"
:
"text"
,
"data"
:
map
[
string
]
string
{
"text"
:
o
.
Content
},
}
case
*
message
.
ReplyElement
:
continue
case
*
message
.
LightAppElement
:
//m = MSG{
// "type": "text",
...
...
@@ -317,6 +327,12 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return
message
.
NewText
(
d
[
"text"
]),
nil
case
"image"
:
return
bot
.
makeImageElem
(
t
,
d
,
group
)
case
"poke"
:
if
!
group
{
return
nil
,
errors
.
New
(
"todo"
)
// TODO: private poke
}
t
,
_
:=
strconv
.
ParseInt
(
d
[
"qq"
],
10
,
64
)
return
&
PokeElement
{
Target
:
t
},
nil
case
"record"
:
if
!
group
{
return
nil
,
errors
.
New
(
"private voice unsupported now"
)
...
...
coolq/event.go
View file @
eeb0defc
...
...
@@ -216,11 +216,11 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven
"post_type"
:
"notice"
,
"group_id"
:
group
.
Code
,
"notice_type"
:
"notify"
,
"
notify_type"
:
"poke"
,
"
sub_type"
:
"poke"
,
"self_id"
:
c
.
Uin
,
"user_id"
:
notify
.
Sender
,
"sender_id"
:
notify
.
Sender
,
"
receiver_id"
:
notify
.
Receiver
,
"
target_id"
:
notify
.
Receiver
,
"time"
:
time
.
Now
()
.
Unix
(),
})
case
*
client
.
GroupRedBagLuckyKingNotifyEvent
:
...
...
@@ -228,15 +228,38 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven
luckyKing
:=
group
.
FindMember
(
notify
.
LuckyKing
)
log
.
Infof
(
"群 %v 内 %v 的红包被抢完, %v 是运气王"
,
formatGroupName
(
group
),
formatMemberName
(
sender
),
formatMemberName
(
luckyKing
))
bot
.
dispatchEventMessage
(
MSG
{
"post_type"
:
"notice"
,
"group_id"
:
group
.
Code
,
"notice_type"
:
"notify"
,
"notify_type"
:
"lucky_king"
,
"self_id"
:
c
.
Uin
,
"user_id"
:
notify
.
Sender
,
"sender_id"
:
notify
.
Sender
,
"lucky_king_id"
:
notify
.
LuckyKing
,
"time"
:
time
.
Now
()
.
Unix
(),
"post_type"
:
"notice"
,
"group_id"
:
group
.
Code
,
"notice_type"
:
"notify"
,
"sub_type"
:
"lucky_king"
,
"self_id"
:
c
.
Uin
,
"user_id"
:
notify
.
Sender
,
"sender_id"
:
notify
.
Sender
,
"target_id"
:
notify
.
LuckyKing
,
"time"
:
time
.
Now
()
.
Unix
(),
})
case
*
client
.
MemberHonorChangedNotifyEvent
:
log
.
Info
(
notify
.
Content
())
bot
.
dispatchEventMessage
(
MSG
{
"post_type"
:
"notice"
,
"group_id"
:
group
.
Code
,
"notice_type"
:
"notify"
,
"sub_type"
:
"honor"
,
"self_id"
:
c
.
Uin
,
"user_id"
:
notify
.
Uin
,
"time"
:
time
.
Now
()
.
Unix
(),
"honor_type"
:
func
()
string
{
switch
notify
.
Honor
{
case
client
.
Talkative
:
return
"talkative"
case
client
.
Performer
:
return
"performer"
case
client
.
Emotion
:
return
"emotion"
default
:
return
"ERROR"
}
}(),
})
}
}
...
...
docs/cqhttp.md
View file @
eeb0defc
...
...
@@ -32,6 +32,22 @@ Type: `redbag`
示例:
`[CQ:redbag,title=恭喜发财]`
### 戳一戳
> 注意:发送戳一戳消息无法撤回,返回的 `message id` 恒定为 `0`
Type:
`poke`
范围:
**发送(仅群聊)**
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ----------- |
| qq | int64 | 需要戳的成员 |
示例:
`[CQ:poke,qq=123456]`
### 合并转发
Type:
`forward`
...
...
@@ -148,9 +164,9 @@ Type: `xml`
示例:
`[CQ:xml,data=xxxx]`
####一些xml样例
####
一些xml样例
####ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中
####
ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中
#### qq音乐
...
...
@@ -386,9 +402,10 @@ Type: `cardimage`
| ------------- | ------ | -------------- | -------------- |
|
`post_type`
| string |
`notice`
| 上报类型 |
|
`notice_type`
| string |
`notify`
| 消息类型 |
|
`notify_type`
| string |
`poke`
| 提示类型 |
|
`group_id`
| int64 | | 群号 |
|
`sub_type`
| string |
`poke`
| 提示类型 |
|
`user_id`
| int64 | | 发送者id |
|
`
receiver
_id`
| int64 | | 被戳者id |
|
`
target
_id`
| int64 | | 被戳者id |
#### 群红包运气王提示
...
...
@@ -400,6 +417,22 @@ Type: `cardimage`
| ------------- | ------ | -------------- | -------------- |
|
`post_type`
| string |
`notice`
| 上报类型 |
|
`notice_type`
| string |
`notify`
| 消息类型 |
|
`notify_type`
| string |
`lucky_king`
| 提示类型 |
|
`group_id`
| int64 | | 群号 |
|
`sub_type`
| string |
`lucky_king`
| 提示类型 |
|
`user_id`
| int64 | | 红包发送者id |
|
`lucky_king_id`
| int64 | | 运气王id |
|
`target_id`
| int64 | | 运气王id |
#### 群成员荣誉变更提示
> 注意:此事件无法在平板和手表协议上触发
**上报数据**
| 字段 | 类型 | 可能的值 | 说明 |
| ------------- | ------ | -------------- | -------------- |
|
`post_type`
| string |
`notice`
| 上报类型 |
|
`notice_type`
| string |
`notify`
| 消息类型 |
|
`group_id`
| int64 | | 群号 |
|
`sub_type`
| string |
`honor`
| 提示类型 |
|
`user_id`
| int64 | | 成员id |
|
`honor_type`
| string |
`talkative:龙王`
`performer:群聊之火`
`emotion:快乐源泉`
| 荣誉类型 |
go.mod
View file @
eeb0defc
...
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-2020091
2123655-d92d61c5998e
github.com/Mrs4s/MiraiGo v0.0.0-2020091
9153352-249af274638d
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
...
...
go.sum
View file @
eeb0defc
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20200912123655-d92d61c5998e h1:wiaXXMPnYCfA+rX1wy9SNrDyW3O43wfun5dIYKKK3BI=
github.com/Mrs4s/MiraiGo v0.0.0-20200912123655-d92d61c5998e/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0=
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4=
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
...
...
main.go
View file @
eeb0defc
...
...
@@ -269,9 +269,16 @@ func main() {
}
})
cli
.
OnServerUpdated
(
func
(
bot
*
client
.
QQClient
,
e
*
client
.
ServerUpdatedEvent
)
{
log
.
Infof
(
"收到服务器地址更新通知, 将在下一次重连时应用.
服务器地址: %v:%v 服务器位置: %v"
,
e
.
Servers
[
0
]
.
Server
,
e
.
Servers
[
0
]
.
Port
,
e
.
Servers
[
0
]
.
Location
)
log
.
Infof
(
"收到服务器地址更新通知, 将在下一次重连时应用.
地址信息已储存到 servers.bin 文件"
)
_
=
ioutil
.
WriteFile
(
"servers.bin"
,
binary
.
NewWriterF
(
func
(
w
*
binary
.
Writer
)
{
w
.
WriteUInt16
(
uint16
(
len
(
e
.
Servers
)))
w
.
WriteUInt16
(
func
()
(
c
uint16
)
{
for
_
,
s
:=
range
e
.
Servers
{
if
!
strings
.
Contains
(
s
.
Server
,
"com"
)
{
c
++
}
}
return
}())
for
_
,
s
:=
range
e
.
Servers
{
if
!
strings
.
Contains
(
s
.
Server
,
"com"
)
{
w
.
WriteString
(
s
.
Server
)
...
...
@@ -282,12 +289,25 @@ func main() {
})
if
global
.
PathExists
(
"servers.bin"
)
{
if
data
,
err
:=
ioutil
.
ReadFile
(
"servers.bin"
);
err
==
nil
{
r
:=
binary
.
NewReader
(
data
)
r
.
ReadUInt16
()
cli
.
CustomServer
=
&
net
.
TCPAddr
{
IP
:
net
.
ParseIP
(
r
.
ReadString
()),
Port
:
int
(
r
.
ReadUInt16
()),
}
func
()
{
defer
func
()
{
if
pan
:=
recover
();
pan
!=
nil
{
log
.
Error
(
"读取服务器地址时出现错误: %v"
,
pan
)
}
}()
r
:=
binary
.
NewReader
(
data
)
var
addr
[]
*
net
.
TCPAddr
l
:=
r
.
ReadUInt16
()
for
i
:=
0
;
i
<
int
(
l
);
i
++
{
addr
=
append
(
addr
,
&
net
.
TCPAddr
{
IP
:
net
.
ParseIP
(
r
.
ReadString
()),
Port
:
int
(
r
.
ReadUInt16
()),
})
}
if
len
(
addr
)
>
0
{
cli
.
SetCustomServer
(
addr
)
}
}()
}
}
rsp
,
err
:=
cli
.
Login
()
...
...
server/http.go
View file @
eeb0defc
...
...
@@ -333,6 +333,11 @@ func (s *httpServer) GetVipInfo(c *gin.Context) {
c
.
JSON
(
200
,
s
.
bot
.
CQGetVipInfo
(
uid
))
}
func
(
s
*
httpServer
)
GetStrangerInfo
(
c
*
gin
.
Context
)
{
uid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"user_id"
),
10
,
64
)
c
.
JSON
(
200
,
s
.
bot
.
CQGetStrangerInfo
(
uid
))
}
func
(
s
*
httpServer
)
HandleQuickOperation
(
c
*
gin
.
Context
)
{
if
c
.
Request
.
Method
!=
"POST"
{
c
.
AbortWithStatus
(
404
)
...
...
@@ -486,6 +491,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"_get_vip_info"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
GetVipInfo
(
c
)
},
"get_stranger_info"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
GetStrangerInfo
(
c
)
},
"reload_event_filter"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
ReloadEventFilter
(
c
)
},
...
...
server/websocket.go
View file @
eeb0defc
...
...
@@ -486,6 +486,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"can_send_record"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQCanSendRecord
()
},
"get_stranger_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetStrangerInfo
(
p
.
Get
(
"user_id"
)
.
Int
())
},
"get_status"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetStatus
()
},
...
...
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