mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
all: optimize
detected by go-perfguard
This commit is contained in:
parent
ee9af5fa69
commit
d522378315
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user