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
a1a3e26b
Commit
a1a3e26b
authored
Sep 12, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: protocol switch & group notify & redbag info.
parent
92c224be
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
15 deletions
+58
-15
coolq/bot.go
coolq/bot.go
+1
-0
coolq/cqcode.go
coolq/cqcode.go
+7
-0
coolq/event.go
coolq/event.go
+36
-0
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-14
main.go
main.go
+11
-0
No files found.
coolq/bot.go
View file @
a1a3e26b
...
...
@@ -59,6 +59,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
bot
.
Client
.
OnTempMessage
(
bot
.
tempMessageEvent
)
bot
.
Client
.
OnGroupMuted
(
bot
.
groupMutedEvent
)
bot
.
Client
.
OnGroupMessageRecalled
(
bot
.
groupRecallEvent
)
bot
.
Client
.
OnGroupNotify
(
bot
.
groupNotifyEvent
)
bot
.
Client
.
OnFriendMessageRecalled
(
bot
.
friendRecallEvent
)
bot
.
Client
.
OnJoinGroup
(
bot
.
joinGroupEvent
)
bot
.
Client
.
OnLeaveGroup
(
bot
.
leaveGroupEvent
)
...
...
coolq/cqcode.go
View file @
a1a3e26b
...
...
@@ -71,6 +71,11 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
"data"
:
map
[
string
]
string
{
"qq"
:
fmt
.
Sprint
(
o
.
Target
)},
}
}
case
*
message
.
RedBagElement
:
m
=
MSG
{
"type"
:
"redbag"
,
"data"
:
map
[
string
]
string
{
"title"
:
o
.
Title
},
}
case
*
message
.
ForwardElement
:
m
=
MSG
{
"type"
:
"forward"
,
...
...
@@ -159,6 +164,8 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
continue
}
r
+=
fmt
.
Sprintf
(
"[CQ:at,qq=%d]"
,
o
.
Target
)
case
*
message
.
RedBagElement
:
r
+=
fmt
.
Sprintf
(
"[CQ:redbag,title=%s]"
,
o
.
Title
)
case
*
message
.
ForwardElement
:
r
+=
fmt
.
Sprintf
(
"[CQ:forward,id=%s]"
,
o
.
ResId
)
case
*
message
.
FaceElement
:
...
...
coolq/event.go
View file @
a1a3e26b
...
...
@@ -205,6 +205,42 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
})
}
func
(
bot
*
CQBot
)
groupNotifyEvent
(
c
*
client
.
QQClient
,
e
client
.
IGroupNotifyEvent
)
{
group
:=
c
.
FindGroup
(
e
.
From
())
switch
notify
:=
e
.
(
type
)
{
case
*
client
.
GroupPokeNotifyEvent
:
sender
:=
group
.
FindMember
(
notify
.
Sender
)
receiver
:=
group
.
FindMember
(
notify
.
Receiver
)
log
.
Infof
(
"群 %v 内 %v 戳了戳 %v"
,
formatGroupName
(
group
),
formatMemberName
(
sender
),
formatMemberName
(
receiver
))
bot
.
dispatchEventMessage
(
MSG
{
"post_type"
:
"notice"
,
"group_id"
:
group
.
Code
,
"notice_type"
:
"notify"
,
"notify_type"
:
"poke"
,
"self_id"
:
c
.
Uin
,
"user_id"
:
notify
.
Sender
,
"sender_id"
:
notify
.
Sender
,
"receiver_id"
:
notify
.
Receiver
,
"time"
:
time
.
Now
()
.
Unix
(),
})
case
*
client
.
GroupRedBagLuckyKingNotifyEvent
:
sender
:=
group
.
FindMember
(
notify
.
Sender
)
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
(),
})
}
}
func
(
bot
*
CQBot
)
friendRecallEvent
(
c
*
client
.
QQClient
,
e
*
client
.
FriendMessageRecalledEvent
)
{
f
:=
c
.
FindFriend
(
e
.
FriendUin
)
gid
:=
ToGlobalId
(
e
.
FriendUin
,
e
.
MessageId
)
...
...
go.mod
View file @
a1a3e26b
...
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-2020091
1100852-71bc19cd42e
b
github.com/Mrs4s/MiraiGo v0.0.0-2020091
2102543-d8eaf11f598
b
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 @
a1a3e26b
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-20200909095006-dde8bded28d1 h1:3cmUqA5RaikLx+59SODlBA7tjORQoh4t1w5CzH5bIH8=
github.com/Mrs4s/MiraiGo v0.0.0-20200909095006-dde8bded28d1/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200909103204-808a63a78efe h1:O2BW87BwpwZDsn7YFHLfRGFGvTS4OUZsG2UiA13OxcQ=
github.com/Mrs4s/MiraiGo v0.0.0-20200909103204-808a63a78efe/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200910010455-37409b1f6b9c h1:bhVr3W0+WTVN+vgZGlxD4iFSV9L3CmUg/lt91h+Ll18=
github.com/Mrs4s/MiraiGo v0.0.0-20200910010455-37409b1f6b9c/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099 h1:b+Tmo9h5leZmQokdUu8c2xSIRkkSYoP1z8G+zcwwyRY=
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb h1:WRj/3obehfAMTNKfNo+X3NVqXjeNurMk2yy6haNl/Yk=
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200912102543-d8eaf11f598b h1:3uUSB/3FzPrcUmp4m+QO+F/U/oNf3n82KQqp+468fvs=
github.com/Mrs4s/MiraiGo v0.0.0-20200912102543-d8eaf11f598b/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=
...
...
@@ -70,8 +62,6 @@ github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdA
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible h1:4mNlp+/SvALIPFpbXV3kxNJJno9iKFWGxSDE13Kl66Q=
github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/strftime v1.0.3 h1:qqOPU7y+TM8Y803I8fG9c/DyKG3xH/xkng6keC1015Q=
...
...
@@ -148,8 +138,6 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f h1:Fqb3ao1hUmOR3GkUOg/Y+BadLwykBIzs5q8Ez2SbHyc=
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
...
...
main.go
View file @
a1a3e26b
...
...
@@ -214,6 +214,17 @@ func main() {
log
.
Info
(
"Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消."
)
time
.
Sleep
(
time
.
Second
*
5
)
log
.
Info
(
"开始尝试登录并同步消息..."
)
log
.
Infof
(
"使用协议: %v"
,
func
()
string
{
switch
client
.
SystemDeviceInfo
.
Protocol
{
case
client
.
AndroidPad
:
return
"Android Pad"
case
client
.
AndroidPhone
:
return
"Android Phone"
case
client
.
AndroidWatch
:
return
"Android Watch"
}
return
"未知"
}())
cli
:=
client
.
NewClient
(
conf
.
Uin
,
conf
.
Password
)
cli
.
OnLog
(
func
(
c
*
client
.
QQClient
,
e
*
client
.
LogEvent
)
{
switch
e
.
Type
{
...
...
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