mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 03:43:25 +00:00
Compare commits
18 Commits
v0.9.40-fi
...
v0.9.40-fi
Author | SHA1 | Date | |
---|---|---|---|
5049a8f697 | |||
c0260bc82d | |||
8185c4cdf1 | |||
0bcd16b252 | |||
b2738d909b | |||
95f2227898 | |||
cdb700c92f | |||
626de1cb17 | |||
bfc3958f34 | |||
9a2b69ccf0 | |||
5854f51506 | |||
cf5d3cef95 | |||
6864dc449b | |||
b781c3b43b | |||
e36a9a95c5 | |||
a639b60155 | |||
77e0363e32 | |||
5d0d8f3908 |
@ -279,4 +279,4 @@ go-cqhttp兼容[OneBot-v11](https://github.com/howmanybots/onebot/tree/master/v1
|
|||||||
|
|
||||||
## 性能
|
## 性能
|
||||||
|
|
||||||
在关闭数据库的情况下, 加载 25 个好友 128 个群运行 24 小时后内存使用为 10MB 左右. 开启数据库后内存使用将根据消息量增加 10-20MB, 如果系统内存小于 128M 建议关闭数据库使用.
|
在关闭数据库的情况下, 加载 25 个好友 128 个群运行 24 小时后内存使用为 15MB 左右. 开启数据库后内存使用将根据消息量增加 10-20MB, 如果系统内存小于 128M 建议关闭数据库使用.
|
||||||
|
14
coolq/api.go
14
coolq/api.go
@ -22,7 +22,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version go-cqhttp的版本信息,在编译时使用ldfalgs进行覆盖
|
// Version go-cqhttp的版本信息,在编译时使用ldflags进行覆盖
|
||||||
var Version = "unknown"
|
var Version = "unknown"
|
||||||
|
|
||||||
// CQGetLoginInfo 获取登录号信息
|
// CQGetLoginInfo 获取登录号信息
|
||||||
@ -438,12 +438,12 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
// CQSendPrivateMessage 发送私聊消息
|
// CQSendPrivateMessage 发送私聊消息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1l
|
// https://git.io/Jtz1l
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape bool) MSG {
|
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupId int64, i interface{}, autoEscape bool) MSG {
|
||||||
var str string
|
var str string
|
||||||
if m, ok := i.(gjson.Result); ok {
|
if m, ok := i.(gjson.Result); ok {
|
||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
elem := bot.ConvertObjectMessage(m, false)
|
elem := bot.ConvertObjectMessage(m, false)
|
||||||
mid := bot.SendPrivateMessage(userID, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userID, groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape b
|
|||||||
} else {
|
} else {
|
||||||
elem = bot.ConvertStringMessage(str, false)
|
elem = bot.ConvertStringMessage(str, false)
|
||||||
}
|
}
|
||||||
mid := bot.SendPrivateMessage(userID, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userID, groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
@ -831,9 +831,9 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
if reply.Exists() {
|
if reply.Exists() {
|
||||||
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
||||||
|
|
||||||
at := !isAnonymous // 除匿名消息场合外默认 true
|
at := !isAnonymous && msgType == "group" // 除匿名消息场合外默认 true
|
||||||
if operation.Get("at_sender").Exists() {
|
if operation.Get("at_sender").Exists() {
|
||||||
at = operation.Get("at_sender").Bool() && !isAnonymous
|
at = operation.Get("at_sender").Bool() && !isAnonymous && msgType == "group"
|
||||||
}
|
}
|
||||||
|
|
||||||
if at && reply.IsArray() {
|
if at && reply.IsArray() {
|
||||||
@ -874,7 +874,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply, autoEscape)
|
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply, autoEscape)
|
||||||
}
|
}
|
||||||
if msgType == "private" {
|
if msgType == "private" {
|
||||||
bot.CQSendPrivateMessage(context.Get("user_id").Int(), reply, autoEscape)
|
bot.CQSendPrivateMessage(context.Get("user_id").Int(), context.Get("group_id").Int(), reply, autoEscape)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msgType == "group" {
|
if msgType == "group" {
|
||||||
|
27
coolq/bot.go
27
coolq/bot.go
@ -242,7 +242,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendPrivateMessage 发送私聊消息
|
// SendPrivateMessage 发送私聊消息
|
||||||
func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) int32 {
|
func (bot *CQBot) SendPrivateMessage(target int64, groupId int64, m *message.SendingMessage) int32 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if i, ok := elem.(*LocalImageElement); ok {
|
if i, ok := elem.(*LocalImageElement); ok {
|
||||||
@ -294,16 +294,33 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
|||||||
if msg != nil {
|
if msg != nil {
|
||||||
id = bot.InsertPrivateMessage(msg)
|
id = bot.InsertPrivateMessage(msg)
|
||||||
}
|
}
|
||||||
} else if code, ok := bot.tempMsgCache.Load(target); ok { // 临时会话
|
} else if code, ok := bot.tempMsgCache.Load(target); ok || groupId != 0 { // 临时会话
|
||||||
msg := bot.Client.SendTempMessage(code.(int64), target, m)
|
if groupId != 0 && !bot.Client.FindGroup(groupId).AdministratorOrOwner() {
|
||||||
if msg != nil {
|
log.Errorf("错误: 机器人在群(%v) 为非管理员或群主, 无法主动发起临时会话", groupId)
|
||||||
id = bot.InsertTempMessage(target, msg)
|
id = -1
|
||||||
|
} else if groupId != 0 && bot.Client.FindGroup(groupId).FindMember(target) == nil {
|
||||||
|
log.Errorf("错误: 群员(%v) 不在 群(%v), 无法发起临时会话", target, groupId)
|
||||||
|
id = -1
|
||||||
|
} else {
|
||||||
|
if code != nil {
|
||||||
|
groupId = code.(int64)
|
||||||
|
}
|
||||||
|
msg := bot.Client.SendTempMessage(groupId, target, m)
|
||||||
|
if msg != nil {
|
||||||
|
id = bot.InsertTempMessage(target, msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if _, ok := bot.oneWayMsgCache.Load(target); ok { // 单向好友
|
} else if _, ok := bot.oneWayMsgCache.Load(target); ok { // 单向好友
|
||||||
msg := bot.Client.SendPrivateMessage(target, m)
|
msg := bot.Client.SendPrivateMessage(target, m)
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
id = bot.InsertPrivateMessage(msg)
|
id = bot.InsertPrivateMessage(msg)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
nickname := "Unknown"
|
||||||
|
if summaryInfo, _ := bot.Client.GetSummaryInfo(target); summaryInfo != nil {
|
||||||
|
nickname = summaryInfo.Nickname
|
||||||
|
}
|
||||||
|
log.Errorf("错误: 请先添加 %v(%v) 为好友", nickname, target)
|
||||||
}
|
}
|
||||||
if id == -1 {
|
if id == -1 {
|
||||||
return -1
|
return -1
|
||||||
|
@ -360,7 +360,7 @@ func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r st
|
|||||||
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{}
|
var d = map[string]string{}
|
||||||
ptr := unsafe.Pointer((*reflect.SliceHeader)(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
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
|
|||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
"sender": MSG{
|
"sender": MSG{
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
|
"group_id": m.GroupCode,
|
||||||
"nickname": m.Sender.Nickname,
|
"nickname": m.Sender.Nickname,
|
||||||
"sex": "unknown",
|
"sex": "unknown",
|
||||||
"age": 0,
|
"age": 0,
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210302163721-39a33e4c4965
|
github.com/Mrs4s/MiraiGo v0.0.0-20210308011115-8c89d62657af
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/gin-contrib/pprof v1.3.0
|
github.com/gin-contrib/pprof v1.3.0
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
|
8
go.sum
8
go.sum
@ -1,7 +1,10 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210302163721-39a33e4c4965 h1:zrm7q2Wnj82pqdbaF72es7SYm2aV4dlrwfvVcNoR4hc=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210305105331-e11fa95c501f h1:jwejWu/frFn1yf/VS7ZBKt1LU9ASU70kXCysQsXl6Ns=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210302163721-39a33e4c4965/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210305105331-e11fa95c501f/go.mod h1:drSlh4LlYtjOMJxirScUCSnylBKi1NIRxUz7TKdSsNs=
|
||||||
|
github.com/Mrs4s/MiraiGo v0.0.0-20210308011115-8c89d62657af h1:PPjWwM/KwbHzOyaEwKm3W5JrK6TTxpOSf+Sd4JXxF9s=
|
||||||
|
github.com/Mrs4s/MiraiGo v0.0.0-20210308011115-8c89d62657af/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
||||||
|
github.com/a8m/syncmap v0.0.0-20200818084611-4bbbd178de97/go.mod h1:f3iF7/3t9i9hsYF8DPgT0XeIVyNzevhMCKf2445Q6pE=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -155,6 +158,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
|||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190501045030-23463209683d/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
11
main.go
11
main.go
@ -119,11 +119,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if terminal.RunningByDoubleClick() {
|
|
||||||
log.Warning("警告: 强烈不推荐通过双击直接运行本程序, 这将导致一些非预料的后果.")
|
|
||||||
log.Warning("将等待10s后启动")
|
|
||||||
time.Sleep(time.Second * 10)
|
|
||||||
}
|
|
||||||
var byteKey []byte
|
var byteKey []byte
|
||||||
arg := os.Args
|
arg := os.Args
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
@ -145,7 +140,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if terminal.RunningByDoubleClick() && !isFastStart {
|
||||||
|
log.Warning("警告: 强烈不推荐通过双击直接运行本程序, 这将导致一些非预料的后果.")
|
||||||
|
log.Warning("将等待10s后启动")
|
||||||
|
time.Sleep(time.Second * 10)
|
||||||
|
}
|
||||||
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
||||||
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
||||||
if !isFastStart {
|
if !isFastStart {
|
||||||
|
@ -45,17 +45,17 @@ func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
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" {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
if p.Get("message_type").Str == "group" {
|
if p.Get("message_type").Str == "group" {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
|
if p.Get("user_id").Int() != 0 {
|
||||||
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
|
}
|
||||||
if p.Get("group_id").Int() != 0 {
|
if p.Get("group_id").Int() != 0 {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
if p.Get("user_id").Int() != 0 {
|
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
|
|
||||||
}
|
|
||||||
return coolq.MSG{}
|
return coolq.MSG{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ func sendGroupForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"),
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"),
|
||||||
global.EnsureBool(p.Get("auto_escape"), false))
|
global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user