mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 04:23:49 +08:00
feature fix url & update doc.
This commit is contained in:
parent
3d5cec13d0
commit
9dc519ff77
@ -31,6 +31,7 @@ var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
|
||||
*/
|
||||
|
||||
var IgnoreInvalidCQCode = false
|
||||
var SplitUrl = false
|
||||
|
||||
type PokeElement struct {
|
||||
Target int64
|
||||
@ -343,7 +344,13 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
|
||||
}
|
||||
saveTempText := func() {
|
||||
if len(tempText) != 0 {
|
||||
r = append(r, message.NewText(CQCodeUnescapeValue(string(tempText))))
|
||||
if SplitUrl {
|
||||
for _, t := range global.SplitUrl(CQCodeUnescapeValue(string(tempText))) {
|
||||
r = append(r, message.NewText(t))
|
||||
}
|
||||
} else {
|
||||
r = append(r, message.NewText(CQCodeUnescapeValue(string(tempText))))
|
||||
}
|
||||
}
|
||||
tempText = []rune{}
|
||||
cqCode = []rune{}
|
||||
@ -506,6 +513,13 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interface{}, err error) {
|
||||
switch t {
|
||||
case "text":
|
||||
if SplitUrl {
|
||||
var ret []message.IMessageElement
|
||||
for _, text := range global.SplitUrl(d["text"]) {
|
||||
ret = append(ret, message.NewText(text))
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
return message.NewText(d["text"]), nil
|
||||
case "image":
|
||||
img, err := bot.makeImageElem(d, group)
|
||||
|
@ -78,6 +78,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
||||
| post_message_format | string | 上报信息类型 |
|
||||
| ignore_invalid_cqcode | bool | 是否忽略错误的CQ码 |
|
||||
| force_fragmented | bool | 是否强制分片发送群长消息 |
|
||||
| fix_url | bool | 是否对链接的发送进行预处理, 可缓解链接信息被风控导致无法发送的情况, 但可能影响客户端着色(不影响内容)|
|
||||
| use_sso_address | bool | 是否使用服务器下发的地址 |
|
||||
| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) |
|
||||
| http_config | object | HTTP API配置 |
|
||||
@ -112,10 +113,10 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
||||
|
||||
| 值 | 类型 | 限制 |
|
||||
| --- | ------------- | ---------------------------------------------------------------- |
|
||||
| 0 | iPad | 无 |
|
||||
| 1 | Android Phone | 无法接收新版表情如 `/吃瓜 /汪汪`, 会自动转换为字符串 |
|
||||
| 2 | Android Watch | 除`Android Phone`的限制外, 无法接收 `notify` 事件、无法接收口令红包、无法接收撤回消息 |
|
||||
| 3 | MacOS | 无 |
|
||||
| 0 | iPad | 无 |
|
||||
| 1 | Android Phone | 无 |
|
||||
| 2 | Android Watch | 无法接收 `notify` 事件、无法接收口令红包、无法接收撤回消息 |
|
||||
| 3 | MacOS | 无 |
|
||||
|
||||
> 注意, 根据协议的不同, 各类消息有所限制
|
||||
|
||||
|
@ -153,6 +153,7 @@ type JsonConfig struct {
|
||||
} `json:"_rate_limit"`
|
||||
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
|
||||
ForceFragmented bool `json:"force_fragmented"`
|
||||
FixUrl bool `json:"fix_url"`
|
||||
ProxyRewrite string `json:"proxy_rewrite"`
|
||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||
|
@ -71,3 +71,23 @@ func VersionNameCompare(current, remote string) bool {
|
||||
}
|
||||
return len(cur) < len(re)
|
||||
}
|
||||
|
||||
func SplitUrl(s string) []string {
|
||||
reg := regexp.MustCompile(`[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?`)
|
||||
idx := reg.FindAllStringIndex(s, -1)
|
||||
if len(idx) == 0 {
|
||||
return []string{s}
|
||||
}
|
||||
var result []string
|
||||
last := 0
|
||||
for i := 0; i < len(idx); i++ {
|
||||
if len(idx[i]) != 2 {
|
||||
continue
|
||||
}
|
||||
m := int(math.Abs(float64(idx[i][0]-idx[i][1]))/1.5) + idx[i][0]
|
||||
result = append(result, s[last:m])
|
||||
last = m
|
||||
}
|
||||
result = append(result, s[last:])
|
||||
return result
|
||||
}
|
||||
|
@ -239,6 +239,7 @@ func (s *webServer) Dologin() {
|
||||
global.BootFilter()
|
||||
global.InitCodec()
|
||||
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
|
||||
coolq.SplitUrl = conf.FixUrl
|
||||
coolq.ForceFragmented = conf.ForceFragmented
|
||||
log.Info("资源初始化完成, 开始处理信息.")
|
||||
log.Info("アトリは、高性能ですから!")
|
||||
|
Loading…
x
Reference in New Issue
Block a user