diff --git a/coolq/api.go b/coolq/api.go index 486b543..44a52e8 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -1342,7 +1342,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) global if reply.Exists() { autoEscape := param.EnsureBool(operation.Get("auto_escape"), false) - at := operation.Get("at_sender").Bool() && !isAnonymous && msgType == "group" + at := !isAnonymous && operation.Get("at_sender").Bool() && msgType == "group" if at && reply.IsArray() { // 在 reply 数组头部插入CQ码 replySegments := make([]global.MSG, 0) @@ -1388,7 +1388,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) global if operation.Get("delete").Bool() { bot.CQDeleteMessage(int32(context.Get("message_id").Int())) } - if operation.Get("kick").Bool() && !isAnonymous { + if !isAnonymous && operation.Get("kick").Bool() { bot.CQSetGroupKick(context.Get("group_id").Int(), context.Get("user_id").Int(), "", operation.Get("reject_add_request").Bool()) } if operation.Get("ban").Bool() { diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 1e97f4b..6b9edac 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -209,7 +209,7 @@ func ToArrayMessage(e []message.IMessageElement, source message.Source) (r []glo case *message.DiceElement: m = global.MSG{ "type": "dice", - "data": map[string]string{"value": fmt.Sprint(o.Value)}, + "data": map[string]string{"value": strconv.FormatInt(int64(o.Value), 10)}, } case *message.MarketFaceElement: m = global.MSG{ @@ -1192,7 +1192,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video bool, sourceTy } return &LocalImageElement{File: fu.Path, URL: f}, nil } - if strings.HasPrefix(f, "base64") && !video { + if !video && strings.HasPrefix(f, "base64") { b, err := param.Base64DecodeString(strings.TrimPrefix(f, "base64://")) if err != nil { return nil, err diff --git a/db/leveldb/writer.go b/db/leveldb/writer.go index a8fe707..baed92a 100644 --- a/db/leveldb/writer.go +++ b/db/leveldb/writer.go @@ -2,7 +2,6 @@ package leveldb import ( "bytes" - "io" "github.com/Mrs4s/go-cqhttp/global" ) @@ -125,7 +124,7 @@ func (w *writer) bytes() []byte { out.uvarint(dataVersion) out.uvarint(uint64(w.strings.Len())) out.uvarint(uint64(w.data.Len())) - _, _ = io.Copy(&out, &w.strings) - _, _ = io.Copy(&out, &w.data) + _, _ = w.strings.WriteTo(&out) + _, _ = w.data.WriteTo(&out) return out.Bytes() } diff --git a/global/log_hook.go b/global/log_hook.go index b93f130..44f4f1d 100644 --- a/global/log_hook.go +++ b/global/log_hook.go @@ -195,7 +195,8 @@ func (f LogFormat) Format(entry *logrus.Entry) ([]byte, error) { buf.WriteString(colorReset) } - ret := append([]byte(nil), buf.Bytes()...) // copy buffer + ret := make([]byte, len(buf.Bytes())) + copy(ret, buf.Bytes()) // copy buffer return ret, nil } diff --git a/global/net.go b/global/net.go index ce74edb..c72000a 100644 --- a/global/net.go +++ b/global/net.go @@ -79,7 +79,7 @@ func DownloadFile(url, path string, limit int64, headers map[string]string) erro if limit > 0 && resp.ContentLength > limit { return ErrOverSize } - _, err = io.Copy(file, resp.Body) + _, err = file.ReadFrom(resp.Body) if err != nil { return err } @@ -107,7 +107,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int, return err } defer file.Close() - if _, err = io.Copy(file, s); err != nil { + if _, err = file.ReadFrom(s); err != nil { return err } return errUnsupportedMultiThreading diff --git a/internal/selfupdate/update.go b/internal/selfupdate/update.go index 5aa52a3..8771502 100644 --- a/internal/selfupdate/update.go +++ b/internal/selfupdate/update.go @@ -188,7 +188,7 @@ func fromStream(updateWith io.Reader) (err error, errRecover error) { } // We won't log this error, because it's always going to happen. defer func() { _ = fp.Close() }() - if _, err = io.Copy(fp, bufio.NewReader(updateWith)); err != nil { + if _, err = bufio.NewReader(updateWith).WriteTo(fp); err != nil { logrus.Errorf("Unable to copy data: %v\n", err) } diff --git a/server/daemon.go b/server/daemon.go index f2746d0..0a570b6 100644 --- a/server/daemon.go +++ b/server/daemon.go @@ -3,9 +3,9 @@ package server // daemon 功能写在这,目前仅支持了-d 作为后台运行参数,stop,start,restart这些功能目前看起来并不需要,可以通过api控制,后续需要的话再补全。 import ( - "fmt" "os" "os/exec" + "strconv" "strings" "github.com/Mrs4s/go-cqhttp/global" @@ -36,7 +36,7 @@ func Daemon() { log.Info("[PID] ", proc.Process.Pid) // pid写入到pid文件中,方便后续stop的时候kill - pidErr := savePid("go-cqhttp.pid", fmt.Sprintf("%d", proc.Process.Pid)) + pidErr := savePid("go-cqhttp.pid", strconv.FormatInt(int64(proc.Process.Pid), 10)) if pidErr != nil { log.Errorf("save pid file error: %v", pidErr) } diff --git a/server/scf.go b/server/scf.go index f41b359..7d95e7f 100644 --- a/server/scf.go +++ b/server/scf.go @@ -54,7 +54,7 @@ func (l *lambdaResponseWriter) flush() error { buffer := global.NewBuffer() defer global.PutBuffer(buffer) body := utils.B2S(l.buf.Bytes()) - header := make(map[string]string) + header := make(map[string]string, len(l.header)) for k, v := range l.header { header[k] = v[0] }