github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/topic/elements.go (about) 1 package topic 2 3 import ( 4 "strconv" 5 ) 6 7 type ( 8 TextElement struct { 9 Content string 10 } 11 12 EmojiElement struct { 13 Index int32 14 Id string 15 Name string 16 } 17 18 AtElement struct { 19 Id string 20 TinyId uint64 21 Nickname string 22 } 23 24 ChannelQuoteElement struct { 25 GuildId uint64 26 ChannelId uint64 27 DisplayText string 28 } 29 30 UrlQuoteElement struct { 31 Url string 32 DisplayText string 33 } 34 ) 35 36 func selectContent(b bool, c1, c2 content) content { 37 if b { 38 return c1 39 } 40 return c2 41 } 42 43 func (e *TextElement) pack(patternId string, isPatternData bool) content { 44 return selectContent(isPatternData, 45 content{ 46 "type": 1, 47 "style": "n", 48 "text": e.Content, 49 "children": make([]int, 0), 50 }, 51 content{ 52 "type": 1, 53 "text_content": content{ 54 "text": e.Content, 55 }, 56 }) 57 } 58 59 func (e *EmojiElement) pack(patternId string, isPatternData bool) content { 60 return selectContent(isPatternData, 61 content{ 62 "type": 2, 63 "id": patternId, 64 "emojiType": "1", 65 "emojiId": e.Id, 66 }, 67 content{ 68 "type": 4, 69 "pattern_id": patternId, 70 "emoji_content": content{ 71 "type": "1", 72 "id": e.Id, 73 }, 74 }) 75 } 76 77 func (e *AtElement) pack(patternId string, isPatternData bool) content { 78 return selectContent(isPatternData, 79 content{ 80 "type": 3, 81 "id": patternId, 82 "user": content{ 83 "id": strconv.FormatUint(e.TinyId, 10), 84 "nick": e.Nickname, 85 }, 86 }, 87 content{ 88 "type": 2, 89 "pattern_id": patternId, 90 "at_content": content{ 91 "type": 1, 92 "user": content{ 93 "id": e.Id, 94 "nick": e.Nickname, 95 }, 96 }, 97 }) 98 } 99 100 func (e *ChannelQuoteElement) pack(patternId string, isPatternData bool) content { 101 return selectContent(isPatternData, 102 content{ 103 "type": 4, 104 "id": patternId, 105 "guild_info": content{ 106 "channel_id": strconv.FormatUint(e.ChannelId, 10), 107 "name": e.DisplayText, 108 }, 109 }, 110 content{ 111 "type": 5, 112 "pattern_id": patternId, 113 "channel_content": content{ 114 "channel_info": content{ 115 "name": e.DisplayText, 116 "sign": content{ 117 "guild_id": strconv.FormatUint(e.GuildId, 10), 118 "channel_id": strconv.FormatUint(e.ChannelId, 10), 119 }, 120 }, 121 }, 122 }) 123 } 124 125 func (e *UrlQuoteElement) pack(patternId string, isPatternData bool) content { 126 return selectContent(isPatternData, 127 content{ 128 "type": 5, 129 "desc": e.DisplayText, 130 "href": e.Url, 131 "id": patternId, 132 }, 133 content{ 134 "type": 3, 135 "pattern_id": patternId, 136 "url_content": content{ 137 "url": e.Url, 138 "displayText": e.DisplayText, 139 }, 140 }) 141 }