From fb44c242b7fb00703595ae46018da2af466dcadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BD=E7=83=AD?= <164668043+yichere@users.noreply.github.com> Date: Sun, 29 Dec 2024 16:42:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(Adapter):=E4=BD=BF=E7=94=A8=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=99=A8=E6=96=B9=E5=BC=8F=E8=A7=A3=E6=9E=90=E6=88=B3?= =?UTF-8?q?=E4=B8=80=E6=88=B3CQ=E7=A0=81=20(#1169)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dice/platform_adapter_gocq_actions.go | 59 ++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/dice/platform_adapter_gocq_actions.go b/dice/platform_adapter_gocq_actions.go index 9b839533..aa1fb291 100644 --- a/dice/platform_adapter_gocq_actions.go +++ b/dice/platform_adapter_gocq_actions.go @@ -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", @@ -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 @@ -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 { @@ -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...)