mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
ci(chore): Fix stylings
This commit is contained in:
parent
ce63c54a16
commit
15a59d4252
@ -1078,7 +1078,7 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
|
||||
log.Warnf("获取群历史消息失败: %v", err)
|
||||
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
||||
}
|
||||
var ms = make([]MSG, 0, len(msg))
|
||||
ms := make([]MSG, 0, len(msg))
|
||||
for _, m := range msg {
|
||||
id := m.Id
|
||||
bot.checkMedia(m.Elements)
|
||||
@ -1104,7 +1104,7 @@ func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
|
||||
return Failed(100, "REFRESH_STATUS_ERROR", err.Error())
|
||||
}
|
||||
}
|
||||
var d = make([]MSG, 0, len(bot.Client.OnlineClients))
|
||||
d := make([]MSG, 0, len(bot.Client.OnlineClients))
|
||||
for _, oc := range bot.Client.OnlineClients {
|
||||
d = append(d, MSG{
|
||||
"app_id": oc.AppId,
|
||||
@ -1264,7 +1264,7 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
|
||||
}
|
||||
list := make([]MSG, 0, len(msgList))
|
||||
for _, m := range msgList {
|
||||
var msg = MSG{
|
||||
msg := MSG{
|
||||
"sender_nick": m.SenderNick,
|
||||
"sender_time": m.SenderTime,
|
||||
"operator_time": m.AddDigestTime,
|
||||
|
@ -174,7 +174,7 @@ func (bot *CQBot) UploadLocalImageAsPrivate(userID int64, img *LocalImageElement
|
||||
|
||||
// SendGroupMessage 发送群消息
|
||||
func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int32 {
|
||||
var newElem = make([]message.IMessageElement, 0, len(m.Elements))
|
||||
newElem := make([]message.IMessageElement, 0, len(m.Elements))
|
||||
group := bot.Client.FindGroup(groupID)
|
||||
for _, elem := range m.Elements {
|
||||
if i, ok := elem.(*LocalImageElement); ok {
|
||||
@ -246,7 +246,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int
|
||||
|
||||
// SendPrivateMessage 发送私聊消息
|
||||
func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.SendingMessage) int32 {
|
||||
var newElem = make([]message.IMessageElement, 0, len(m.Elements))
|
||||
newElem := make([]message.IMessageElement, 0, len(m.Elements))
|
||||
for _, elem := range m.Elements {
|
||||
if i, ok := elem.(*LocalImageElement); ok {
|
||||
fm, err := bot.UploadLocalImageAsPrivate(target, i)
|
||||
|
@ -46,7 +46,7 @@ var SplitURL = false
|
||||
var magicCQ = uint32(0)
|
||||
|
||||
func init() {
|
||||
var CQHeader = "[CQ:"
|
||||
CQHeader := "[CQ:"
|
||||
magicCQ = *(*uint32)(unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&CQHeader)).Data))
|
||||
}
|
||||
|
||||
@ -55,8 +55,11 @@ func add(ptr unsafe.Pointer, offset uintptr) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(ptr) + offset)
|
||||
}
|
||||
|
||||
const maxImageSize = 1024 * 1024 * 30 // 30MB
|
||||
const maxVideoSize = 1024 * 1024 * 100 // 100MB
|
||||
const (
|
||||
maxImageSize = 1024 * 1024 * 30 // 30MB
|
||||
maxVideoSize = 1024 * 1024 * 100 // 100MB
|
||||
)
|
||||
|
||||
// PokeElement 拍一拍
|
||||
type PokeElement struct {
|
||||
Target int64
|
||||
@ -352,7 +355,7 @@ func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r st
|
||||
// ConvertStringMessage 将消息字符串转为消息元素数组
|
||||
func (bot *CQBot) ConvertStringMessage(s string, isGroup bool) (r []message.IMessageElement) {
|
||||
var t, key string
|
||||
var d = map[string]string{}
|
||||
d := map[string]string{}
|
||||
ptr := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data)
|
||||
l := len(s)
|
||||
i, j, CQBegin := 0, 0, 0
|
||||
@ -760,14 +763,14 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
|
||||
}
|
||||
if d["type"] == "custom" {
|
||||
if d["subtype"] != "" {
|
||||
var subtype = map[string]int{
|
||||
subtype := map[string]int{
|
||||
"qq": message.QQMusic,
|
||||
"163": message.CloudMusic,
|
||||
"migu": message.MiguMusic,
|
||||
"kugou": message.KugouMusic,
|
||||
"kuwo": message.KuwoMusic,
|
||||
}
|
||||
var musicType = 0
|
||||
musicType := 0
|
||||
if tp, ok := subtype[d["subtype"]]; ok {
|
||||
musicType = tp
|
||||
}
|
||||
@ -858,7 +861,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var header = make([]byte, 4)
|
||||
header := make([]byte, 4)
|
||||
_, err = video.Read(header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -970,7 +973,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
||||
}
|
||||
hash := md5.Sum([]byte(f))
|
||||
cacheFile := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
|
||||
var maxSize = func() int64 {
|
||||
maxSize := func() int64 {
|
||||
if video {
|
||||
return maxVideoSize
|
||||
}
|
||||
|
@ -13,9 +13,11 @@ import (
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
var currentPath = getCurrentPath()
|
||||
var DefaultConfFile = path.Join(currentPath, "config.hjson")
|
||||
var AccountToken []byte
|
||||
var (
|
||||
currentPath = getCurrentPath()
|
||||
DefaultConfFile = path.Join(currentPath, "config.hjson")
|
||||
AccountToken []byte
|
||||
)
|
||||
|
||||
// DefaultConfigWithComments 为go-cqhttp的默认配置文件
|
||||
var DefaultConfigWithComments = `
|
||||
@ -286,7 +288,7 @@ func LoadConfig(p string) *JSONConfig {
|
||||
return nil
|
||||
}
|
||||
var dat map[string]interface{}
|
||||
var c = JSONConfig{}
|
||||
c := JSONConfig{}
|
||||
err := hjson.Unmarshal([]byte(ReadAllText(p)), &dat)
|
||||
if err == nil {
|
||||
b, _ := json.Marshal(dat)
|
||||
|
@ -54,7 +54,6 @@ func (hook *LocalHook) pathWrite(entry *logrus.Entry) error {
|
||||
defer fd.Close()
|
||||
|
||||
log, err := hook.formatter.Format(entry)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -142,24 +141,36 @@ func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus
|
||||
func GetLogLevel(level string) []logrus.Level {
|
||||
switch level {
|
||||
case "trace":
|
||||
return []logrus.Level{logrus.TraceLevel, logrus.DebugLevel,
|
||||
return []logrus.Level{
|
||||
logrus.TraceLevel, logrus.DebugLevel,
|
||||
logrus.InfoLevel, logrus.WarnLevel, logrus.ErrorLevel,
|
||||
logrus.FatalLevel, logrus.PanicLevel}
|
||||
logrus.FatalLevel, logrus.PanicLevel,
|
||||
}
|
||||
case "debug":
|
||||
return []logrus.Level{logrus.DebugLevel, logrus.InfoLevel,
|
||||
return []logrus.Level{
|
||||
logrus.DebugLevel, logrus.InfoLevel,
|
||||
logrus.WarnLevel, logrus.ErrorLevel,
|
||||
logrus.FatalLevel, logrus.PanicLevel}
|
||||
logrus.FatalLevel, logrus.PanicLevel,
|
||||
}
|
||||
case "info":
|
||||
return []logrus.Level{logrus.InfoLevel, logrus.WarnLevel,
|
||||
logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel}
|
||||
return []logrus.Level{
|
||||
logrus.InfoLevel, logrus.WarnLevel,
|
||||
logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel,
|
||||
}
|
||||
case "warn":
|
||||
return []logrus.Level{logrus.WarnLevel, logrus.ErrorLevel,
|
||||
logrus.FatalLevel, logrus.PanicLevel}
|
||||
return []logrus.Level{
|
||||
logrus.WarnLevel, logrus.ErrorLevel,
|
||||
logrus.FatalLevel, logrus.PanicLevel,
|
||||
}
|
||||
case "error":
|
||||
return []logrus.Level{logrus.ErrorLevel, logrus.FatalLevel,
|
||||
logrus.PanicLevel}
|
||||
return []logrus.Level{
|
||||
logrus.ErrorLevel, logrus.FatalLevel,
|
||||
logrus.PanicLevel,
|
||||
}
|
||||
default:
|
||||
return []logrus.Level{logrus.InfoLevel, logrus.WarnLevel,
|
||||
logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel}
|
||||
return []logrus.Level{
|
||||
logrus.InfoLevel, logrus.WarnLevel,
|
||||
logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return errors.New("response status unsuccessful: " + strconv.FormatInt(int64(resp.StatusCode), 10))
|
||||
}
|
||||
var buffer = make([]byte, 1024)
|
||||
buffer := make([]byte, 1024)
|
||||
i, err := resp.Body.Read(buffer)
|
||||
for {
|
||||
if err != nil && err != io.EOF {
|
||||
|
@ -6,8 +6,10 @@ import (
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
var limiter *rate.Limiter
|
||||
var limitEnable = false
|
||||
var (
|
||||
limiter *rate.Limiter
|
||||
limitEnable = false
|
||||
)
|
||||
|
||||
// RateLimit 执行API调用速率限制
|
||||
func RateLimit(ctx context.Context) {
|
||||
|
14
main.go
14
main.go
@ -38,12 +38,14 @@ import (
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
var conf *global.JSONConfig
|
||||
var isFastStart = false
|
||||
var c string
|
||||
var d bool
|
||||
var h bool
|
||||
var (
|
||||
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
conf *global.JSONConfig
|
||||
isFastStart = false
|
||||
c string
|
||||
d bool
|
||||
h bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
var debug bool
|
||||
|
@ -42,6 +42,7 @@ func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||
p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("no_cache").Bool(),
|
||||
)
|
||||
}
|
||||
|
||||
func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
|
||||
if p.Get("message_type").Str == "private" {
|
||||
|
@ -30,7 +30,6 @@ func Daemon() {
|
||||
|
||||
proc := exec.Command(os.Args[0], execArgs...)
|
||||
err := proc.Start()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ type webSocketConn struct {
|
||||
|
||||
// WebSocketServer 初始化一个WebSocketServer实例
|
||||
var WebSocketServer = &webSocketServer{}
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user