Skip to content

Commit

Permalink
fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
2mf8 committed Aug 1, 2022
1 parent 3b80516 commit cb5d097
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
17 changes: 13 additions & 4 deletions pkg/bot/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,22 @@ func HandleSendChannelMsg(cli *client.QQClient, req *onebot.SendChannelMsgReq) *
log.Warnf("消息为空")
return nil
}
guildId := cli.GuildService.FindGuild(req.GuildId)
if guildId == nil {
log.Warnf("频道不存在")
return nil
}
channelId := guildId.FindChannel(req.ChannelId)
if channelId == nil {
log.Warnf("子频道不存在")
return nil
}
if channelId.ChannelType != client.ChannelTypeText {
log.Warnf("无法发送频道信息: 频道类型错误, 不接受文本信息")
}
miraiMsg := ProtoMsgToMiraiMsg(cli, req.Message, req.AutoEscape)
sendingMessage := &message.SendingMessage{Elements: miraiMsg}
channelInfo, _ := cli.GuildService.FetchChannelInfo(req.GuildId, req.ChannelId)
log.Infof("Bot(%+v) GuildId(%+v) ChannelId(%+v) <- %+v\n", cli.Uin, req.GuildId, req.ChannelId, MiraiMsgToRawMsg(cli, miraiMsg))
if channelInfo.ChannelType != client.ChannelTypeText {
log.Warnf("无法发送频道信息: 频道类型错误, 不接受文本信息")
}
preProcessChannelSendingMessage(cli, req.GuildId, req.ChannelId, sendingMessage)
if len(sendingMessage.Elements) == 0 {
log.Warnf("发送消息内容为空")
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ var GroupRequestLru = NewLruCache(128)
// string:
var GroupInvitedRequestLru = NewLruCache(16)

var GuildAdminLru = NewLruCache(100)
var GuildAdminLru = NewLruCache(2048)

var GetGuildAdminTimeLru = NewLruCache(1)
var GetGuildAdminTimeLru = NewLruCache(100)
2 changes: 1 addition & 1 deletion pkg/gmc/plugins/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func LogGroupMessage(cli *client.QQClient, event *message.GroupMessage) int32 {
func LogChannelMessage(cli *client.QQClient, event *message.GuildChannelMessage) int32 {
log.Infof("Bot(%+v) GuildId(%+v) ChannelId(%+v) -> %+v\n", cli.Uin, event.GuildId, event.ChannelId, bot.MiraiMsgToRawMsg(cli, event.Elements))
return plugin.MessageIgnore
}
}
9 changes: 5 additions & 4 deletions pkg/gmc/plugins/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,22 @@ func ReportGroupMessage(cli *client.QQClient, event *message.GroupMessage) int32

func ReportChannelMessage(cli *client.QQClient, event *message.GuildChannelMessage) int32 {
cache.ChannelMessageLru.Add(event.Id, event)
v, ok := cache.GetGuildAdminTimeLru.Get(1)
v, ok := cache.GetGuildAdminTimeLru.Get(event.GuildId)
gtime, _ := strconv.ParseInt(fmt.Sprintf("%v", v), 10, 64)
if !ok || time.Now().Unix() > gtime {
log.Println("缓存频道管理员更新")
cache.GetGuildAdminTimeLru.Clear()
cache.GetGuildAdminTimeLru.Remove(event.GuildId)
users, _ := cli.GuildService.FetchGuildMemberListWithRole(event.GuildId, event.ChannelId, 0, 2, "")
for _, v := range users.Members {
// log.Println(v.Nickname, v.Role, v.RoleName, v.TinyId, v.Title, v.LastSpeakTime)
if v.Role == 2 {
cache.GuildAdminLru.Remove(v.TinyId)
cache.GuildAdminLru.Add(v.TinyId, v)
} else {
break
}
}
cache.GetGuildAdminTimeLru.Add(1, time.Now().Add(time.Minute*10).Unix())
cache.GetGuildAdminTimeLru.Add(event.GuildId, time.Now().Add(time.Minute*10).Unix())
}

role, _ := cache.GuildAdminLru.Get(event.Sender.TinyId)
Expand Down Expand Up @@ -532,4 +533,4 @@ func ReportOfflineFile(cli *client.QQClient, event *client.OfflineFileEvent) int
}
bot.HandleEventFrame(cli, eventProto)
return plugin.MessageIgnore
}
}

0 comments on commit cb5d097

Please sign in to comment.