Skip to content

Commit

Permalink
feat(Adapter):使用适配器方式解析戳一戳CQ码 (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
yichere authored Dec 29, 2024
1 parent 80cb951 commit fb44c24
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion dice/platform_adapter_gocq_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ func (pa *PlatformAdapterGocq) SendToPerson(ctx *MsgContext, userID string, text

text = textAssetsConvert(text)
texts := textSplit(text)

for index, subText := range texts {
re := regexp.MustCompile(`\[CQ:poke,qq=(\d+)\]`)

if re.MatchString(subText) {
re = regexp.MustCompile(`\d+`)
qq := re.FindStringSubmatch(subText)
pa.FriendPoke(qq[0])
texts = append(texts[:index], texts[index+1:]...)
}
}

for _, subText := range texts {
a, _ := json.Marshal(oneBotCommand{
Action: "send_msg",
Expand All @@ -212,6 +224,41 @@ func (pa *PlatformAdapterGocq) SendToPerson(ctx *MsgContext, userID string, text
}
}

type PokeStruct struct {
UserID int64 `json:"user_id"`
GroupID int64 `json:"group_id,omitempty"`
}

func (pa *PlatformAdapterGocq) FriendPoke(userId string) {
userID, _ := strconv.ParseInt(userId, 10, 64)

text, _ := json.Marshal(oneBotCommand{
Action: "friend_poke",
Params: PokeStruct{
UserID: userID,
},
})
s := string(text)

socketSendText(pa.Socket, s)
}

func (pa *PlatformAdapterGocq) GroupPoke(ctx *MsgContext, userId string) {
groupId := strings.ReplaceAll(ctx.Group.GroupID, "QQ-Group:", "")
groupID, _ := strconv.ParseInt(groupId, 10, 64)
userID, _ := strconv.ParseInt(userId, 10, 64)

text, _ := json.Marshal(oneBotCommand{
Action: "group_poke",
Params: PokeStruct{
UserID: userID,
GroupID: groupID,
},
})
s := string(text)
socketSendText(pa.Socket, s)
}

func (pa *PlatformAdapterGocq) SendToGroup(ctx *MsgContext, groupID string, text string, flag string) {
if groupID == "" {
return
Expand Down Expand Up @@ -255,6 +302,17 @@ func (pa *PlatformAdapterGocq) SendToGroup(ctx *MsgContext, groupID string, text
text = textAssetsConvert(text)
texts := textSplit(text)

for index, subText := range texts {
re := regexp.MustCompile(`\[CQ:poke,qq=(\d+)\]`)

if re.MatchString(subText) {
re = regexp.MustCompile(`\d+`)
qq := re.FindStringSubmatch(subText)
pa.GroupPoke(ctx, qq[0])
texts = append(texts[:index], texts[index+1:]...)
}
}

for index, subText := range texts {
var a []byte
if pa.useArrayMessage {
Expand Down Expand Up @@ -627,7 +685,6 @@ func textSplit(input string) []string {
input = input[0:span[0]] + input[span[1]:]
}
}

splits := utils.SplitLongText(input, 2000, utils.DefaultSplitPaginationHint)
splits = append(splits, poke...)

Expand Down

0 comments on commit fb44c24

Please sign in to comment.