Skip to content

Commit

Permalink
Beta320 (#323)
Browse files Browse the repository at this point in the history
* beta318

* beta319

* beta320
  • Loading branch information
Hoshinonyaruko authored Feb 12, 2024
1 parent 3b7440f commit 645d49e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type Settings struct {
LinkBots []string `yaml:"link_bots"`
LinkText string `yaml:"link_text"`
LinkPic string `yaml:"link_pic"`
MusicPrefix string `yaml:"music_prefix"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -1763,3 +1764,15 @@ func GetLinkPic() string {
}
return instance.Settings.LinkPic
}

// 获取 GetMusicPrefix
func GetMusicPrefix() string {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to get MusicPrefix.")
return ""
}
return instance.Settings.MusicPrefix
}
20 changes: 18 additions & 2 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,25 @@ func createMusicKeyboard(jumpURL string, musicURL string) *keyboard.MessageKeybo
// },
// }

//自传播按钮
musicPrefix := config.GetMusicPrefix()
playNowButton := &keyboard.Button{
RenderData: &keyboard.RenderData{
Label: "我也要点歌",
VisitedLabel: "再次点歌",
Style: 1, // 蓝色边缘
},
Action: &keyboard.Action{
Type: 2, // 链接类型
Permission: &keyboard.Permission{Type: 2}, // 所有人可操作
Data: musicPrefix + " ",
UnsupportTips: "请升级新版手机QQ",
},
}

// 将按钮添加到当前行
// currentRow.Buttons = append(currentRow.Buttons, songPageButton, playNowButton)
currentRow.Buttons = append(currentRow.Buttons, songPageButton)
currentRow.Buttons = append(currentRow.Buttons, songPageButton, playNowButton)
//currentRow.Buttons = append(currentRow.Buttons, songPageButton)

// 将当前行添加到自定义键盘
customKeyboard.Rows = append(customKeyboard.Rows, currentRow)
Expand Down
38 changes: 18 additions & 20 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
mylog.Printf("send_group_msg获取到信息类型:%v", msgType)
var idInt64 int64
var err error
var ret *dto.GroupMessageResponse
var retmsg string

if message.Params.GroupID != "" {
Expand Down Expand Up @@ -149,7 +148,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if SSM {
//mylog.Printf("正在使用Msgid:%v 补发之前失败的主动信息,请注意AtoP不要设置超过3,否则可能会影响正常信息发送", messageID)
//mylog.Printf("originalGroupID:%v ", originalGroupID)
SendStackMessages(apiv2, messageID, originalGroupID)
SendStackMessages(apiv2, messageID, message.Params.GroupID.(string))
}
mylog.Println("群组发信息messageText:", messageText)
//mylog.Println("foundItems:", foundItems)
Expand Down Expand Up @@ -260,12 +259,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap

}
// 发送组合消息
ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
_, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送组合消息失败: %v", err)
return "", nil // 或其他错误处理
}
if ret != nil && ret.Message.Ret == 22009 {
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送")
var pair echo.MessageGroupPair
pair.Group = message.Params.GroupID.(string)
Expand Down Expand Up @@ -295,11 +294,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap

groupMessage.Timestamp = time.Now().Unix() // 设置时间戳
//重新为err赋值
ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
_, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送文本群组信息失败: %v", err)
}
if ret != nil && ret.Message.Ret == 22009 {
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送")
var pair echo.MessageGroupPair
pair.Group = message.Params.GroupID.(string)
Expand Down Expand Up @@ -331,11 +330,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
return "", nil // 或其他错误处理
}
//重新为err赋值
ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
_, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送md信息失败: %v", err)
}
if ret != nil && ret.Message.Ret == 22009 {
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送")
var pair echo.MessageGroupPair
pair.Group = message.Params.GroupID.(string)
Expand All @@ -362,11 +361,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
}
groupMessage.Timestamp = time.Now().Unix() // 设置时间戳
//重新为err赋值
ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
_, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送文本报错信息失败: %v", err)
}
if ret != nil && ret.Message.Ret == 22009 {
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送")
var pair echo.MessageGroupPair
pair.Group = message.Params.GroupID.(string)
Expand All @@ -390,11 +389,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
}
groupMessage.Timestamp = time.Now().Unix() // 设置时间戳
//重新为err赋值
ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
_, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送图片失败: %v", err)
}
if ret != nil && ret.Message.Ret == 22009 {
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送")
var pair echo.MessageGroupPair
pair.Group = message.Params.GroupID.(string)
Expand Down Expand Up @@ -1053,20 +1052,19 @@ func uploadMedia(ctx context.Context, groupID string, richMediaMessage *dto.Rich
}

// 发送栈中的消息
func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, originalGroupID string) {
func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, GroupID string) {
count := config.GetAtoPCount()
mylog.Printf("取出数量: %v", count)
pairs := echo.PopGlobalStackMulti(count)
for i, pair := range pairs {
mylog.Printf("%v: %v", pair.Group, originalGroupID)
if pair.Group == originalGroupID {
mylog.Printf("%v: %v", pair.Group, GroupID)
if pair.Group == GroupID {
// 发送消息
messageID := pair.GroupMessage.MsgID
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
msgseq := echo.GetMappingSeq(messageid)
echo.AddMappingSeq(messageid, msgseq+1)
pair.GroupMessage.MsgSeq = msgseq + 1
pair.GroupMessage.MsgID = messageid
ret, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage)
_, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage)
if err != nil {
mylog.Printf("发送组合消息失败: %v", err)
continue
Expand All @@ -1075,7 +1073,7 @@ func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, originalGroupID
}

// 检查错误码
if ret != nil && ret.Message.Ret == 22009 {
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息再次发送失败,加入到队列中,下次被动信息进行发送")
echo.PushGlobalStack(pair)
}
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ settings:
me_prefix : "/me" #需设置 #增强配置项 master_id 可触发
unlock_prefix : "/unlock" #频道私信卡住了? gsk可以帮到你 在任意子频道发送unlock 你会收到来自机器人的频道私信
link_prefix : "/link" #友情链接配置 配置custom_template_id后可用(https://www.yuque.com/km57bt/hlhnxg/tzbr84y59dbz6pib)
music_prefix : "点歌" #[CQ:music,type=qq,id=123] 在消息文本组合qq音乐歌曲id,可以发送点歌,这是歌曲按钮第二个按钮的填充内容,应为你的机器人点歌插件的指令.
link_bots : ["",""] #发送友情链接时 下方按钮携带的机器人 格式 "appid-qq-name","appid-qq-name"
link_text : "" #友情链接文本 不可为空!
link_pic : "" #友情链接图片 可为空 需url图片 可带端口 不填可能会有显示错误
Expand Down

0 comments on commit 645d49e

Please sign in to comment.