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