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
c27ebadb
Commit
c27ebadb
authored
Aug 10, 2020
by
XYenon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for post_message_format: array
parent
d5a8f3ea
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
18 deletions
+113
-18
coolq/api.go
coolq/api.go
+1
-1
coolq/bot.go
coolq/bot.go
+1
-1
coolq/cqcode.go
coolq/cqcode.go
+70
-0
coolq/event.go
coolq/event.go
+18
-3
docs/config.md
docs/config.md
+2
-1
global/config.go
global/config.go
+10
-8
main.go
main.go
+11
-4
No files found.
coolq/api.go
View file @
c27ebadb
...
...
@@ -446,7 +446,7 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
"nickname"
:
n
.
SenderName
,
},
"time"
:
n
.
Time
,
"content"
:
To
String
Message
(
n
.
Message
,
0
,
false
),
"content"
:
To
Formatted
Message
(
n
.
Message
,
0
,
false
),
})
}
return
OK
(
MSG
{
...
...
coolq/bot.go
View file @
c27ebadb
...
...
@@ -154,7 +154,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
"group-name"
:
m
.
GroupName
,
"sender"
:
m
.
Sender
,
"time"
:
m
.
Time
,
"message"
:
To
String
Message
(
m
.
Elements
,
m
.
GroupCode
,
true
),
"message"
:
To
Formatted
Message
(
m
.
Elements
,
m
.
GroupCode
,
true
),
}
id
:=
ToGlobalId
(
m
.
GroupCode
,
m
.
Id
)
if
bot
.
db
!=
nil
{
...
...
coolq/cqcode.go
View file @
c27ebadb
...
...
@@ -23,6 +23,76 @@ var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
var
typeReg
=
regexp
.
MustCompile
(
`\[CQ:(\w+)`
)
var
paramReg
=
regexp
.
MustCompile
(
`,([\w\-.]+?)=([^,\]]+)`
)
func
ToArrayMessage
(
e
[]
message
.
IMessageElement
,
code
int64
,
raw
...
bool
)
(
r
[]
MSG
)
{
ur
:=
false
if
len
(
raw
)
!=
0
{
ur
=
raw
[
0
]
}
for
_
,
elem
:=
range
e
{
m
:=
MSG
{}
switch
o
:=
elem
.
(
type
)
{
case
*
message
.
TextElement
:
m
=
MSG
{
"type"
:
"text"
,
"data"
:
map
[
string
]
string
{
"text"
:
CQCodeEscapeText
(
o
.
Content
)},
}
case
*
message
.
AtElement
:
if
o
.
Target
==
0
{
m
=
MSG
{
"type"
:
"at"
,
"data"
:
map
[
string
]
string
{
"qq"
:
"all"
},
}
}
else
{
m
=
MSG
{
"type"
:
"at"
,
"data"
:
map
[
string
]
string
{
"qq"
:
fmt
.
Sprint
(
o
.
Target
)},
}
}
case
*
message
.
ReplyElement
:
m
=
MSG
{
"type"
:
"reply"
,
"data"
:
map
[
string
]
string
{
"id"
:
fmt
.
Sprint
(
ToGlobalId
(
code
,
o
.
ReplySeq
))},
}
case
*
message
.
ForwardElement
:
m
=
MSG
{
"type"
:
"forward"
,
"data"
:
map
[
string
]
string
{
"id"
:
o
.
ResId
},
}
case
*
message
.
FaceElement
:
m
=
MSG
{
"type"
:
"face"
,
"data"
:
map
[
string
]
string
{
"id"
:
fmt
.
Sprint
(
o
.
Index
)},
}
case
*
message
.
VoiceElement
:
if
ur
{
m
=
MSG
{
"type"
:
"record"
,
"data"
:
map
[
string
]
string
{
"file"
:
o
.
Name
},
}
}
else
{
m
=
MSG
{
"type"
:
"record"
,
"data"
:
map
[
string
]
string
{
"file"
:
o
.
Name
,
"url"
:
o
.
Url
},
}
}
case
*
message
.
ImageElement
:
if
ur
{
m
=
MSG
{
"type"
:
"image"
,
"data"
:
map
[
string
]
string
{
"file"
:
o
.
Filename
},
}
}
else
{
m
=
MSG
{
"type"
:
"image"
,
"data"
:
map
[
string
]
string
{
"file"
:
o
.
Filename
,
"url"
:
o
.
Url
},
}
}
}
r
=
append
(
r
,
m
)
}
return
}
func
ToStringMessage
(
e
[]
message
.
IMessageElement
,
code
int64
,
raw
...
bool
)
(
r
string
)
{
ur
:=
false
if
len
(
raw
)
!=
0
{
...
...
coolq/event.go
View file @
c27ebadb
...
...
@@ -14,6 +14,21 @@ import (
"time"
)
var
format
=
"string"
func
SetMessageFormat
(
f
string
)
{
format
=
f
}
func
ToFormattedMessage
(
e
[]
message
.
IMessageElement
,
code
int64
,
raw
...
bool
)
(
r
interface
{})
{
if
format
==
"string"
{
r
=
ToStringMessage
(
e
,
code
,
raw
...
)
}
else
if
format
==
"array"
{
r
=
ToArrayMessage
(
e
,
code
,
raw
...
)
}
return
}
func
(
bot
*
CQBot
)
privateMessageEvent
(
c
*
client
.
QQClient
,
m
*
message
.
PrivateMessage
)
{
checkMedia
(
m
.
Elements
)
cqm
:=
ToStringMessage
(
m
.
Elements
,
0
,
true
)
...
...
@@ -24,7 +39,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
"sub_type"
:
"friend"
,
"message_id"
:
ToGlobalId
(
m
.
Sender
.
Uin
,
m
.
Id
),
"user_id"
:
m
.
Sender
.
Uin
,
"message"
:
To
String
Message
(
m
.
Elements
,
0
,
false
),
"message"
:
To
Formatted
Message
(
m
.
Elements
,
0
,
false
),
"raw_message"
:
cqm
,
"font"
:
0
,
"self_id"
:
c
.
Uin
,
...
...
@@ -72,7 +87,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
"anonymous"
:
nil
,
"font"
:
0
,
"group_id"
:
m
.
GroupCode
,
"message"
:
To
String
Message
(
m
.
Elements
,
m
.
GroupCode
,
false
),
"message"
:
To
Formatted
Message
(
m
.
Elements
,
m
.
GroupCode
,
false
),
"message_id"
:
id
,
"message_type"
:
"group"
,
"post_type"
:
"message"
,
...
...
@@ -128,7 +143,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
"sub_type"
:
"group"
,
"message_id"
:
m
.
Id
,
"user_id"
:
m
.
Sender
.
Uin
,
"message"
:
To
String
Message
(
m
.
Elements
,
0
,
false
),
"message"
:
To
Formatted
Message
(
m
.
Elements
,
0
,
false
),
"raw_message"
:
cqm
,
"font"
:
0
,
"self_id"
:
c
.
Uin
,
...
...
docs/config.md
View file @
c27ebadb
...
...
@@ -28,7 +28,8 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
"enabled"
:
true
,
"host"
:
"0.0.0.0"
,
"port"
:
5700
,
"post_urls"
:
{
"url:port"
:
"secret"
}
"post_urls"
:
{
"url:port"
:
"secret"
},
"post_message_format"
:
"string"
},
"ws_config"
:
{
"enabled"
:
true
,
...
...
global/config.go
View file @
c27ebadb
...
...
@@ -40,10 +40,11 @@ type CQHttpApiConfig struct {
}
type
GoCQHttpConfig
struct
{
Enabled
bool
`json:"enabled"`
Host
string
`json:"host"`
Port
uint16
`json:"port"`
PostUrls
map
[
string
]
string
`json:"post_urls"`
Enabled
bool
`json:"enabled"`
Host
string
`json:"host"`
Port
uint16
`json:"port"`
PostUrls
map
[
string
]
string
`json:"post_urls"`
PostMessageFormat
string
`json:"post_message_format"`
}
type
GoCQWebsocketConfig
struct
{
...
...
@@ -66,10 +67,11 @@ func DefaultConfig() *JsonConfig {
ReLogin
:
true
,
ReLoginDelay
:
3
,
HttpConfig
:
&
GoCQHttpConfig
{
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Port
:
5700
,
PostUrls
:
map
[
string
]
string
{},
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Port
:
5700
,
PostUrls
:
map
[
string
]
string
{},
PostMessageFormat
:
"string"
,
},
WSConfig
:
&
GoCQWebsocketConfig
{
Enabled
:
true
,
...
...
main.go
View file @
c27ebadb
...
...
@@ -91,10 +91,11 @@ func main() {
Uin
:
uin
,
Password
:
pwd
,
HttpConfig
:
&
global
.
GoCQHttpConfig
{
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Port
:
5700
,
PostUrls
:
map
[
string
]
string
{},
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Port
:
5700
,
PostUrls
:
map
[
string
]
string
{},
PostMessageFormat
:
"string"
,
},
WSConfig
:
&
global
.
GoCQWebsocketConfig
{
Enabled
:
true
,
...
...
@@ -193,6 +194,12 @@ func main() {
b
:=
coolq
.
NewQQBot
(
cli
,
conf
)
if
conf
.
HttpConfig
!=
nil
&&
conf
.
HttpConfig
.
Enabled
{
server
.
HttpServer
.
Run
(
fmt
.
Sprintf
(
"%s:%d"
,
conf
.
HttpConfig
.
Host
,
conf
.
HttpConfig
.
Port
),
conf
.
AccessToken
,
b
)
if
conf
.
HttpConfig
.
PostMessageFormat
!=
"string"
&&
conf
.
HttpConfig
.
PostMessageFormat
!=
"array"
{
log
.
Errorf
(
"http_config.post_message_format 配置错误"
)
return
}
else
{
coolq
.
SetMessageFormat
(
conf
.
HttpConfig
.
PostMessageFormat
)
}
for
k
,
v
:=
range
conf
.
HttpConfig
.
PostUrls
{
server
.
NewHttpClient
()
.
Run
(
k
,
v
,
b
)
}
...
...
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