Skip to content

Commit

Permalink
Beta135 (#310)
Browse files Browse the repository at this point in the history
* beta122

* beta123

* beta124

* beta124

* beta124

* beta127

* beta128

* beta129

* beta130

* beta131

* beta132

* beta133

* beta134

* beta135
  • Loading branch information
Hoshinonyaruko authored Jan 19, 2024
1 parent d3a488e commit dcde24f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 23 deletions.
7 changes: 2 additions & 5 deletions handlers/get_group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,11 @@ func HandleGetGroupInfo(client callapi.Client, api openapi.OpenAPI, apiv2 openap
// 当 message.Echo 是字符串类型时执行此块
msgType = echo.GetMsgTypeByKey(echoStr)
}
//如果获取不到 就用user_id获取信息类型
if msgType == "" {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}

//如果获取不到 就用group_id获取信息类型
if msgType == "" {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
switch msgType {
case "guild", "guild_private":
Expand Down
42 changes: 28 additions & 14 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,24 +617,38 @@ func RevertTransformedText(data interface{}, msgtype string, api openapi.OpenAPI
allPrefixes = append(allPrefixes, temporaryCommands...)
matched := false

// 遍历白名单数组,检查是否有匹配项
// 检查allPrefixes中的每个prefix是否都以*开头
allStarPrefixed := true
for _, prefix := range allPrefixes {
trimmedPrefix := prefix
if strings.HasPrefix(prefix, "*") {
// 如果前缀以 * 开头,则移除 *
trimmedPrefix = strings.TrimPrefix(prefix, "*")
} else if strings.HasPrefix(prefix, "&") {
// 如果前缀以 & 开头,则移除 & 并从 trimmedPrefix 前端去除 matchedPrefix.Prefix
trimmedPrefix = strings.TrimPrefix(prefix, "&")
trimmedPrefix = strings.TrimPrefix(trimmedPrefix, matchedPrefix.Prefix)
if !strings.HasPrefix(prefix, "*") {
allStarPrefixed = false
break
}
}

// 从trimmedPrefix中去除前后空格(可能会有bug)
trimmedPrefix = strings.TrimSpace(trimmedPrefix)
//如果二级指令白名单全部是*(忽略自身,那么不判断二级白名单是否匹配)
if allStarPrefixed {
matched = true
} else {
// 遍历白名单数组,检查是否有匹配项
for _, prefix := range allPrefixes {
trimmedPrefix := prefix
if strings.HasPrefix(prefix, "*") {
// 如果前缀以 * 开头,则移除 *
trimmedPrefix = strings.TrimPrefix(prefix, "*")
} else if strings.HasPrefix(prefix, "&") {
// 如果前缀以 & 开头,则移除 & 并从 trimmedPrefix 前端去除 matchedPrefix.Prefix
trimmedPrefix = strings.TrimPrefix(prefix, "&")
trimmedPrefix = strings.TrimPrefix(trimmedPrefix, matchedPrefix.Prefix)
}

if strings.HasPrefix(messageText, trimmedPrefix) {
matched = true
break
// 从trimmedPrefix中去除前后空格(可能会有bug)
trimmedPrefix = strings.TrimSpace(trimmedPrefix)

if strings.HasPrefix(messageText, trimmedPrefix) {
matched = true
break
}
}
}

Expand Down
44 changes: 40 additions & 4 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,9 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage
var actiondata string
//检查是否设置了enter数组
enter := checkDataLabelPrefix(dataLabel)
switch whiteLabel {
case "邀请机器人", "邀请我", "添加我":

switch {
case strings.HasPrefix(whiteLabel, "邀请机器人"): //默认是群
botuin := config.GetUinStr()
botappid := config.GetAppIDStr()
boturl := BuildQQBotShareLink(botuin, botappid)
Expand All @@ -1184,19 +1185,49 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage
permission = &keyboard.Permission{
Type: 2, // 所有人可操作
}
case "测试按钮回调":
case strings.HasPrefix(whiteLabel, "添加到群聊"):
botuin := config.GetUinStr()
botappid := config.GetAppIDStr()
boturl := BuildQQBotShareLink(botuin, botappid)
actiontype = 0
actiondata = boturl
permission = &keyboard.Permission{
Type: 2, // 所有人可操作
}
case strings.HasPrefix(whiteLabel, "添加到频道"):
botuin := config.GetUinStr()
botappid := config.GetAppIDStr()
boturl := BuildQQBotShareLinkGuild(botuin, botappid)
actiontype = 0
actiondata = boturl
permission = &keyboard.Permission{
Type: 2, // 所有人可操作
}
case strings.HasPrefix(whiteLabel, "权限判断"):
actiontype = 1
actiondata = "收到就代表是管理员哦"
permission = &keyboard.Permission{
Type: 1, // 仅管理可操作
}
case strings.HasPrefix(whiteLabel, "%"):
// 分割whiteLabel来获取显示内容和URL
parts := strings.SplitN(whiteLabel[1:], " ", 2) // [1:] 用于去除白名单标签开头的'%'
if len(parts) == 2 {
whiteLabel = parts[0] // 显示内容
actiondata = parts[1] // URL
actiontype = 0 // 链接类型
permission = &keyboard.Permission{
Type: 2, // 所有人可操作
}
}
default:
actiontype = 2 //帮用户输入指令
actiontype = 2 //帮用户输入指令 用户自己回车发送
actiondata = dataLabel //从虚拟前缀的二级指令组合md按钮
permission = &keyboard.Permission{
Type: 2, // 所有人可操作
}
}

// 创建按钮
button := &keyboard.Button{
RenderData: &keyboard.RenderData{
Expand Down Expand Up @@ -1241,6 +1272,11 @@ func BuildQQBotShareLink(uin string, appid string) string {
return fmt.Sprintf("https://qun.qq.com/qunpro/robot/qunshare?robot_uin=%s&robot_appid=%s", uin, appid)
}

// 构建QQ群机器人分享链接的函数
func BuildQQBotShareLinkGuild(uin string, appid string) string {
return fmt.Sprintf("https://qun.qq.com/qunpro/robot/share?robot_appid=%s", appid)
}

// 检查dataLabel是否以config中getenters返回的任一字符串开头
func checkDataLabelPrefix(dataLabel string) bool {
enters := config.GetEnters()
Expand Down

0 comments on commit dcde24f

Please sign in to comment.