From 22c6eaa7f81d42c1a612ec448a3f135d4201b489 Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Tue, 18 Jun 2024 09:42:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E4=B8=BA=20MessageElement=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=AD=90?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E6=96=B9=E6=B3=95=EF=BC=8C=E5=B9=B6=E4=B8=BA?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=85=83=E7=B4=A0=E6=B7=BB=E5=8A=A0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/message/message_element.go | 1 + pkg/message/message_element_basic.go | 4 ++++ pkg/message/message_element_typography.go | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/pkg/message/message_element.go b/pkg/message/message_element.go index 99dfccf..e3b0bfc 100644 --- a/pkg/message/message_element.go +++ b/pkg/message/message_element.go @@ -8,6 +8,7 @@ type MessageElement interface { Tag() string Stringify() string Alias() []string + GetChildren() []MessageElement } type noAliasMessageElement struct { diff --git a/pkg/message/message_element_basic.go b/pkg/message/message_element_basic.go index 7da5d76..302a83c 100644 --- a/pkg/message/message_element_basic.go +++ b/pkg/message/message_element_basic.go @@ -31,6 +31,10 @@ func (e *MessageElementText) Parse(n *html.Node) (MessageElement, error) { return nil, nil } +func (e *MessageElementText) GetChildren() []MessageElement { + return nil +} + type MessageElementAt struct { *noAliasMessageElement *ChildrenMessageElement diff --git a/pkg/message/message_element_typography.go b/pkg/message/message_element_typography.go index 44048bc..b956c32 100644 --- a/pkg/message/message_element_typography.go +++ b/pkg/message/message_element_typography.go @@ -20,6 +20,10 @@ func (e *MessageElmentBr) Parse(n *html.Node) (MessageElement, error) { return &MessageElmentBr{}, nil } +func (e *MessageElmentBr) GetChildren() []MessageElement { + return nil +} + type MessageElmentP struct { *noAliasMessageElement *ChildrenMessageElement From 125a7b83009edfe63073cdf2244688580cf2c280 Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Tue, 18 Jun 2024 09:49:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20select=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/message/message.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/message/message.go b/pkg/message/message.go index d27f79d..7f5a22b 100644 --- a/pkg/message/message.go +++ b/pkg/message/message.go @@ -41,3 +41,31 @@ func (m *Message) Encode() ([]MessageElement, error) { } return Parse(m.Content) } + +// Select 选取特定的消息元素 +func Select(element MessageElement, tag string) []MessageElement { + var selected []MessageElement + + if element.Tag() == tag { + selected = append(selected, element) + } + + selected = selectFromSlide(element.GetChildren(), tag, selected) + + return selected +} + +// selectFromSlide 从列表中选取特定的消息元素 +func selectFromSlide(elements []MessageElement, tag string, selected []MessageElement) []MessageElement { + for _, element := range elements { + if element.Tag() == tag { + selected = append(selected, element) + } + } + + for _, element := range elements { + selected = append(selected, selectFromSlide(element.GetChildren(), tag, selected)...) + } + + return selected +} From d99df3bd925cac9aa522f7a99d6e7f05b1142a74 Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Tue, 18 Jun 2024 23:25:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20Data=20=E7=B1=BB=E5=9E=8B=E4=B8=BA=E6=8C=87?= =?UTF-8?q?=E9=92=88=E5=88=87=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/channel/channel.go | 4 ++-- pkg/guild/guild.go | 4 ++-- pkg/guildmember/guildmember.go | 4 ++-- pkg/guildrole/guildrole.go | 4 ++-- pkg/message/message.go | 6 +++--- pkg/user/user.go | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/channel/channel.go b/pkg/channel/channel.go index 71c1eda..ab2fcd1 100644 --- a/pkg/channel/channel.go +++ b/pkg/channel/channel.go @@ -19,6 +19,6 @@ type Channel struct { // Channel 分页列表 type ChannelList struct { - Data []Channel `json:"data"` // 数据 - Next string `json:"next,omitempty"` // 下一页的令牌 + Data []*Channel `json:"data"` // 数据 + Next string `json:"next,omitempty"` // 下一页的令牌 } diff --git a/pkg/guild/guild.go b/pkg/guild/guild.go index 4876e5e..973833c 100644 --- a/pkg/guild/guild.go +++ b/pkg/guild/guild.go @@ -9,6 +9,6 @@ type Guild struct { // Guild 分页列表 type GuildList struct { - Data []Guild `json:"data"` // 数据 - Next string `json:"next,omitempty"` // 下一页的令牌 + Data []*Guild `json:"data"` // 数据 + Next string `json:"next,omitempty"` // 下一页的令牌 } diff --git a/pkg/guildmember/guildmember.go b/pkg/guildmember/guildmember.go index 2eb406d..b7b6dd8 100644 --- a/pkg/guildmember/guildmember.go +++ b/pkg/guildmember/guildmember.go @@ -12,6 +12,6 @@ type GuildMember struct { // GuildMember 分页列表 type GuildMemberList struct { - Data []GuildMember `json:"data"` // 数据 - Next string `json:"next,omitempty"` // 下一页的令牌 + Data []*GuildMember `json:"data"` // 数据 + Next string `json:"next,omitempty"` // 下一页的令牌 } diff --git a/pkg/guildrole/guildrole.go b/pkg/guildrole/guildrole.go index 3fb3e4a..1abe29d 100644 --- a/pkg/guildrole/guildrole.go +++ b/pkg/guildrole/guildrole.go @@ -8,6 +8,6 @@ type GuildRole struct { // GuildRole 分页列表 type GuildRoleList struct { - Data []GuildRole `json:"data"` // 数据 - Next string `json:"next,omitempty"` // 下一页的令牌 + Data []*GuildRole `json:"data"` // 数据 + Next string `json:"next,omitempty"` // 下一页的令牌 } diff --git a/pkg/message/message.go b/pkg/message/message.go index 7f5a22b..19023e3 100644 --- a/pkg/message/message.go +++ b/pkg/message/message.go @@ -21,9 +21,9 @@ type Message struct { // Message 双向分页列表 type MessageBidiList struct { - Data []Message `json:"data"` // 数据 - Prev string `json:"prev,omitempty"` // 上一页的令牌 - Next string `json:"next,omitempty"` // 下一页的令牌 + Data []*Message `json:"data"` // 数据 + Prev string `json:"prev,omitempty"` // 上一页的令牌 + Next string `json:"next,omitempty"` // 下一页的令牌 } func (m *Message) Decode(elements []MessageElement) error { diff --git a/pkg/user/user.go b/pkg/user/user.go index ec23f77..e7ffb63 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -11,6 +11,6 @@ type User struct { // User 分页列表 type UserList struct { - Data []User `json:"data"` // 数据 - Next string `json:"next,omitempty"` // 下一页的令牌 + Data []*User `json:"data"` // 数据 + Next string `json:"next,omitempty"` // 下一页的令牌 }