mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 03:43:25 +00:00
Compare commits
33 Commits
v1.0.0-rc5
...
v1.1.0
Author | SHA1 | Date | |
---|---|---|---|
9c1390c75c | |||
b958046a27 | |||
19906eba36 | |||
8e6e79f734 | |||
9b9ecd6a41 | |||
c8e480d12f | |||
5bf64ee743 | |||
bad3c86912 | |||
2af55d6a67 | |||
42606a825d | |||
1ed675d5bf | |||
91b4394d9b | |||
0b90074a48 | |||
55cb80dccc | |||
54995fc101 | |||
8acc9f39c2 | |||
13325634c0 | |||
7b2d1fd573 | |||
637d46f282 | |||
1e42b2c450 | |||
749cde2a6d | |||
0f0e711111 | |||
233e276d6a | |||
1ab1cba84c | |||
268ac07271 | |||
c486c254d8 | |||
6ad62a2642 | |||
9762a66ba2 | |||
43c6e3dcf5 | |||
6a17c70689 | |||
d70d66d6d7 | |||
43ff36e3e8 | |||
008d546f1a |
@ -56,6 +56,7 @@ run:
|
|||||||
skip-dirs:
|
skip-dirs:
|
||||||
- db
|
- db
|
||||||
- cmd/api-generator
|
- cmd/api-generator
|
||||||
|
- internal/encryption
|
||||||
tests: true
|
tests: true
|
||||||
|
|
||||||
# output configuration options
|
# output configuration options
|
||||||
|
@ -42,3 +42,4 @@ WORKDIR /data
|
|||||||
VOLUME [ "/data" ]
|
VOLUME [ "/data" ]
|
||||||
|
|
||||||
ENTRYPOINT [ "/docker-entrypoint.sh" ]
|
ENTRYPOINT [ "/docker-entrypoint.sh" ]
|
||||||
|
CMD [ "/app/cqhttp" ]
|
||||||
|
@ -14,25 +14,19 @@ import (
|
|||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
"github.com/Mrs4s/MiraiGo/wrapper"
|
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"gopkg.ilharper.com/x/isatty"
|
"gopkg.ilharper.com/x/isatty"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/download"
|
"github.com/Mrs4s/go-cqhttp/internal/download"
|
||||||
)
|
)
|
||||||
|
|
||||||
var console = bufio.NewReader(os.Stdin)
|
var console = bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
func init() {
|
|
||||||
wrapper.DandelionEnergy = energy
|
|
||||||
}
|
|
||||||
|
|
||||||
func readLine() (str string) {
|
func readLine() (str string) {
|
||||||
str, _ = console.ReadString('\n')
|
str, _ = console.ReadString('\n')
|
||||||
str = strings.TrimSpace(str)
|
str = strings.TrimSpace(str)
|
||||||
@ -216,8 +210,13 @@ func loginResponseProcessor(res *client.LoginResponse) error {
|
|||||||
case client.OtherLoginError, client.UnknownLoginError, client.TooManySMSRequestError:
|
case client.OtherLoginError, client.UnknownLoginError, client.TooManySMSRequestError:
|
||||||
msg := res.ErrorMessage
|
msg := res.ErrorMessage
|
||||||
log.Warnf("登录失败: %v Code: %v", msg, res.Code)
|
log.Warnf("登录失败: %v Code: %v", msg, res.Code)
|
||||||
if res.Code == 235 {
|
switch res.Code {
|
||||||
log.Warnf("请删除 device.json 后重试.")
|
case 235:
|
||||||
|
log.Warnf("设备信息被封禁, 请删除 device.json 后重试.")
|
||||||
|
case 237:
|
||||||
|
log.Warnf("登录过于频繁, 请在手机QQ登录并根据提示完成认证后等一段时间重试")
|
||||||
|
case 45:
|
||||||
|
log.Warnf("你的账号被限制登录, 请配置 SignServer 后重试")
|
||||||
}
|
}
|
||||||
log.Infof("按 Enter 继续....")
|
log.Infof("按 Enter 继续....")
|
||||||
readLine()
|
readLine()
|
||||||
@ -266,26 +265,48 @@ func fetchCaptcha(id string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func energy(uin uint64, id string, salt []byte) ([]byte, error) {
|
func energy(uin uint64, id string, appVersion string, salt []byte) ([]byte, error) {
|
||||||
// temporary solution
|
signServer := base.SignServer
|
||||||
signServer := "https://captcha.go-cqhttp.org/sdk/dandelion/energy"
|
if !strings.HasSuffix(signServer, "/") {
|
||||||
if base.SignServerOverwrite != "" {
|
signServer += "/"
|
||||||
signServer = base.SignServerOverwrite
|
}
|
||||||
|
response, err := download.Request{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
URL: signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt)),
|
||||||
|
}.Bytes()
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("获取T544 sign时出现错误: %v server: %v", err, signServer)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data, err := hex.DecodeString(gjson.GetBytes(response, "data").String())
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("获取T544 sign时出现错误: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(data) == 0 {
|
||||||
|
log.Warnf("获取T544 sign时出现错误: %v", "data is empty")
|
||||||
|
return nil, errors.New("data is empty")
|
||||||
|
}
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []byte, extra []byte, token []byte, err error) {
|
||||||
|
signServer := base.SignServer
|
||||||
|
if !strings.HasSuffix(signServer, "/") {
|
||||||
|
signServer += "/"
|
||||||
}
|
}
|
||||||
response, err := download.Request{
|
response, err := download.Request{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
URL: signServer,
|
URL: signServer + "sign",
|
||||||
Header: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
|
Header: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
|
||||||
Body: bytes.NewReader([]byte(fmt.Sprintf("uin=%v&id=%s&salt=%s", uin, id, hex.EncodeToString(salt)))),
|
Body: bytes.NewReader([]byte(fmt.Sprintf("uin=%v&qua=%s&cmd=%s&seq=%v&buffer=%v", uin, qua, cmd, seq, hex.EncodeToString(buff)))),
|
||||||
}.Bytes()
|
}.Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取T544时出现问题: %v", err)
|
log.Warnf("获取sso sign时出现错误: %v server: %v", err, signServer)
|
||||||
return nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
sign, err := hex.DecodeString(gjson.GetBytes(response, "result").String())
|
sign, _ = hex.DecodeString(gjson.GetBytes(response, "data.sign").String())
|
||||||
if err != nil {
|
extra, _ = hex.DecodeString(gjson.GetBytes(response, "data.extra").String())
|
||||||
log.Errorf("获取T544时出现问题: %v", err)
|
token, _ = hex.DecodeString(gjson.GetBytes(response, "data.token").String())
|
||||||
return nil, err
|
return sign, extra, token, nil
|
||||||
}
|
|
||||||
return sign, nil
|
|
||||||
}
|
}
|
||||||
|
130
cmd/gocq/main.go
130
cmd/gocq/main.go
@ -14,21 +14,22 @@ import (
|
|||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
|
"github.com/Mrs4s/MiraiGo/wrapper"
|
||||||
para "github.com/fumiama/go-hide-param"
|
para "github.com/fumiama/go-hide-param"
|
||||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/download"
|
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
"github.com/Mrs4s/go-cqhttp/db"
|
"github.com/Mrs4s/go-cqhttp/db"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/cache"
|
"github.com/Mrs4s/go-cqhttp/internal/cache"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/internal/download"
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/selfdiagnosis"
|
"github.com/Mrs4s/go-cqhttp/internal/selfdiagnosis"
|
||||||
"github.com/Mrs4s/go-cqhttp/internal/selfupdate"
|
"github.com/Mrs4s/go-cqhttp/internal/selfupdate"
|
||||||
"github.com/Mrs4s/go-cqhttp/modules/servers"
|
"github.com/Mrs4s/go-cqhttp/modules/servers"
|
||||||
@ -163,55 +164,60 @@ func LoginInteract() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if base.SignServer != "-" && base.SignServer != "" {
|
||||||
|
log.Infof("使用服务器 %s 进行数据包签名", base.SignServer)
|
||||||
|
wrapper.DandelionEnergy = energy
|
||||||
|
wrapper.FekitGetSign = sign
|
||||||
|
} else {
|
||||||
|
log.Warnf("警告: 未配置签名服务器, 这可能会导致登录 45 错误码或发送消息被风控")
|
||||||
|
}
|
||||||
|
|
||||||
if base.Account.Encrypt {
|
if base.Account.Encrypt {
|
||||||
if !global.PathExists("password.encrypt") {
|
if !global.PathExists("password.encrypt") {
|
||||||
if base.Account.Password == "" {
|
if base.Account.Password == "" {
|
||||||
log.Error("无法进行加密,请在配置文件中的添加密码后重新启动.")
|
log.Error("无法进行加密,请在配置文件中的添加密码后重新启动.")
|
||||||
readLine()
|
} else {
|
||||||
os.Exit(0)
|
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
|
||||||
|
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
|
||||||
|
_ = os.WriteFile("password.encrypt", []byte(PasswordHashEncrypt(base.PasswordHash[:], byteKey)), 0o644)
|
||||||
|
log.Info("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
||||||
}
|
}
|
||||||
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
|
|
||||||
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
|
||||||
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
|
|
||||||
_ = os.WriteFile("password.encrypt", []byte(PasswordHashEncrypt(base.PasswordHash[:], byteKey)), 0o644)
|
|
||||||
log.Info("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
|
||||||
readLine()
|
readLine()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
|
||||||
if base.Account.Password != "" {
|
|
||||||
log.Error("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
|
||||||
readLine()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(byteKey) == 0 {
|
|
||||||
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
|
||||||
cancel := make(chan struct{}, 1)
|
|
||||||
state, _ := term.GetState(int(os.Stdin.Fd()))
|
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case <-cancel:
|
|
||||||
return
|
|
||||||
case <-time.After(time.Second * 45):
|
|
||||||
log.Infof("解密key输入超时")
|
|
||||||
time.Sleep(3 * time.Second)
|
|
||||||
_ = term.Restore(int(os.Stdin.Fd()), state)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
|
||||||
cancel <- struct{}{}
|
|
||||||
} else {
|
|
||||||
log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.")
|
|
||||||
}
|
|
||||||
|
|
||||||
encrypt, _ := os.ReadFile("password.encrypt")
|
|
||||||
ph, err := PasswordHashDecrypt(string(encrypt), byteKey)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("加密存储的密码损坏,请尝试重新配置密码")
|
|
||||||
}
|
|
||||||
copy(base.PasswordHash[:], ph)
|
|
||||||
}
|
}
|
||||||
|
if base.Account.Password != "" {
|
||||||
|
log.Error("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
||||||
|
readLine()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if len(byteKey) == 0 {
|
||||||
|
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
||||||
|
cancel := make(chan struct{}, 1)
|
||||||
|
state, _ := term.GetState(int(os.Stdin.Fd()))
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-cancel:
|
||||||
|
return
|
||||||
|
case <-time.After(time.Second * 45):
|
||||||
|
log.Infof("解密key输入超时")
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
_ = term.Restore(int(os.Stdin.Fd()), state)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
cancel <- struct{}{}
|
||||||
|
} else {
|
||||||
|
log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.")
|
||||||
|
}
|
||||||
|
|
||||||
|
encrypt, _ := os.ReadFile("password.encrypt")
|
||||||
|
ph, err := PasswordHashDecrypt(string(encrypt), byteKey)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("加密存储的密码损坏,请尝试重新配置密码")
|
||||||
|
}
|
||||||
|
copy(base.PasswordHash[:], ph)
|
||||||
} else if len(base.Account.Password) > 0 {
|
} else if len(base.Account.Password) > 0 {
|
||||||
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
|
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
|
||||||
}
|
}
|
||||||
@ -281,24 +287,30 @@ func LoginInteract() {
|
|||||||
cli.Uin = base.Account.Uin
|
cli.Uin = base.Account.Uin
|
||||||
cli.PasswordMd5 = base.PasswordHash
|
cli.PasswordMd5 = base.PasswordHash
|
||||||
}
|
}
|
||||||
if !isTokenLogin {
|
if !base.FastStart {
|
||||||
if !base.Account.DisableProtocolUpdate {
|
log.Infof("正在检查协议更新...")
|
||||||
log.Infof("正在检查协议更新...")
|
currentVersionName := device.Protocol.Version().SortVersionName
|
||||||
oldVersionName := device.Protocol.Version().String()
|
remoteVersion, err := getRemoteLatestProtocolVersion(int(device.Protocol.Version().Protocol))
|
||||||
remoteVersion, err := getRemoteLatestProtocolVersion(int(device.Protocol.Version().Protocol))
|
if err == nil {
|
||||||
if err == nil {
|
remoteVersionName := gjson.GetBytes(remoteVersion, "sort_version_name").String()
|
||||||
if err = device.Protocol.Version().UpdateFromJson(remoteVersion); err == nil {
|
if remoteVersionName != currentVersionName {
|
||||||
if device.Protocol.Version().String() != oldVersionName {
|
switch {
|
||||||
log.Infof("已自动更新协议版本: %s -> %s", oldVersionName, device.Protocol.Version().String())
|
case !base.UpdateProtocol:
|
||||||
} else {
|
log.Infof("检测到协议更新: %s -> %s", currentVersionName, remoteVersionName)
|
||||||
log.Infof("协议已经是最新版本")
|
log.Infof("如果登录时出现版本过低错误, 可尝试使用 -update-protocol 参数启动")
|
||||||
}
|
case !isTokenLogin:
|
||||||
_ = os.WriteFile(versionFile, remoteVersion, 0o644)
|
_ = device.Protocol.Version().UpdateFromJson(remoteVersion)
|
||||||
|
log.Infof("协议版本已更新: %s -> %s", currentVersionName, remoteVersionName)
|
||||||
|
default:
|
||||||
|
log.Infof("检测到协议更新: %s -> %s", currentVersionName, remoteVersionName)
|
||||||
|
log.Infof("由于使用了会话缓存, 无法自动更新协议, 请删除缓存后重试")
|
||||||
}
|
}
|
||||||
} else if err.Error() != "remote version unavailable" {
|
|
||||||
log.Warnf("检查协议更新失败: %v", err)
|
|
||||||
}
|
}
|
||||||
|
} else if err.Error() != "remote version unavailable" {
|
||||||
|
log.Warnf("检查协议更新失败: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if !isTokenLogin {
|
||||||
if !isQRCodeLogin {
|
if !isQRCodeLogin {
|
||||||
if err := commonLogin(); err != nil {
|
if err := commonLogin(); err != nil {
|
||||||
log.Fatalf("登录时发生致命错误: %v", err)
|
log.Fatalf("登录时发生致命错误: %v", err)
|
||||||
@ -361,6 +373,7 @@ func LoginInteract() {
|
|||||||
})
|
})
|
||||||
saveToken()
|
saveToken()
|
||||||
cli.AllowSlider = true
|
cli.AllowSlider = true
|
||||||
|
download.SetTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新
|
||||||
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
|
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
|
||||||
log.Info("开始加载好友列表...")
|
log.Info("开始加载好友列表...")
|
||||||
global.Check(cli.ReloadFriendList(), true)
|
global.Check(cli.ReloadFriendList(), true)
|
||||||
@ -372,7 +385,6 @@ func LoginInteract() {
|
|||||||
base.Account.Status = 0
|
base.Account.Status = 0
|
||||||
}
|
}
|
||||||
cli.SetOnlineStatus(allowStatus[base.Account.Status])
|
cli.SetOnlineStatus(allowStatus[base.Account.Status])
|
||||||
|
|
||||||
servers.Run(coolq.NewQQBot(cli))
|
servers.Run(coolq.NewQQBot(cli))
|
||||||
log.Info("资源初始化完成, 开始处理信息.")
|
log.Info("资源初始化完成, 开始处理信息.")
|
||||||
log.Info("アトリは、高性能ですから!")
|
log.Info("アトリは、高性能ですから!")
|
||||||
|
@ -617,6 +617,7 @@ func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MS
|
|||||||
log.Warnf("上传私聊文件 %v 失败: %+v", file, err)
|
log.Warnf("上传私聊文件 %v 失败: %+v", file, err)
|
||||||
return Failed(100, "OPEN_FILE_ERROR", "打开文件失败")
|
return Failed(100, "OPEN_FILE_ERROR", "打开文件失败")
|
||||||
}
|
}
|
||||||
|
defer func() { _ = fileBody.Close() }()
|
||||||
localFile := &client.LocalFile{
|
localFile := &client.LocalFile{
|
||||||
FileName: name,
|
FileName: name,
|
||||||
Body: fileBody,
|
Body: fileBody,
|
||||||
|
@ -28,7 +28,7 @@ func (bot *CQBot) CQGetVersion() global.MSG {
|
|||||||
//
|
//
|
||||||
// @route12(send_message)
|
// @route12(send_message)
|
||||||
// @rename(m->message)
|
// @rename(m->message)
|
||||||
func (bot *CQBot) CQSendMessageV12(groupID, userID, detailType string, m gjson.Result) global.MSG {
|
func (bot *CQBot) CQSendMessageV12(groupID, userID, detailType string, m gjson.Result) global.MSG { // nolint
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) *event {
|
|||||||
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
||||||
}
|
}
|
||||||
gm["sender"].(global.MSG)["nickname"] = "匿名消息"
|
gm["sender"].(global.MSG)["nickname"] = "匿名消息"
|
||||||
gm["sub_type"] = "anonymous"
|
typ = "message/group/anonymous"
|
||||||
} else {
|
} else {
|
||||||
group := bot.Client.FindGroup(m.GroupCode)
|
group := bot.Client.FindGroup(m.GroupCode)
|
||||||
mem := group.FindMember(m.Sender.Uin)
|
mem := group.FindMember(m.Sender.Uin)
|
||||||
|
@ -642,7 +642,7 @@ func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType
|
|||||||
return bot.reply(spec, elem, sourceType)
|
return bot.reply(spec, elem, sourceType)
|
||||||
case "forward":
|
case "forward":
|
||||||
id := elem.Get("id")
|
id := elem.Get("id")
|
||||||
if id != "" {
|
if id == "" {
|
||||||
return nil, errors.New("forward 消息中必须包含 id")
|
return nil, errors.New("forward 消息中必须包含 id")
|
||||||
}
|
}
|
||||||
fwdMsg := bot.Client.DownloadForwardMessage(id)
|
fwdMsg := bot.Client.DownloadForwardMessage(id)
|
||||||
@ -713,7 +713,7 @@ func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType
|
|||||||
MusicType: message.CloudMusic,
|
MusicType: message.CloudMusic,
|
||||||
Title: info.Get("name").String(),
|
Title: info.Get("name").String(),
|
||||||
Summary: artistName,
|
Summary: artistName,
|
||||||
Url: "https://y.music.163.com/m/song/" + id,
|
Url: "https://music.163.com/song/?id=" + id,
|
||||||
PictureUrl: info.Get("album.picUrl").String(),
|
PictureUrl: info.Get("album.picUrl").String(),
|
||||||
MusicUrl: "https://music.163.com/song/media/outer/url?id=" + id,
|
MusicUrl: "https://music.163.com/song/media/outer/url?id=" + id,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -136,7 +136,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
|||||||
bot.dispatch(gm)
|
bot.dispatch(gm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEvent) {
|
func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *client.TempMessageEvent) {
|
||||||
m := e.Message
|
m := e.Message
|
||||||
bot.checkMedia(m.Elements, m.Sender.Uin)
|
bot.checkMedia(m.Elements, m.Sender.Uin)
|
||||||
source := message.Source{
|
source := message.Source{
|
||||||
@ -475,6 +475,9 @@ func (bot *CQBot) offlineFileEvent(c *client.QQClient, e *client.OfflineFileEven
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
||||||
|
if group == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
||||||
bot.dispatch(bot.groupIncrease(group.Code, 0, c.Uin))
|
bot.dispatch(bot.groupIncrease(group.Code, 0, c.Uin))
|
||||||
}
|
}
|
||||||
@ -488,7 +491,7 @@ func (bot *CQBot) leaveGroupEvent(c *client.QQClient, e *client.GroupLeaveEvent)
|
|||||||
bot.dispatch(bot.groupDecrease(e.Group.Code, c.Uin, e.Operator))
|
bot.dispatch(bot.groupDecrease(e.Group.Code, c.Uin, e.Operator))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.MemberPermissionChangedEvent) {
|
func (bot *CQBot) memberPermissionChangedEvent(_ *client.QQClient, e *client.MemberPermissionChangedEvent) {
|
||||||
st := "unset"
|
st := "unset"
|
||||||
if e.NewPermission == client.Administrator {
|
if e.NewPermission == client.Administrator {
|
||||||
st = "set"
|
st = "set"
|
||||||
@ -499,7 +502,7 @@ func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.Mem
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) memberCardUpdatedEvent(c *client.QQClient, e *client.MemberCardUpdatedEvent) {
|
func (bot *CQBot) memberCardUpdatedEvent(_ *client.QQClient, e *client.MemberCardUpdatedEvent) {
|
||||||
log.Infof("群 %v 的 %v 更新了名片 %v -> %v", formatGroupName(e.Group), formatMemberName(e.Member), e.OldCard, e.Member.CardName)
|
log.Infof("群 %v 的 %v 更新了名片 %v -> %v", formatGroupName(e.Group), formatMemberName(e.Member), e.OldCard, e.Member.CardName)
|
||||||
bot.dispatchEvent("notice/group_card", global.MSG{
|
bot.dispatchEvent("notice/group_card", global.MSG{
|
||||||
"group_id": e.Group.Code,
|
"group_id": e.Group.Code,
|
||||||
@ -523,7 +526,7 @@ func (bot *CQBot) memberLeaveEvent(_ *client.QQClient, e *client.MemberLeaveGrou
|
|||||||
bot.dispatch(bot.groupDecrease(e.Group.Code, e.Member.Uin, e.Operator))
|
bot.dispatch(bot.groupDecrease(e.Group.Code, e.Member.Uin, e.Operator))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequest) {
|
func (bot *CQBot) friendRequestEvent(_ *client.QQClient, e *client.NewFriendRequest) {
|
||||||
log.Infof("收到来自 %v(%v) 的好友请求: %v", e.RequesterNick, e.RequesterUin, e.Message)
|
log.Infof("收到来自 %v(%v) 的好友请求: %v", e.RequesterNick, e.RequesterUin, e.Message)
|
||||||
flag := strconv.FormatInt(e.RequestId, 10)
|
flag := strconv.FormatInt(e.RequestId, 10)
|
||||||
bot.friendReqCache.Store(flag, e)
|
bot.friendReqCache.Store(flag, e)
|
||||||
@ -534,7 +537,7 @@ func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequ
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent) {
|
func (bot *CQBot) friendAddedEvent(_ *client.QQClient, e *client.NewFriendEvent) {
|
||||||
log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin)
|
log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin)
|
||||||
bot.tempSessionCache.Delete(e.Friend.Uin)
|
bot.tempSessionCache.Delete(e.Friend.Uin)
|
||||||
bot.dispatchEvent("notice/friend_add", global.MSG{
|
bot.dispatchEvent("notice/friend_add", global.MSG{
|
||||||
@ -542,7 +545,7 @@ func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRequest) {
|
func (bot *CQBot) groupInvitedEvent(_ *client.QQClient, e *client.GroupInvitedRequest) {
|
||||||
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
|
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
|
||||||
flag := strconv.FormatInt(e.RequestId, 10)
|
flag := strconv.FormatInt(e.RequestId, 10)
|
||||||
bot.dispatchEvent("request/group/invite", global.MSG{
|
bot.dispatchEvent("request/group/invite", global.MSG{
|
||||||
@ -554,7 +557,7 @@ func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRe
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
|
func (bot *CQBot) groupJoinReqEvent(_ *client.QQClient, e *client.UserJoinGroupRequest) {
|
||||||
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
|
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
|
||||||
flag := strconv.FormatInt(e.RequestId, 10)
|
flag := strconv.FormatInt(e.RequestId, 10)
|
||||||
bot.dispatchEvent("request/group/add", global.MSG{
|
bot.dispatchEvent("request/group/add", global.MSG{
|
||||||
@ -566,7 +569,7 @@ func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupR
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) otherClientStatusChangedEvent(c *client.QQClient, e *client.OtherClientStatusChangedEvent) {
|
func (bot *CQBot) otherClientStatusChangedEvent(_ *client.QQClient, e *client.OtherClientStatusChangedEvent) {
|
||||||
if e.Online {
|
if e.Online {
|
||||||
log.Infof("Bot 账号在客户端 %v (%v) 登录.", e.Client.DeviceName, e.Client.DeviceKind)
|
log.Infof("Bot 账号在客户端 %v (%v) 登录.", e.Client.DeviceName, e.Client.DeviceKind)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,4 +17,4 @@ chown -R ${UID}:${GID} /app /data
|
|||||||
chmod +x /app/cqhttp
|
chmod +x /app/cqhttp
|
||||||
|
|
||||||
echo "Starting..."
|
echo "Starting..."
|
||||||
su-exec ${USER} /app/cqhttp
|
su-exec ${USER} "$@"
|
||||||
|
@ -33,9 +33,15 @@ func EncoderSilk(data []byte) ([]byte, error) {
|
|||||||
// EncodeMP4 将给定视频文件编码为MP4
|
// EncodeMP4 将给定视频文件编码为MP4
|
||||||
func EncodeMP4(src string, dst string) error { // -y 覆盖文件
|
func EncodeMP4(src string, dst string) error { // -y 覆盖文件
|
||||||
cmd1 := exec.Command("ffmpeg", "-i", src, "-y", "-c", "copy", "-map", "0", dst)
|
cmd1 := exec.Command("ffmpeg", "-i", src, "-y", "-c", "copy", "-map", "0", dst)
|
||||||
|
if errors.Is(cmd1.Err, exec.ErrDot) {
|
||||||
|
cmd1.Err = nil
|
||||||
|
}
|
||||||
err := cmd1.Run()
|
err := cmd1.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd2 := exec.Command("ffmpeg", "-i", src, "-y", "-c:v", "h264", "-c:a", "mp3", dst)
|
cmd2 := exec.Command("ffmpeg", "-i", src, "-y", "-c:v", "h264", "-c:a", "mp3", dst)
|
||||||
|
if errors.Is(cmd2.Err, exec.ErrDot) {
|
||||||
|
cmd2.Err = nil
|
||||||
|
}
|
||||||
return errors.Wrap(cmd2.Run(), "convert mp4 failed")
|
return errors.Wrap(cmd2.Run(), "convert mp4 failed")
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -44,5 +50,8 @@ func EncodeMP4(src string, dst string) error { // -y 覆盖文件
|
|||||||
// ExtractCover 获取给定视频文件的Cover
|
// ExtractCover 获取给定视频文件的Cover
|
||||||
func ExtractCover(src string, target string) error {
|
func ExtractCover(src string, target string) error {
|
||||||
cmd := exec.Command("ffmpeg", "-i", src, "-y", "-ss", "0", "-frames:v", "1", target)
|
cmd := exec.Command("ffmpeg", "-i", src, "-y", "-ss", "0", "-frames:v", "1", target)
|
||||||
|
if errors.Is(cmd.Err, exec.ErrDot) {
|
||||||
|
cmd.Err = nil
|
||||||
|
}
|
||||||
return errors.Wrap(cmd.Run(), "extract video cover failed")
|
return errors.Wrap(cmd.Run(), "extract video cover failed")
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.20
|
|||||||
require (
|
require (
|
||||||
github.com/FloatTech/sqlite v1.5.7
|
github.com/FloatTech/sqlite v1.5.7
|
||||||
github.com/Microsoft/go-winio v0.6.0
|
github.com/Microsoft/go-winio v0.6.0
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20230317162854-fd83d24f6794
|
github.com/Mrs4s/MiraiGo v0.0.0-20230627090859-19e3d172596e
|
||||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
|
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
|
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
|
||||||
github.com/fumiama/go-base16384 v1.6.1
|
github.com/fumiama/go-base16384 v1.6.1
|
||||||
|
4
go.sum
4
go.sum
@ -4,8 +4,8 @@ github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJG
|
|||||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||||
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
|
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
|
||||||
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
|
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20230317162854-fd83d24f6794 h1:V2hkbdJhTGX6tfwEsCg53rUCx/skTGBfwRMHB5/hy7E=
|
github.com/Mrs4s/MiraiGo v0.0.0-20230627090859-19e3d172596e h1:99itMjI//+KaFF0+0QCBg/uHhGMJ99jG2lP6z/UnOsU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20230317162854-fd83d24f6794/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
|
github.com/Mrs4s/MiraiGo v0.0.0-20230627090859-19e3d172596e/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
|
||||||
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
|
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
|
||||||
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
|
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
|
||||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
|
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
|
||||||
|
@ -37,7 +37,9 @@ var (
|
|||||||
LogColorful bool // 是否启用日志颜色
|
LogColorful bool // 是否启用日志颜色
|
||||||
FastStart bool // 是否为快速启动
|
FastStart bool // 是否为快速启动
|
||||||
AllowTempSession bool // 是否允许发送临时会话信息
|
AllowTempSession bool // 是否允许发送临时会话信息
|
||||||
SignServerOverwrite string // 使用特定的服务器进行签名
|
UpdateProtocol bool // 是否更新协议
|
||||||
|
SignServer string // 使用特定的服务器进行签名
|
||||||
|
HTTPTimeout int
|
||||||
|
|
||||||
PostFormat string // 上报格式 string or array
|
PostFormat string // 上报格式 string or array
|
||||||
Proxy string // 存储 proxy_rewrite,用于设置代理
|
Proxy string // 存储 proxy_rewrite,用于设置代理
|
||||||
@ -61,7 +63,7 @@ func Parse() {
|
|||||||
flag.StringVar(&LittleWD, "w", "", "cover the working directory")
|
flag.StringVar(&LittleWD, "w", "", "cover the working directory")
|
||||||
d := flag.Bool("D", false, "debug mode")
|
d := flag.Bool("D", false, "debug mode")
|
||||||
flag.BoolVar(&FastStart, "faststart", false, "skip waiting 5 seconds")
|
flag.BoolVar(&FastStart, "faststart", false, "skip waiting 5 seconds")
|
||||||
flag.StringVar(&SignServerOverwrite, "sign-server", "", "use special server to sign tlv")
|
flag.BoolVar(&UpdateProtocol, "update-protocol", false, "update protocol")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *d {
|
if *d {
|
||||||
@ -86,6 +88,8 @@ func Init() {
|
|||||||
ReportSelfMessage = conf.Message.ReportSelfMessage
|
ReportSelfMessage = conf.Message.ReportSelfMessage
|
||||||
UseSSOAddress = conf.Account.UseSSOAddress
|
UseSSOAddress = conf.Account.UseSSOAddress
|
||||||
AllowTempSession = conf.Account.AllowTempSession
|
AllowTempSession = conf.Account.AllowTempSession
|
||||||
|
SignServer = conf.Account.SignServer
|
||||||
|
HTTPTimeout = conf.Message.HTTPTimeout
|
||||||
}
|
}
|
||||||
{ // others
|
{ // others
|
||||||
Proxy = conf.Message.ProxyRewrite
|
Proxy = conf.Message.ProxyRewrite
|
||||||
|
@ -4,6 +4,7 @@ package download
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -22,15 +23,28 @@ import (
|
|||||||
|
|
||||||
var client = &http.Client{
|
var client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
Proxy: func(request *http.Request) (u *url.URL, e error) {
|
Proxy: func(request *http.Request) (*url.URL, error) {
|
||||||
if base.Proxy == "" {
|
if base.Proxy == "" {
|
||||||
return http.ProxyFromEnvironment(request)
|
return http.ProxyFromEnvironment(request)
|
||||||
}
|
}
|
||||||
return url.Parse(base.Proxy)
|
return url.Parse(base.Proxy)
|
||||||
},
|
},
|
||||||
ForceAttemptHTTP2: false,
|
// Disable http2
|
||||||
MaxConnsPerHost: 0,
|
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
|
||||||
MaxIdleConns: 0,
|
MaxIdleConnsPerHost: 999,
|
||||||
|
},
|
||||||
|
Timeout: time.Second * 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
var clienth2 = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Proxy: func(request *http.Request) (*url.URL, error) {
|
||||||
|
if base.Proxy == "" {
|
||||||
|
return http.ProxyFromEnvironment(request)
|
||||||
|
}
|
||||||
|
return url.Parse(base.Proxy)
|
||||||
|
},
|
||||||
|
ForceAttemptHTTP2: true,
|
||||||
MaxIdleConnsPerHost: 999,
|
MaxIdleConnsPerHost: 999,
|
||||||
},
|
},
|
||||||
Timeout: time.Second * 5,
|
Timeout: time.Second * 5,
|
||||||
@ -42,6 +56,15 @@ var ErrOverSize = errors.New("oversize")
|
|||||||
// UserAgent HTTP请求时使用的UA
|
// UserAgent HTTP请求时使用的UA
|
||||||
const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
|
const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
|
||||||
|
|
||||||
|
// SetTimeout set internal/download client timeout
|
||||||
|
func SetTimeout(t time.Duration) {
|
||||||
|
if t == 0 {
|
||||||
|
t = time.Second * 10
|
||||||
|
}
|
||||||
|
client.Timeout = t
|
||||||
|
clienth2.Timeout = t
|
||||||
|
}
|
||||||
|
|
||||||
// Request is a file download request
|
// Request is a file download request
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Method string
|
Method string
|
||||||
@ -51,6 +74,13 @@ type Request struct {
|
|||||||
Body io.Reader
|
Body io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r Request) client() *http.Client {
|
||||||
|
if strings.Contains(r.URL, "go-cqhttp.org") {
|
||||||
|
return clienth2
|
||||||
|
}
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
func (r Request) do() (*http.Response, error) {
|
func (r Request) do() (*http.Response, error) {
|
||||||
if r.Method == "" {
|
if r.Method == "" {
|
||||||
r.Method = http.MethodGet
|
r.Method = http.MethodGet
|
||||||
@ -65,7 +95,7 @@ func (r Request) do() (*http.Response, error) {
|
|||||||
req.Header.Set(k, v)
|
req.Header.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.Do(req)
|
return r.client().Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Request) body() (io.ReadCloser, error) {
|
func (r Request) body() (io.ReadCloser, error) {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseString(t *testing.T) {
|
func TestParseString(_ *testing.T) {
|
||||||
// TODO: add more text
|
// TODO: add more text
|
||||||
for _, v := range ParseString(`[CQ:face,id=115,text=111][CQ:face,id=217]] [CQ:text,text=123] [`) {
|
for _, v := range ParseString(`[CQ:face,id=115,text=111][CQ:face,id=217]] [CQ:text,text=123] [`) {
|
||||||
fmt.Println(v)
|
fmt.Println(v)
|
||||||
|
@ -28,14 +28,14 @@ type Reconnect struct {
|
|||||||
|
|
||||||
// Account 账号配置
|
// Account 账号配置
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Uin int64 `yaml:"uin"`
|
Uin int64 `yaml:"uin"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
Encrypt bool `yaml:"encrypt"`
|
Encrypt bool `yaml:"encrypt"`
|
||||||
Status int `yaml:"status"`
|
Status int `yaml:"status"`
|
||||||
ReLogin *Reconnect `yaml:"relogin"`
|
ReLogin *Reconnect `yaml:"relogin"`
|
||||||
UseSSOAddress bool `yaml:"use-sso-address"`
|
UseSSOAddress bool `yaml:"use-sso-address"`
|
||||||
AllowTempSession bool `yaml:"allow-temp-session"`
|
AllowTempSession bool `yaml:"allow-temp-session"`
|
||||||
DisableProtocolUpdate bool `yaml:"disable-protocol-update"`
|
SignServer string `yaml:"sign-server"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config 总配置文件
|
// Config 总配置文件
|
||||||
@ -57,6 +57,7 @@ type Config struct {
|
|||||||
ExtraReplyData bool `yaml:"extra-reply-data"`
|
ExtraReplyData bool `yaml:"extra-reply-data"`
|
||||||
SkipMimeScan bool `yaml:"skip-mime-scan"`
|
SkipMimeScan bool `yaml:"skip-mime-scan"`
|
||||||
ConvertWebpImage bool `yaml:"convert-webp-image"`
|
ConvertWebpImage bool `yaml:"convert-webp-image"`
|
||||||
|
HTTPTimeout int `yaml:"http-timeout"`
|
||||||
} `yaml:"message"`
|
} `yaml:"message"`
|
||||||
|
|
||||||
Output struct {
|
Output struct {
|
||||||
|
@ -15,8 +15,15 @@ account: # 账号相关
|
|||||||
use-sso-address: true
|
use-sso-address: true
|
||||||
# 是否允许发送临时会话消息
|
# 是否允许发送临时会话消息
|
||||||
allow-temp-session: false
|
allow-temp-session: false
|
||||||
# 是否禁用协议更新
|
|
||||||
disable-protocol-update: false
|
# 数据包的签名服务器
|
||||||
|
# 兼容 https://github.com/fuqiuluo/unidbg-fetch-qsign
|
||||||
|
# 如果遇到 登录 45 错误, 或者发送信息风控的话需要填入一个服务器
|
||||||
|
# 示例:
|
||||||
|
# sign-server: 'http://127.0.0.1:8080' # 本地签名服务器
|
||||||
|
# sign-server: 'https://signserver.example.com' # 线上签名服务器
|
||||||
|
# 服务器可使用docker在本地搭建或者使用他人开放的服务
|
||||||
|
sign-server: '-'
|
||||||
|
|
||||||
heartbeat:
|
heartbeat:
|
||||||
# 心跳频率, 单位秒
|
# 心跳频率, 单位秒
|
||||||
@ -47,6 +54,8 @@ message:
|
|||||||
skip-mime-scan: false
|
skip-mime-scan: false
|
||||||
# 是否自动转换 WebP 图片
|
# 是否自动转换 WebP 图片
|
||||||
convert-webp-image: false
|
convert-webp-image: false
|
||||||
|
# http超时时间
|
||||||
|
http-timeout: 0
|
||||||
|
|
||||||
output:
|
output:
|
||||||
# 日志等级 trace,debug,info,warn,error
|
# 日志等级 trace,debug,info,warn,error
|
||||||
|
@ -32,6 +32,9 @@ func encode(record []byte, tempName string) (silkWav []byte, err error) {
|
|||||||
// 2.转换pcm
|
// 2.转换pcm
|
||||||
pcmPath := path.Join(silkCachePath, tempName+".pcm")
|
pcmPath := path.Join(silkCachePath, tempName+".pcm")
|
||||||
cmd := exec.Command("ffmpeg", "-i", rawPath, "-f", "s16le", "-ar", "24000", "-ac", "1", pcmPath)
|
cmd := exec.Command("ffmpeg", "-i", rawPath, "-f", "s16le", "-ar", "24000", "-ac", "1", pcmPath)
|
||||||
|
if errors.Is(cmd.Err, exec.ErrDot) {
|
||||||
|
cmd.Err = nil
|
||||||
|
}
|
||||||
if base.Debug {
|
if base.Debug {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
78
pkg/onebot/attr.go
Normal file
78
pkg/onebot/attr.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// Copyright 2022 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package onebot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// An Attr is a key-value pair.
|
||||||
|
type Attr struct {
|
||||||
|
Key string
|
||||||
|
Value Value
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns an Attr for a string value.
|
||||||
|
func String(key, value string) Attr {
|
||||||
|
return Attr{key, StringValue(value)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64 returns an Attr for an int64.
|
||||||
|
func Int64(key string, value int64) Attr {
|
||||||
|
return Attr{key, Int64Value(value)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int converts an int to an int64 and returns
|
||||||
|
// an Attr with that value.
|
||||||
|
func Int(key string, value int) Attr {
|
||||||
|
return Int64(key, int64(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint64 returns an Attr for a uint64.
|
||||||
|
func Uint64(key string, v uint64) Attr {
|
||||||
|
return Attr{key, Uint64Value(v)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns an Attr for a floating-point number.
|
||||||
|
func Float64(key string, v float64) Attr {
|
||||||
|
return Attr{key, Float64Value(v)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns an Attr for a bool.
|
||||||
|
func Bool(key string, v bool) Attr {
|
||||||
|
return Attr{key, BoolValue(v)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time returns an Attr for a time.Time.
|
||||||
|
// It discards the monotonic portion.
|
||||||
|
func Time(key string, v time.Time) Attr {
|
||||||
|
return Attr{key, TimeValue(v)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duration returns an Attr for a time.Duration.
|
||||||
|
func Duration(key string, v time.Duration) Attr {
|
||||||
|
return Attr{key, DurationValue(v)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns an Attr for a Group Value.
|
||||||
|
// The caller must not subsequently mutate the
|
||||||
|
// argument slice.
|
||||||
|
//
|
||||||
|
// Use Group to collect several Attrs under a single
|
||||||
|
// key on a log line, or as the result of LogValue
|
||||||
|
// in order to log a single value as multiple Attrs.
|
||||||
|
func Group(key string, as ...Attr) Attr {
|
||||||
|
return Attr{key, GroupValue(as...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Any returns an Attr for the supplied value.
|
||||||
|
// See [Value.AnyValue] for how values are treated.
|
||||||
|
func Any(key string, value any) Attr {
|
||||||
|
return Attr{key, AnyValue(value)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a Attr) String() string {
|
||||||
|
return a.Key + "=" + a.Value.String()
|
||||||
|
}
|
31
pkg/onebot/kind_string.go
Normal file
31
pkg/onebot/kind_string.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Code generated by "stringer -type=Kind -trimprefix=Kind"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package onebot
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[KindAny-0]
|
||||||
|
_ = x[KindBool-1]
|
||||||
|
_ = x[KindDuration-2]
|
||||||
|
_ = x[KindFloat64-3]
|
||||||
|
_ = x[KindInt64-4]
|
||||||
|
_ = x[KindString-5]
|
||||||
|
_ = x[KindTime-6]
|
||||||
|
_ = x[KindUint64-7]
|
||||||
|
_ = x[KindGroup-8]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _Kind_name = "AnyBoolDurationFloat64Int64StringTimeUint64Group"
|
||||||
|
|
||||||
|
var _Kind_index = [...]uint8{0, 3, 7, 15, 22, 27, 33, 37, 43, 48}
|
||||||
|
|
||||||
|
func (i Kind) String() string {
|
||||||
|
if i < 0 || i >= Kind(len(_Kind_index)-1) {
|
||||||
|
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
|
||||||
|
}
|
355
pkg/onebot/value.go
Normal file
355
pkg/onebot/value.go
Normal file
@ -0,0 +1,355 @@
|
|||||||
|
// Copyright 2022 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package onebot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A Value can represent any Go value, but unlike type any,
|
||||||
|
// it can represent most small values without an allocation.
|
||||||
|
// The zero Value corresponds to nil.
|
||||||
|
type Value struct {
|
||||||
|
_ [0]func() // disallow ==
|
||||||
|
num uint64 // hold number value
|
||||||
|
any any // hold Kind or other value
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
stringptr *byte // used in Value.any when the Value is a string
|
||||||
|
groupptr *Attr // used in Value.any when the Value is a []Attr
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate stringer -type=Kind -trimprefix=Kind
|
||||||
|
|
||||||
|
// Kind is the kind of Value.
|
||||||
|
type Kind int
|
||||||
|
|
||||||
|
// Kind
|
||||||
|
const (
|
||||||
|
KindAny Kind = iota
|
||||||
|
KindBool
|
||||||
|
KindDuration
|
||||||
|
KindFloat64
|
||||||
|
KindInt64
|
||||||
|
KindString
|
||||||
|
KindTime
|
||||||
|
KindUint64
|
||||||
|
KindGroup
|
||||||
|
)
|
||||||
|
|
||||||
|
// Unexported version of Kind, just so we can store Kinds in Values.
|
||||||
|
// (No user-provided value has this type.)
|
||||||
|
type kind Kind
|
||||||
|
|
||||||
|
// Kind returns v's Kind.
|
||||||
|
func (v Value) Kind() Kind {
|
||||||
|
switch x := v.any.(type) {
|
||||||
|
case Kind:
|
||||||
|
return x
|
||||||
|
case stringptr:
|
||||||
|
return KindString
|
||||||
|
case timeLocation:
|
||||||
|
return KindTime
|
||||||
|
case groupptr:
|
||||||
|
return KindGroup
|
||||||
|
case kind: // a kind is just a wrapper for a Kind
|
||||||
|
return KindAny
|
||||||
|
default:
|
||||||
|
return KindAny
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////// Constructors
|
||||||
|
|
||||||
|
// StringValue returns a new Value for a string.
|
||||||
|
func StringValue(value string) Value {
|
||||||
|
return Value{num: uint64(len(value)), any: stringptr(unsafe.StringData(value))}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntValue returns a Value for an int.
|
||||||
|
func IntValue(v int) Value {
|
||||||
|
return Int64Value(int64(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64Value returns a Value for an int64.
|
||||||
|
func Int64Value(v int64) Value {
|
||||||
|
return Value{num: uint64(v), any: KindInt64}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint64Value returns a Value for a uint64.
|
||||||
|
func Uint64Value(v uint64) Value {
|
||||||
|
return Value{num: v, any: KindUint64}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64Value returns a Value for a floating-point number.
|
||||||
|
func Float64Value(v float64) Value {
|
||||||
|
return Value{num: math.Float64bits(v), any: KindFloat64}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolValue returns a Value for a bool.
|
||||||
|
func BoolValue(v bool) Value {
|
||||||
|
u := uint64(0)
|
||||||
|
if v {
|
||||||
|
u = 1
|
||||||
|
}
|
||||||
|
return Value{num: u, any: KindBool}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unexported version of *time.Location, just so we can store *time.Locations in
|
||||||
|
// Values. (No user-provided value has this type.)
|
||||||
|
type timeLocation *time.Location
|
||||||
|
|
||||||
|
// TimeValue returns a Value for a time.Time.
|
||||||
|
// It discards the monotonic portion.
|
||||||
|
func TimeValue(v time.Time) Value {
|
||||||
|
if v.IsZero() {
|
||||||
|
// UnixNano on the zero time is undefined, so represent the zero time
|
||||||
|
// with a nil *time.Location instead. time.Time.Location method never
|
||||||
|
// returns nil, so a Value with any == timeLocation(nil) cannot be
|
||||||
|
// mistaken for any other Value, time.Time or otherwise.
|
||||||
|
return Value{any: timeLocation(nil)}
|
||||||
|
}
|
||||||
|
return Value{num: uint64(v.UnixNano()), any: timeLocation(v.Location())}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DurationValue returns a Value for a time.Duration.
|
||||||
|
func DurationValue(v time.Duration) Value {
|
||||||
|
return Value{num: uint64(v.Nanoseconds()), any: KindDuration}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupValue returns a new Value for a list of Attrs.
|
||||||
|
// The caller must not subsequently mutate the argument slice.
|
||||||
|
func GroupValue(as ...Attr) Value {
|
||||||
|
return Value{num: uint64(len(as)), any: groupptr(unsafe.SliceData(as))}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnyValue returns a Value for the supplied value.
|
||||||
|
//
|
||||||
|
// If the supplied value is of type Value, it is returned
|
||||||
|
// unmodified.
|
||||||
|
//
|
||||||
|
// Given a value of one of Go's predeclared string, bool, or
|
||||||
|
// (non-complex) numeric types, AnyValue returns a Value of kind
|
||||||
|
// String, Bool, Uint64, Int64, or Float64. The width of the
|
||||||
|
// original numeric type is not preserved.
|
||||||
|
//
|
||||||
|
// Given a time.Time or time.Duration value, AnyValue returns a Value of kind
|
||||||
|
// KindTime or KindDuration. The monotonic time is not preserved.
|
||||||
|
//
|
||||||
|
// For nil, or values of all other types, including named types whose
|
||||||
|
// underlying type is numeric, AnyValue returns a value of kind KindAny.
|
||||||
|
func AnyValue(v any) Value {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case string:
|
||||||
|
return StringValue(v)
|
||||||
|
case int:
|
||||||
|
return Int64Value(int64(v))
|
||||||
|
case uint:
|
||||||
|
return Uint64Value(uint64(v))
|
||||||
|
case int64:
|
||||||
|
return Int64Value(v)
|
||||||
|
case uint64:
|
||||||
|
return Uint64Value(v)
|
||||||
|
case bool:
|
||||||
|
return BoolValue(v)
|
||||||
|
case time.Duration:
|
||||||
|
return DurationValue(v)
|
||||||
|
case time.Time:
|
||||||
|
return TimeValue(v)
|
||||||
|
case uint8:
|
||||||
|
return Uint64Value(uint64(v))
|
||||||
|
case uint16:
|
||||||
|
return Uint64Value(uint64(v))
|
||||||
|
case uint32:
|
||||||
|
return Uint64Value(uint64(v))
|
||||||
|
case uintptr:
|
||||||
|
return Uint64Value(uint64(v))
|
||||||
|
case int8:
|
||||||
|
return Int64Value(int64(v))
|
||||||
|
case int16:
|
||||||
|
return Int64Value(int64(v))
|
||||||
|
case int32:
|
||||||
|
return Int64Value(int64(v))
|
||||||
|
case float64:
|
||||||
|
return Float64Value(v)
|
||||||
|
case float32:
|
||||||
|
return Float64Value(float64(v))
|
||||||
|
case []Attr:
|
||||||
|
return GroupValue(v...)
|
||||||
|
case Kind:
|
||||||
|
return Value{any: kind(v)}
|
||||||
|
case Value:
|
||||||
|
return v
|
||||||
|
default:
|
||||||
|
return Value{any: v}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////// Accessors
|
||||||
|
|
||||||
|
// Any returns v's value as an any.
|
||||||
|
func (v Value) Any() any {
|
||||||
|
switch v.Kind() {
|
||||||
|
case KindAny:
|
||||||
|
if k, ok := v.any.(kind); ok {
|
||||||
|
return Kind(k)
|
||||||
|
}
|
||||||
|
return v.any
|
||||||
|
case KindGroup:
|
||||||
|
return v.group()
|
||||||
|
case KindInt64:
|
||||||
|
return int64(v.num)
|
||||||
|
case KindUint64:
|
||||||
|
return v.num
|
||||||
|
case KindFloat64:
|
||||||
|
return v.float()
|
||||||
|
case KindString:
|
||||||
|
return v.str()
|
||||||
|
case KindBool:
|
||||||
|
return v.bool()
|
||||||
|
case KindDuration:
|
||||||
|
return v.duration()
|
||||||
|
case KindTime:
|
||||||
|
return v.time()
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns Value's value as a string, formatted like fmt.Sprint. Unlike
|
||||||
|
// the methods Int64, Float64, and so on, which panic if v is of the
|
||||||
|
// wrong kind, String never panics.
|
||||||
|
func (v Value) String() string {
|
||||||
|
if sp, ok := v.any.(stringptr); ok {
|
||||||
|
return unsafe.String(sp, v.num)
|
||||||
|
}
|
||||||
|
var buf []byte
|
||||||
|
return string(v.append(buf))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Value) str() string {
|
||||||
|
return unsafe.String(v.any.(stringptr), v.num)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64 returns v's value as an int64. It panics
|
||||||
|
// if v is not a signed integer.
|
||||||
|
func (v Value) Int64() int64 {
|
||||||
|
if g, w := v.Kind(), KindInt64; g != w {
|
||||||
|
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||||
|
}
|
||||||
|
return int64(v.num)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint64 returns v's value as a uint64. It panics
|
||||||
|
// if v is not an unsigned integer.
|
||||||
|
func (v Value) Uint64() uint64 {
|
||||||
|
if g, w := v.Kind(), KindUint64; g != w {
|
||||||
|
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||||
|
}
|
||||||
|
return v.num
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns v's value as a bool. It panics
|
||||||
|
// if v is not a bool.
|
||||||
|
func (v Value) Bool() bool {
|
||||||
|
if g, w := v.Kind(), KindBool; g != w {
|
||||||
|
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||||
|
}
|
||||||
|
return v.bool()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Value) bool() bool {
|
||||||
|
return v.num == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duration returns v's value as a time.Duration. It panics
|
||||||
|
// if v is not a time.Duration.
|
||||||
|
func (v Value) Duration() time.Duration {
|
||||||
|
if g, w := v.Kind(), KindDuration; g != w {
|
||||||
|
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.duration()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Value) duration() time.Duration {
|
||||||
|
return time.Duration(int64(v.num))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns v's value as a float64. It panics
|
||||||
|
// if v is not a float64.
|
||||||
|
func (v Value) Float64() float64 {
|
||||||
|
if g, w := v.Kind(), KindFloat64; g != w {
|
||||||
|
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.float()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Value) float() float64 {
|
||||||
|
return math.Float64frombits(v.num)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time returns v's value as a time.Time. It panics
|
||||||
|
// if v is not a time.Time.
|
||||||
|
func (v Value) Time() time.Time {
|
||||||
|
if g, w := v.Kind(), KindTime; g != w {
|
||||||
|
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||||
|
}
|
||||||
|
return v.time()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Value) time() time.Time {
|
||||||
|
loc := v.any.(timeLocation)
|
||||||
|
if loc == nil {
|
||||||
|
return time.Time{}
|
||||||
|
}
|
||||||
|
return time.Unix(0, int64(v.num)).In(loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns v's value as a []Attr.
|
||||||
|
// It panics if v's Kind is not KindGroup.
|
||||||
|
func (v Value) Group() []Attr {
|
||||||
|
if sp, ok := v.any.(groupptr); ok {
|
||||||
|
return unsafe.Slice(sp, v.num)
|
||||||
|
}
|
||||||
|
panic("Group: bad kind")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Value) group() []Attr {
|
||||||
|
return unsafe.Slice((*Attr)(v.any.(groupptr)), v.num)
|
||||||
|
}
|
||||||
|
|
||||||
|
// append appends a text representation of v to dst.
|
||||||
|
// v is formatted as with fmt.Sprint.
|
||||||
|
func (v Value) append(dst []byte) []byte {
|
||||||
|
switch v.Kind() {
|
||||||
|
case KindString:
|
||||||
|
return append(dst, v.str()...)
|
||||||
|
case KindInt64:
|
||||||
|
return strconv.AppendInt(dst, int64(v.num), 10)
|
||||||
|
case KindUint64:
|
||||||
|
return strconv.AppendUint(dst, v.num, 10)
|
||||||
|
case KindFloat64:
|
||||||
|
return strconv.AppendFloat(dst, v.float(), 'g', -1, 64)
|
||||||
|
case KindBool:
|
||||||
|
return strconv.AppendBool(dst, v.bool())
|
||||||
|
case KindDuration:
|
||||||
|
return append(dst, v.duration().String()...)
|
||||||
|
case KindTime:
|
||||||
|
return append(dst, v.time().String()...)
|
||||||
|
case KindGroup:
|
||||||
|
return fmt.Append(dst, v.group())
|
||||||
|
case KindAny:
|
||||||
|
return fmt.Append(dst, v.any)
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
echo "Start GOCQHTTP~~~"
|
function index.main_handler() {
|
||||||
|
echo "Start GOCQHTTP~~~"
|
||||||
cp -f config.yml /tmp/config.yml
|
cp -f config.yml /tmp/config.yml
|
||||||
cp -f device.json /tmp/device.json
|
cp -f device.json /tmp/device.json
|
||||||
./go-cqhttp -w="/tmp/" faststart
|
./go-cqhttp -w="/tmp/" faststart
|
||||||
|
}
|
||||||
|
index.main_handler
|
||||||
|
Reference in New Issue
Block a user