/
message_element_cardimage.go
103 lines (93 loc) · 2.66 KB
/
message_element_cardimage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package model
import (
"encoding/json"
"fmt"
)
type MessageElementCardimage struct {
// file string 和image的file字段对齐, 支持也是一样的
File string `json:"file"`
// minwidth int64 默认不填为400, 最小width
Minwidth int64 `json:"minwidth"`
// minheight int64 默认不填为400, 最小height
Minheight int64 `json:"minheight"`
// maxwidth int64 默认不填为500, 最大width
Maxwidth int64 `json:"maxwidth"`
// maxheight int64 默认不填为1000, 最大height
Maxheight int64 `json:"maxheight"`
// source string 分享来源的名称, 可以留空
Source string `json:"source"`
// icon string 分享来源的icon图标url, 可以留空
Icon string `json:"icon"`
}
func (msg *MessageElementCardimage) Type() string {
return "cardimage"
}
func (msg *MessageElementCardimage) Enabled() bool {
return true
}
// ToCQCode
func (msg *MessageElementCardimage) ToCQCode() string {
cqCode := CQPrefix + CQEleSplit + "file=" + msg.File
if msg.Minwidth != 0 {
cqCode += (CQEleSplit + fmt.Sprintf("minwidth=%d", msg.Minwidth))
}
if msg.Minheight != 0 {
cqCode += (CQEleSplit + fmt.Sprintf("minheight=%d", msg.Minheight))
}
if msg.Icon != "" {
cqCode += (CQEleSplit + "icon=" + msg.Icon)
}
if msg.Source != "" {
cqCode += (CQEleSplit + "source=" + msg.Source)
}
return cqCode + CQSuffix
}
// ProcessGRPC
func (msg *MessageElementCardimage) ProcessGRPC(segment *MessageSegmentGRPC) {
segment.Data = &MessageSegmentGRPC_MessageElementCardimage{
MessageElementCardimage: msg.ToGRPC(),
}
}
func (msg *MessageElementCardimage) ToGRPC() *MessageElementCardimageGRPC {
return &MessageElementCardimageGRPC{
File: msg.File,
Minwidth: msg.Minwidth,
Minheight: msg.Minheight,
Maxwidth: msg.Maxwidth,
Maxheight: msg.Maxheight,
Source: msg.Source,
Icon: msg.Icon,
}
}
func (msg *MessageElementCardimageGRPC) ToStruct() *MessageElementCardimage {
return &MessageElementCardimage{
File: msg.File,
Minwidth: msg.Minwidth,
Minheight: msg.Minheight,
Maxwidth: msg.Maxwidth,
Maxheight: msg.Maxheight,
Source: msg.Source,
Icon: msg.Icon,
}
}
func init() {
messageElementUnmarshalJSONMap["cardimage"] = func(data []byte) (MessageElement, error) {
var result MessageElementCardimage
err := json.Unmarshal(data, &result)
return &result, err
}
messageSegmentGRPCToStructMap["cardimage"] = func(msg *MessageSegmentGRPC) (MessageElement, error) {
if msg == nil {
return nil, nil
}
if msg.Data == nil {
return nil, nil
}
switch data := msg.Data.(type) {
case *MessageSegmentGRPC_MessageElementCardimage:
return data.MessageElementCardimage.ToStruct(), nil
default:
return nil, nil
}
}
}