Skip to content

Commit

Permalink
Merge pull request #5 from WindowsSov8forUs/master
Browse files Browse the repository at this point in the history
feat: 进行部分代码调整
  • Loading branch information
WindowsSov8forUs committed Jun 17, 2024
2 parents ca8e9a8 + 2487858 commit f5b421e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 79 deletions.
12 changes: 6 additions & 6 deletions pkg/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const (
)

type Login struct {
User *user.User `json:"user,omitempty"` // 用户对象
SelfId string `json:"self_id,omitempty"` // 平台账号
Platform string `json:"platform,omitempty"` // 平台名称
Status LoginStatus `json:"status"` // 登录状态
Features []string `json:"features"` // 平台特性 列表
ResourceUrls []string `json:"resource_urls"` // 代理路由 列表
User *user.User `json:"user,omitempty"` // 用户对象
SelfId string `json:"self_id,omitempty"` // 平台账号
Platform string `json:"platform,omitempty"` // 平台名称
Status LoginStatus `json:"status"` // 登录状态
Features []string `json:"features"` // 平台特性 列表
ProxyUrls []string `json:"proxy_urls"` // 代理路由 列表
}
27 changes: 17 additions & 10 deletions pkg/message/message_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ func (e *noAliasMessageElement) Alias() []string {
}

type ChildrenMessageElement struct {
Children []MessageElement
children []MessageElement
}

