1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-07 04:23:49 +08:00

update config. close #190

This commit is contained in:
Mrs4s 2020-08-25 17:26:08 +08:00
parent bda02d895a
commit 02355db0f1
5 changed files with 49 additions and 29 deletions

View File

@ -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
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

View File

@ -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
} }
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 {
r = append(r, message.NewText(code)) log.Warnf("转换CQ码 %v 到MiraiGo Element时出现错误: %v 将原样发送.", code, err)
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)

View File

@ -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,
@ -51,18 +53,23 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| 字段 | 类型 | 说明 | | 字段 | 类型 | 说明 |
| ------------------ | -------- | ------------------------------------------------------------------- | | ------------------ | -------- | ------------------------------------------------------------------- |
| uin | int64 | 登录用QQ号 | | uin | int64 | 登录用QQ号 |
| password | string | 登录用密码 | | password | string | 登录用密码 |
| encrypt_password | bool | 是否对密码进行加密. | | encrypt_password | bool | 是否对密码进行加密. |
| password_encrypted | string | 加密后的密码(请勿修改) | | password_encrypted | string | 加密后的密码(请勿修改) |
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | | enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | | access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
| relogin | bool | 是否自动重新登录 | | relogin | bool | 是否自动重新登录 |
| relogin_delay | int | 重登录延时(秒) | | relogin_delay | int | 重登录延时(秒) |
| http_config | object | HTTP API配置 | | post_message_format | string | 上报信息类型 |
| ws_config | object | Websocket API 配置 | | ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 | | force_fragmented | bool | 是否强制分片发送群长消息 |
| http_config | object | HTTP API配置 |
| ws_config | object | Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
> 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误. > 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误.
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取. > 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
> 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥 > 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥
> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析.

View File

@ -6,19 +6,21 @@ import (
) )
type JsonConfig struct { type JsonConfig struct {
Uin int64 `json:"uin"` Uin int64 `json:"uin"`
Password string `json:"password"` Password string `json:"password"`
EncryptPassword bool `json:"encrypt_password"` EncryptPassword bool `json:"encrypt_password"`
PasswordEncrypted string `json:"password_encrypted"` PasswordEncrypted string `json:"password_encrypted"`
EnableDB bool `json:"enable_db"` EnableDB bool `json:"enable_db"`
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"`
HttpConfig *GoCQHttpConfig `json:"http_config"` IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
WSConfig *GoCQWebsocketConfig `json:"ws_config"` ForceFragmented bool `json:"force_fragmented"`
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` HttpConfig *GoCQHttpConfig `json:"http_config"`
PostMessageFormat string `json:"post_message_format"` WSConfig *GoCQWebsocketConfig `json:"ws_config"`
Debug bool `json:"debug"` ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
PostMessageFormat string `json:"post_message_format"`
Debug bool `json:"debug"`
} }
type CQHttpApiConfig struct { type CQHttpApiConfig struct {
@ -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",

View File

@ -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 {