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
be179205
Commit
be179205
authored
Aug 26, 2020
by
F0ur
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Mrs4s/go-cqhttp into master
parents
fe7a1f50
174ebfae
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
32 deletions
+52
-32
coolq/bot.go
coolq/bot.go
+3
-1
coolq/cqcode.go
coolq/cqcode.go
+8
-2
docs/config.md
docs/config.md
+20
-13
global/config.go
global/config.go
+16
-13
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-2
main.go
main.go
+2
-0
No files found.
coolq/bot.go
View file @
be179205
...
@@ -31,6 +31,8 @@ type CQBot struct {
...
@@ -31,6 +31,8 @@ type CQBot struct {
type
MSG
map
[
string
]
interface
{}
type
MSG
map
[
string
]
interface
{}
var
ForceFragmented
=
false
func
NewQQBot
(
cli
*
client
.
QQClient
,
conf
*
global
.
JsonConfig
)
*
CQBot
{
func
NewQQBot
(
cli
*
client
.
QQClient
,
conf
*
global
.
JsonConfig
)
*
CQBot
{
bot
:=
&
CQBot
{
bot
:=
&
CQBot
{
Client
:
cli
,
Client
:
cli
,
...
@@ -128,7 +130,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
...
@@ -128,7 +130,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
newElem
=
append
(
newElem
,
elem
)
newElem
=
append
(
newElem
,
elem
)
}
}
m
.
Elements
=
newElem
m
.
Elements
=
newElem
ret
:=
bot
.
Client
.
SendGroupMessage
(
groupId
,
m
)
ret
:=
bot
.
Client
.
SendGroupMessage
(
groupId
,
m
,
ForceFragmented
)
if
ret
==
nil
||
ret
.
Id
==
-
1
{
if
ret
==
nil
||
ret
.
Id
==
-
1
{
log
.
Warnf
(
"群消息发送失败: 账号可能被风控."
)
log
.
Warnf
(
"群消息发送失败: 账号可能被风控."
)
return
-
1
return
-
1
...
...
coolq/cqcode.go
View file @
be179205
...
@@ -25,6 +25,8 @@ var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
...
@@ -25,6 +25,8 @@ var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
var
typeReg
=
regexp
.
MustCompile
(
`\[CQ:(\w+)`
)
var
typeReg
=
regexp
.
MustCompile
(
`\[CQ:(\w+)`
)
var
paramReg
=
regexp
.
MustCompile
(
`,([\w\-.]+?)=([^,\]]+)`
)
var
paramReg
=
regexp
.
MustCompile
(
`,([\w\-.]+?)=([^,\]]+)`
)
var
IgnoreInvalidCQCode
=
false
func
ToArrayMessage
(
e
[]
message
.
IMessageElement
,
code
int64
,
raw
...
bool
)
(
r
[]
MSG
)
{
func
ToArrayMessage
(
e
[]
message
.
IMessageElement
,
code
int64
,
raw
...
bool
)
(
r
[]
MSG
)
{
ur
:=
false
ur
:=
false
if
len
(
raw
)
!=
0
{
if
len
(
raw
)
!=
0
{
...
@@ -199,8 +201,12 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
...
@@ -199,8 +201,12 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
}
}
elem
,
err
:=
bot
.
ToElement
(
t
,
d
,
group
)
elem
,
err
:=
bot
.
ToElement
(
t
,
d
,
group
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Warnf
(
"转换CQ码到MiraiGo Element时出现错误: %v 将原样发送."
,
err
)
if
!
IgnoreInvalidCQCode
{
log
.
Warnf
(
"转换CQ码 %v 到MiraiGo Element时出现错误: %v 将原样发送."
,
code
,
err
)
r
=
append
(
r
,
message
.
NewText
(
code
))
r
=
append
(
r
,
message
.
NewText
(
code
))
}
else
{
log
.
Warnf
(
"转换CQ码 %v 到MiraiGo Element时出现错误: %v 将忽略."
,
code
,
err
)
}
continue
continue
}
}
r
=
append
(
r
,
elem
)
r
=
append
(
r
,
elem
)
...
...
docs/config.md
View file @
be179205
...
@@ -25,12 +25,14 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -25,12 +25,14 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
"relogin"
:
false
,
"relogin"
:
false
,
"relogin_delay"
:
0
,
"relogin_delay"
:
0
,
"post_message_format"
:
"string"
,
"post_message_format"
:
"string"
,
"ignore_invalid_cqcode"
:
false
,
"force_fragmented"
:
true
,
"http_config"
:
{
"http_config"
:
{
"enabled"
:
true
,
"enabled"
:
true
,
"host"
:
"0.0.0.0"
,
"host"
:
"0.0.0.0"
,
"port"
:
5700
,
"port"
:
5700
,
"timeout"
:
5
,
"timeout"
:
5
,
"post_urls"
:
{
"url:port"
:
"secret"
}
,
"post_urls"
:
{
"url:port"
:
"secret"
}
},
},
"ws_config"
:
{
"ws_config"
:
{
"enabled"
:
true
,
"enabled"
:
true
,
...
@@ -59,6 +61,9 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -59,6 +61,9 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| access_token | string | 同CQHTTP的
`access_token`
用于身份验证 |
| access_token | string | 同CQHTTP的
`access_token`
用于身份验证 |
| relogin | bool | 是否自动重新登录 |
| relogin | bool | 是否自动重新登录 |
| relogin_delay | int | 重登录延时(秒) |
| relogin_delay | int | 重登录延时(秒) |
| post_message_format | string | 上报信息类型 |
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
| force_fragmented | bool | 是否强制分片发送群长消息 |
| http_config | object | HTTP API配置 |
| http_config | object | HTTP API配置 |
| ws_config | object | Websocket API 配置 |
| ws_config | object | Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
...
@@ -66,3 +71,5 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -66,3 +71,5 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
> 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误.
> 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误.
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
> 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥
> 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥
> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析.
\ No newline at end of file
global/config.go
View file @
be179205
...
@@ -14,6 +14,8 @@ type JsonConfig struct {
...
@@ -14,6 +14,8 @@ type JsonConfig struct {
AccessToken
string
`json:"access_token"`
AccessToken
string
`json:"access_token"`
ReLogin
bool
`json:"relogin"`
ReLogin
bool
`json:"relogin"`
ReLoginDelay
int
`json:"relogin_delay"`
ReLoginDelay
int
`json:"relogin_delay"`
IgnoreInvalidCQCode
bool
`json:"ignore_invalid_cqcode"`
ForceFragmented
bool
`json:"force_fragmented"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
...
@@ -68,6 +70,7 @@ func DefaultConfig() *JsonConfig {
...
@@ -68,6 +70,7 @@ func DefaultConfig() *JsonConfig {
ReLogin
:
true
,
ReLogin
:
true
,
ReLoginDelay
:
3
,
ReLoginDelay
:
3
,
PostMessageFormat
:
"string"
,
PostMessageFormat
:
"string"
,
ForceFragmented
:
true
,
HttpConfig
:
&
GoCQHttpConfig
{
HttpConfig
:
&
GoCQHttpConfig
{
Enabled
:
true
,
Enabled
:
true
,
Host
:
"0.0.0.0"
,
Host
:
"0.0.0.0"
,
...
...
go.mod
View file @
be179205
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
go 1.14
require (
require (
github.com/Mrs4s/MiraiGo v0.0.0-2020082
4164833-834baa5b6b58
github.com/Mrs4s/MiraiGo v0.0.0-2020082
5052841-d3b0f5f9e839
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.4.2
...
...
go.sum
View file @
be179205
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
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/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-2020082
4164833-834baa5b6b58 h1:bQDlJSgZmQh9fOMF7yWwL6w2HDm2YUmJlW871WQ404U
=
github.com/Mrs4s/MiraiGo v0.0.0-2020082
5052841-d3b0f5f9e839 h1:TDhaPfWcubIMKDz1HU+N07SwIUjj7oVUQ7EXZBbDUxs
=
github.com/Mrs4s/MiraiGo v0.0.0-2020082
4164833-834baa5b6b58
/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/Mrs4s/MiraiGo v0.0.0-2020082
5052841-d3b0f5f9e839
/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
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=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
...
...
main.go
View file @
be179205
...
@@ -220,6 +220,8 @@ func main() {
...
@@ -220,6 +220,8 @@ func main() {
}
else
{
}
else
{
coolq
.
SetMessageFormat
(
conf
.
PostMessageFormat
)
coolq
.
SetMessageFormat
(
conf
.
PostMessageFormat
)
}
}
coolq
.
IgnoreInvalidCQCode
=
conf
.
IgnoreInvalidCQCode
coolq
.
ForceFragmented
=
conf
.
ForceFragmented
if
conf
.
HttpConfig
!=
nil
&&
conf
.
HttpConfig
.
Enabled
{
if
conf
.
HttpConfig
!=
nil
&&
conf
.
HttpConfig
.
Enabled
{
server
.
HttpServer
.
Run
(
fmt
.
Sprintf
(
"%s:%d"
,
conf
.
HttpConfig
.
Host
,
conf
.
HttpConfig
.
Port
),
conf
.
AccessToken
,
b
)
server
.
HttpServer
.
Run
(
fmt
.
Sprintf
(
"%s:%d"
,
conf
.
HttpConfig
.
Host
,
conf
.
HttpConfig
.
Port
),
conf
.
AccessToken
,
b
)
for
k
,
v
:=
range
conf
.
HttpConfig
.
PostUrls
{
for
k
,
v
:=
range
conf
.
HttpConfig
.
PostUrls
{
...
...
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