func (e *ChildrenMessageElement) stringifyChildren() string {
if e == nil {
return ""
}
if len(e.Children) == 0 {
if len(e.children) == 0 {
return ""
}
var result string
for _, e := range e.Children {
for _, e := range e.children {
result += e.Stringify()
}
return result
Expand All @@ -44,40 +44,47 @@ func (e *ChildrenMessageElement) parseChildren(n *html.Node) (*ChildrenMessageEl
return nil, err
}
result := &ChildrenMessageElement{
Children: children,
children: children,
}
return result, nil
}

func (e *ChildrenMessageElement) GetChildren() []MessageElement {
if e == nil {
return nil
}
return e.children
}

type ExtendAttributes struct {
Attributes map[string]string
attributes map[string]string
}

func (e *ExtendAttributes) AddAttribute(key, value string) *ExtendAttributes {
result := e
if result == nil {
result = &ExtendAttributes{
Attributes: make(map[string]string),
attributes: make(map[string]string),
}
}
result.Attributes[key] = value
result.attributes[key] = value
return result
}

func (e *ExtendAttributes) Get(key string) (string, bool) {
if e == nil {
return "", false
}
v, ok := e.Attributes[key]
v, ok := e.attributes[key]
return v, ok
}

func (e *ExtendAttributes) stringifyAttributes() string {
if e == nil || len(e.Attributes) == 0 {
if e == nil || len(e.attributes) == 0 {
return ""
}
var result string
for k, v := range e.Attributes {
for k, v := range e.attributes {
if v == "" {
result += " " + k
} else {
Expand Down
16 changes: 8 additions & 8 deletions pkg/message/message_element_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type MessageElementAt struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Id string
Name string // 收发 目标用户的名称
Role string // 收发 目标角色
Type string // 收发 特殊操作,例如 all 表示 @全体成员,here 表示 @在线成员
Id string // 收发 目标用户的 ID
Name string // 收发 目标用户的名称
Role string // 收发 目标角色
Type string // 收发 特殊操作,例如 all 表示 @全体成员,here 表示 @在线成员
}

func (e *MessageElementAt) Tag() string {
Expand Down Expand Up @@ -92,8 +92,8 @@ type MessageElementSharp struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Id string //收发 目标频道的 ID
Name string //收发 目标频道的名称
Id string // 收发 目标频道的 ID
Name string // 收发 目标频道的名称
}

func (e *MessageElementSharp) Tag() string {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (e *MessageElementSharp) Parse(n *html.Node) (MessageElement, error) {
Name: attrMap["name"],
}
for key, value := range attrMap {
if key != "id" && key != "name" && key != "role" && key != "type" {
if key != "id" && key != "name" {
result.ExtendAttributes = result.AddAttribute(key, value)
}
}
Expand All @@ -139,7 +139,7 @@ type MessageElementA struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Href string
Href string // 收发 链接的 URL
}

func (e *MessageElementA) Tag() string {
Expand Down
6 changes: 3 additions & 3 deletions pkg/message/message_element_decorative.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func (e *MessageElementSpl) Parse(n *html.Node) (MessageElement, error) {
}

type MessageElementCode struct {
*ChildrenMessageElement
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
}

Expand Down Expand Up @@ -213,8 +213,8 @@ func (e *MessageElementCode) Parse(n *html.Node) (MessageElement, error) {
}

type MessageElementSup struct {
*ChildrenMessageElement
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
}

Expand Down Expand Up @@ -246,8 +246,8 @@ func (e *MessageElementSup) Parse(n *html.Node) (MessageElement, error) {
}

type MessageElementSub struct {
*ChildrenMessageElement
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/message/message_element_extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ type MessageElementExtend struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Type string
tag string
}

func (e *MessageElementExtend) Tag() string {
return e.Type
return e.tag
}

func (e *MessageElementExtend) Stringify() string {
Expand All @@ -26,7 +26,7 @@ func (e *MessageElementExtend) Stringify() string {
func (e *MessageElementExtend) Parse(n *html.Node) (MessageElement, error) {
attrMap := attrList2MapVal(n.Attr)
result := &MessageElementExtend{
Type: n.Data,
tag: n.Data,
}
for key, value := range attrMap {
result.ExtendAttributes = result.AddAttribute(key, value)
Expand Down
10 changes: 5 additions & 5 deletions pkg/message/message_element_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package message
import "golang.org/x/net/html"

type MessageElementQuote struct {
Id string
Forward bool
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Id string // 发 消息的 ID
Forward bool // 发 是否为转发消息
}

func (e *MessageElementQuote) Tag() string {
Expand Down Expand Up @@ -58,9 +58,9 @@ type MessageElementAuthor struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Id string
Name string
Avatar string
Id string // 发 用户 ID
Name string // 发 昵称
Avatar string // 发 头像 URL
}

func (e *MessageElementAuthor) Tag() string {
Expand Down
16 changes: 5 additions & 11 deletions pkg/message/message_element_oprator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ type MessageElementButton struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
// id string? 发 按钮的 ID
//
// type string? 发 按钮的类型
// href string? 发 按钮的链接
// text string? 发 待输入文本
// theme string? 发 按钮的样式
Id string
Type string
Href string
Text string
Theme string
Id string // 发 按钮的 ID
Type string // 发 按钮的类型
Href string // 发 按钮的链接
Text string // 发 待输入文本
Theme string // 发 按钮的样式
}

func (e *MessageElementButton) Tag() string {
Expand Down
62 changes: 31 additions & 31 deletions pkg/message/message_element_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ type MessageElementImg struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Src string
Title string
Cache bool
Timeout string //ms
Width uint32
Height uint32
Src string // 收发 资源的 URL
Title string // 收发 资源文件名称
Cache bool // 发 是否使用已缓存的文件
Timeout string // 发 下载文件的最长时间 (毫秒)
Width uint32 // 收 图片宽度 (像素)
Height uint32 // 收 图片高度 (像素)
}

func (e *MessageElementImg) Tag() string {
Expand Down Expand Up @@ -116,14 +116,14 @@ func (e *MessageElementImg) Parse(n *html.Node) (MessageElement, error) {
if w, ok := attrMap["width"]; ok {
width, e := strconv.Atoi(w)
if e != nil {
return nil, fmt.Errorf("width[%s] is illegal:%v", w, e)
return nil, fmt.Errorf("width '%s' is illegal: %v", w, e)
}
result.Width = uint32(width)
}
if h, ok := attrMap["height"]; ok {
height, e := strconv.Atoi(h)
if e != nil {
return nil, fmt.Errorf("height[%s] is illegal:%v", h, e)
return nil, fmt.Errorf("height '%s' is illegal: %v", h, e)
}
result.Height = uint32(height)
}
Expand All @@ -144,12 +144,12 @@ type MessageElementAudio struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Src string
Title string
Cache bool
Timeout string //ms
Duration uint32
Poster string
Src string // 收发 资源的 URL
Title string // 收发 资源文件名称
Cache bool // 发 是否使用已缓存的文件
Timeout string // 发 下载文件的最长时间 (毫秒)
Duration uint32 // 收 音频长度 (秒)
Poster string // 收发 音频封面 URL
}

func (e *MessageElementAudio) Tag() string {
Expand Down Expand Up @@ -210,7 +210,7 @@ func (e *MessageElementAudio) Parse(n *html.Node) (MessageElement, error) {
if d, ok := attrMap["duration"]; ok {
duration, e := strconv.Atoi(d)
if e != nil {
return nil, fmt.Errorf("duration[%s] is illegal:%v", d, e)
return nil, fmt.Errorf("duration '%s' is illegal: %v", d, e)
}
result.Duration = uint32(duration)
}
Expand All @@ -234,14 +234,14 @@ type MessageElementVideo struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Src string
Title string
Cache bool
Timeout string //ms
Width uint32
Height uint32
Duration uint32
Poster string
Src string // 收发 资源的 URL
Title string // 收发 资源文件名称
Cache bool // 发 是否使用已缓存的文件
Timeout string // 发 下载文件的最长时间 (毫秒)
Width uint32 // 收 视频宽度 (像素)
Height uint32 // 收 视频高度 (像素)
Duration uint32 // 收 视频长度 (秒)
Poster string // 收发 视频封面 URL
}

func (e *MessageElementVideo) Tag() string {
Expand Down Expand Up @@ -307,21 +307,21 @@ func (e *MessageElementVideo) Parse(n *html.Node) (MessageElement, error) {
if w, ok := attrMap["width"]; ok {
width, e := strconv.Atoi(w)
if e != nil {
return nil, fmt.Errorf("width[%s] is illegal:%v", w, e)
return nil, fmt.Errorf("width '%s' is illegal: %v", w, e)
}
result.Width = uint32(width)
}
if h, ok := attrMap["height"]; ok {
height, e := strconv.Atoi(h)
if e != nil {
return nil, fmt.Errorf("height[%s] is illegal:%v", h, e)
return nil, fmt.Errorf("height '%s' is illegal: %v", h, e)
}
result.Height = uint32(height)
}
if d, ok := attrMap["duration"]; ok {
duration, e := strconv.Atoi(d)
if e != nil {
return nil, fmt.Errorf("duration[%s] is illegal:%v", d, e)
return nil, fmt.Errorf("duration '%s' is illegal: %v", d, e)
}
result.Duration = uint32(duration)
}
Expand All @@ -345,11 +345,11 @@ type MessageElementFile struct {
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Src string
Title string
Cache bool
Timeout string //ms
Poster string
Src string // 收发 资源的 URL
Title string // 收发 资源文件名称
Cache bool // 发 是否使用已缓存的文件
Timeout string // 发 下载文件的最长时间 (毫秒)
Poster string // 收发 缩略图 URL
}

func (e *MessageElementFile) Tag() string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/message/message_element_typography.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (e *MessageElmentP) Parse(n *html.Node) (MessageElement, error) {
}

type MessageElementMessage struct {
Id string
Forward bool
*noAliasMessageElement
*ChildrenMessageElement
*ExtendAttributes
Id string // 发 消息的 ID
Forward bool // 发 是否为转发消息
}

func (e *MessageElementMessage) Tag() string {
Expand Down

0 comments on commit f5b421e

Please sign in to comment.