1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-30 11:53:25 +00:00

Compare commits

..

18 Commits

Author SHA1 Message Date
5049a8f697 Merge pull request #697 from povsister/ldflags-typo
Fix a comment typo
2021-03-09 16:11:39 +08:00
c0260bc82d update MiraiGo. 2021-03-09 16:07:29 +08:00
8185c4cdf1 fix typo 2021-03-08 22:32:15 +08:00
0bcd16b252 Merge pull request #702 from sam01101/dev
限制 handle_quick_op... 的 at_sender 使用场景
2021-03-08 08:35:17 +08:00
Sam
b2738d909b 限制 handle_quick_op... 的 at_sender 使用场景, Closes #701 2021-03-06 20:31:58 +08:00
95f2227898 Merge pull request #698 from sam01101/dev
Fix bug
2021-03-05 19:59:59 +08:00
cdb700c92f update MiraiGo. 2021-03-05 19:03:09 +08:00
Sam
626de1cb17 Closes #556 2021-03-05 17:34:21 +08:00
bfc3958f34 Fix a comment typo 2021-03-05 12:57:07 +08:00
9a2b69ccf0 Merge branch 'dev' of https://github.com/Mrs4s/go-cqhttp into dev 2021-03-04 19:49:32 +08:00
5854f51506 update MiraiGo. 2021-03-04 19:49:19 +08:00
cf5d3cef95 Merge pull request #696 from sam01101/dev
临时会话添加Group字段, Fixes #695
2021-03-04 16:36:24 +08:00
6864dc449b more memory usage. 2021-03-04 16:16:54 +08:00
b781c3b43b [temp_msg] Changed gorup_id to sender list 2021-03-04 16:11:41 +08:00
e36a9a95c5 update MiraiGo. 2021-03-04 16:09:10 +08:00
Sam
a639b60155 临时会话添加Group字段, Fixes #695 2021-03-04 15:13:22 +08:00
77e0363e32 update. 2021-03-04 11:13:33 +08:00
5d0d8f3908 update MiraiGo. fix #689 2021-03-04 09:07:07 +08:00
9 changed files with 49 additions and 28 deletions

View File

@ -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 建议关闭数据库使用.

View File

@ -22,7 +22,7 @@ import (
log "github.com/sirupsen/logrus"
)
// Version go-cqhttp的版本信息在编译时使用ldfalgs进行覆盖
// Version go-cqhttp的版本信息在编译时使用ldflags进行覆盖
var Version = "unknown"
// CQGetLoginInfo 获取登录号信息
@ -438,12 +438,12 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
// CQSendPrivateMessage 发送私聊消息
//
// 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
if m, ok := i.(gjson.Result); ok {
if m.Type == gjson.JSON {
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 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
}
@ -468,7 +468,7 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape b
} else {
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 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
}
@ -831,9 +831,9 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
if reply.Exists() {
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
at := !isAnonymous // 除匿名消息场合外默认 true
at := !isAnonymous && msgType == "group" // 除匿名消息场合外默认 true
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() {
@ -874,7 +874,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply, autoEscape)
}
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" {

View File

@ -242,7 +242,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int
}
// 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
for _, elem := range m.Elements {
if i, ok := elem.(*LocalImageElement); ok {
@ -294,16 +294,33 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
if msg != nil {
id = bot.InsertPrivateMessage(msg)
}
} else if code, ok := bot.tempMsgCache.Load(target); ok { // 临时会话
msg := bot.Client.SendTempMessage(code.(int64), target, m)
if msg != nil {
id = bot.InsertTempMessage(target, msg)
} else if code, ok := bot.tempMsgCache.Load(target); ok || groupId != 0 { // 临时会话
if groupId != 0 && !bot.Client.FindGroup(groupId).AdministratorOrOwner() {
log.Errorf("错误: 机器人在群(%v) 为非管理员或群主, 无法主动发起临时会话", groupId)
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 { // 单向好友
msg := bot.Client.SendPrivateMessage(target, m)
if msg != nil {
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 {
return -1

View File

@ -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) {
var t, key 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)
i, j, CQBegin := 0, 0, 0

View File

@ -123,6 +123,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
"time": time.Now().Unix(),
"sender": MSG{
"user_id": m.Sender.Uin,
"group_id": m.GroupCode,
"nickname": m.Sender.Nickname,
"sex": "unknown",
"age": 0,

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.16
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/gin-contrib/pprof v1.3.0
github.com/gin-gonic/gin v1.6.3

8
go.sum
View File

@ -1,7 +1,10 @@
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/Mrs4s/MiraiGo v0.0.0-20210302163721-39a33e4c4965 h1:zrm7q2Wnj82pqdbaF72es7SYm2aV4dlrwfvVcNoR4hc=
github.com/Mrs4s/MiraiGo v0.0.0-20210302163721-39a33e4c4965/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
github.com/Mrs4s/MiraiGo v0.0.0-20210305105331-e11fa95c501f h1:jwejWu/frFn1yf/VS7ZBKt1LU9ASU70kXCysQsXl6Ns=
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/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
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-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-20190501045030-23463209683d/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=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

11
main.go
View File

@ -119,11 +119,6 @@ func init() {
}
func main() {
if terminal.RunningByDoubleClick() {
log.Warning("警告: 强烈不推荐通过双击直接运行本程序, 这将导致一些非预料的后果.")
log.Warning("将等待10s后启动")
time.Sleep(time.Second * 10)
}
var byteKey []byte
arg := os.Args
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 == "") {
log.Warnf("请修改 config.hjson 以添加账号密码.")
if !isFastStart {

View File

@ -45,17 +45,17 @@ func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
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" {
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 {
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{}
}
@ -69,7 +69,7 @@ func sendGroupForwardMSG(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))
}