github.com/diamondburned/arikawa/v2@v2.1.0/discord/message.go (about) 1 package discord 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 8 "github.com/diamondburned/arikawa/v2/utils/json/enum" 9 ) 10 11 // https://discord.com/developers/docs/resources/channel#message-object 12 type Message struct { 13 // ID is the id of the message. 14 ID MessageID `json:"id"` 15 // ChannelID is the id of the channel the message was sent in. 16 ChannelID ChannelID `json:"channel_id"` 17 // GuildID is the id of the guild the message was sent in. 18 GuildID GuildID `json:"guild_id,omitempty"` 19 20 // Type is the type of message. 21 Type MessageType `json:"type"` 22 23 // Flags are the MessageFlags. 24 Flags MessageFlags `json:"flags"` 25 26 // TTS specifies whether the was a TTS message. 27 TTS bool `json:"tts"` 28 // Pinned specifies whether the message is pinned. 29 Pinned bool `json:"pinned"` 30 31 // MentionEveryone specifies whether the message mentions everyone. 32 MentionEveryone bool `json:"mention_everyone"` 33 // Mentions contains the users specifically mentioned in the message. 34 // 35 // The user objects in the mentions array will only have the partial 36 // member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from 37 // text-based guild channels. 38 Mentions []GuildUser `json:"mentions"` 39 // MentionRoleIDs contains the ids of the roles specifically mentioned in 40 // the message. 41 MentionRoleIDs []RoleID `json:"mention_roles"` 42 // MentionChannels are the channels specifically mentioned in the message. 43 // 44 // Not all channel mentions in a message will appear in mention_channels. 45 // Only textual channels that are visible to everyone in a lurkable guild 46 // will ever be included. Only crossposted messages (via Channel Following) 47 // currently include mention_channels at all. If no mentions in the message 48 // meet these requirements, the slice will be empty. 49 MentionChannels []ChannelMention `json:"mention_channels,omitempty"` 50 51 // Author is the author of the message. 52 // 53 // The author object follows the structure of the user object, but is only 54 // a valid user in the case where the message is generated by a user or bot 55 // user. If the message is generated by a webhook, the author object 56 // corresponds to the webhook's id, username, and avatar. You can tell if a 57 // message is generated by a webhook by checking for the webhook_id on the 58 // message object. 59 Author User `json:"author"` 60 61 // Content contains the contents of the message. 62 Content string `json:"content"` 63 64 // Timestamp specifies when the message was sent 65 Timestamp Timestamp `json:"timestamp,omitempty"` 66 // EditedTimestamp specifies when this message was edited. 67 // 68 // IsValid() will return false, if the messages hasn't been edited. 69 EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"` 70 71 // Attachments contains any attached files. 72 Attachments []Attachment `json:"attachments"` 73 // Embeds contains any embedded content. 74 Embeds []Embed `json:"embeds"` 75 76 Reactions []Reaction `json:"reactions,omitempty"` 77 78 // Used for validating a message was sent 79 Nonce string `json:"nonce,omitempty"` 80 81 // WebhookID contains the ID of the webhook, if the message was generated 82 // by a webhook. 83 WebhookID WebhookID `json:"webhook_id,omitempty"` 84 85 // Activity is sent with Rich Presence-related chat embeds. 86 Activity *MessageActivity `json:"activity,omitempty"` 87 // Application is sent with Rich Presence-related chat embeds. 88 Application *MessageApplication `json:"application,omitempty"` 89 90 // Reference is the reference data sent with crossposted messages and 91 // inline replies. 92 Reference *MessageReference `json:"message_reference,omitempty"` 93 // ReferencedMessage is the message that was replied to. If not present and 94 // the type is InlinedReplyMessage, the backend couldn't fetch the 95 // replied-to message. If null, the message was deleted. If present and 96 // non-null, it is a message object 97 ReferencedMessage *Message `json:"referenced_message,omitempty"` 98 99 // Stickers contains the sticker sent with the message. 100 Stickers []Sticker `json:"stickers,omitempty"` 101 } 102 103 // URL generates a Discord client URL to the message. If the message doesn't 104 // have a GuildID, it will generate a URL with the guild "@me". 105 func (m Message) URL() string { 106 var guildID = "@me" 107 if m.GuildID.IsValid() { 108 guildID = m.GuildID.String() 109 } 110 111 return fmt.Sprintf( 112 "https://discord.com/channels/%s/%s/%s", 113 guildID, m.ChannelID.String(), m.ID.String(), 114 ) 115 } 116 117 type MessageType uint8 118 119 // https://discord.com/developers/docs/resources/channel#message-object-message-types 120 const ( 121 DefaultMessage MessageType = 0 122 RecipientAddMessage MessageType = 1 123 RecipientRemoveMessage MessageType = 2 124 CallMessage MessageType = 3 125 ChannelNameChangeMessage MessageType = 4 126 ChannelIconChangeMessage MessageType = 5 127 ChannelPinnedMessage MessageType = 6 128 GuildMemberJoinMessage MessageType = 7 129 NitroBoostMessage MessageType = 8 130 NitroTier1Message MessageType = 9 131 NitroTier2Message MessageType = 10 132 NitroTier3Message MessageType = 11 133 ChannelFollowAddMessage MessageType = 12 134 GuildDiscoveryDisqualifiedMessage MessageType = 14 135 GuildDiscoveryRequalifiedMessage MessageType = 15 136 InlinedReplyMessage MessageType = 19 137 ApplicationCommandMessage MessageType = 20 138 ) 139 140 type MessageFlags enum.Enum 141 142 // https://discord.com/developers/docs/resources/channel#message-object-message-types 143 var ( 144 // NullMessage is the JSON null value of MessageFlags. 145 NullMessage MessageFlags = enum.Null 146 // CrosspostedMessage specifies whether the message has been published to 147 // subscribed channels (via Channel Following). 148 CrosspostedMessage MessageFlags = 1 149 // MessageIsCrosspost specifies whether the message originated from a 150 // message in another channel (via Channel Following). 151 MessageIsCrosspost MessageFlags = 2 152 // SuppressEmbeds specifies whether to not include any embeds when 153 // serializing the message. 154 SuppressEmbeds MessageFlags = 4 155 // SourceMessageDeleted specifies whether the source message for the 156 // crosspost has been deleted (via Channel Following). 157 SourceMessageDeleted MessageFlags = 8 158 // UrgentMessage specifies whether the message came from the urgent message 159 // system. 160 UrgentMessage MessageFlags = 16 161 ) 162 163 // https://discord.com/developers/docs/resources/channel#message-object-message-sticker-structure 164 type Sticker struct { 165 // ID is the ID of the sticker. 166 ID StickerID `json:"id"` 167 // PackID is the ID of the pack the sticker is from. 168 PackID StickerPackID `json:"pack_id"` 169 // Name is the name of the sticker. 170 Name string `json:"name"` 171 // Description is the description of the sticker. 172 Description string `json:"description"` 173 // Tags is a comma-delimited list of tags for the sticker. To get the list 174 // as a slice, use TagList. 175 Tags string `json:"-"` 176 // Asset is the sticker's assert hash. 177 Asset Hash `json:"asset"` 178 // PreviewAsset is the sticker preview asset hash. 179 PreviewAsset Hash `json:"preview_asset"` 180 // FormatType is the type of sticker format. 181 FormatType StickerFormatType `json:"format_type"` 182 } 183 184 // CreatedAt returns a time object representing when the sticker was created. 185 func (s Sticker) CreatedAt() time.Time { 186 return s.ID.Time() 187 } 188 189 // PackCreatedAt returns a time object representing when the sticker's pack 190 // was created. 191 func (s Sticker) PackCreatedAt() time.Time { 192 return s.PackID.Time() 193 } 194 195 // TagList splits the sticker tags into a slice of strings. 196 func (s Sticker) TagList() []string { 197 return strings.Split(s.Tags, ",") 198 } 199 200 type StickerFormatType uint8 201 202 // https://discord.com/developers/docs/resources/channel#message-object-message-sticker-format-types 203 const ( 204 StickerFormatPNG = 1 205 StickerFormatAPNG = 2 206 StickerFormatLottie = 3 207 ) 208 209 // https://discord.com/developers/docs/resources/channel#channel-mention-object 210 type ChannelMention struct { 211 // ChannelID is the ID of the channel. 212 ChannelID ChannelID `json:"id"` 213 // GuildID is the ID of the guild containing the channel. 214 GuildID GuildID `json:"guild_id"` 215 // ChannelType is the type of channel. 216 ChannelType ChannelType `json:"type"` 217 // ChannelName is the name of the channel. 218 ChannelName string `json:"name"` 219 } 220 221 type GuildUser struct { 222 User 223 Member *Member `json:"member,omitempty"` 224 } 225 226 // 227 228 // https://discord.com/developers/docs/resources/channel#message-object-message-activity-structure 229 type MessageActivity struct { 230 // Type is the type of message activity. 231 Type MessageActivityType `json:"type"` 232 // PartyID is the party_id from a Rich Presence event. 233 PartyID string `json:"party_id,omitempty"` 234 } 235 236 type MessageActivityType uint8 237 238 // https://discord.com/developers/docs/resources/channel#message-object-message-activity-types 239 const ( 240 JoinMessage MessageActivityType = iota + 1 241 SpectateMessage 242 ListenMessage 243 JoinRequestMessage 244 ) 245 246 // 247 248 // https://discord.com/developers/docs/resources/channel#message-object-message-application-structure 249 type MessageApplication struct { 250 // ID is the id of the application. 251 ID AppID `json:"id"` 252 // CoverID is the id of the embed's image asset. 253 CoverID string `json:"cover_image,omitempty"` 254 // Description is the application's description. 255 Description string `json:"description"` 256 // Icon is the id of the application's icon. 257 Icon string `json:"icon"` 258 // Name is the name of the application. 259 Name string `json:"name"` 260 } 261 262 // CreatedAt returns a time object representing when the message application 263 // was created. 264 func (m MessageApplication) CreatedAt() time.Time { 265 return m.ID.Time() 266 } 267 268 // 269 270 // MessageReference is used in four situations: 271 // 272 // Crosspost messages 273 // 274 // Messages that originated from another channel (IS_CROSSPOST flag). These 275 // messages have all three fields, with data of the original message that was 276 // crossposted. 277 // 278 // Channel Follow Add messages 279 // 280 // Automatic messages sent when a channel is followed into the current channel 281 // (type 12). These messages have the ChannelID and GuildID fields, with data 282 // of the followed announcement channel. 283 // 284 // Pin messages 285 // 286 // Automatic messages sent when a message is pinned (type 6). These messages 287 // have MessageID and ChannelID, and GuildID if it is in a guild, with data 288 // of the message that was pinned. 289 // 290 // Replies 291 // 292 // Messages replying to a previous message (type 19). These messages have 293 // MessageID, and ChannelID, and GuildID if it is in a guild, with data of the 294 // message that was replied to. The ChannelID and GuildID will be the 295 // same as the reply. 296 // 297 // Replies are created by including a message_reference when sending a message. 298 // When sending, only MessageID is required. 299 // https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure 300 type MessageReference struct { 301 // MessageID is the id of the originating message. 302 MessageID MessageID `json:"message_id,omitempty"` 303 // ChannelID is the id of the originating message's channel. 304 ChannelID ChannelID `json:"channel_id,omitempty"` 305 // GuildID is the id of the originating message's guild. 306 GuildID GuildID `json:"guild_id,omitempty"` 307 } 308 309 // 310 311 // https://discord.com/developers/docs/resources/channel#attachment-object 312 type Attachment struct { 313 // ID is the attachment id. 314 ID AttachmentID `json:"id"` 315 // Filename is the name of file attached. 316 Filename string `json:"filename"` 317 // Size is the size of file in bytes. 318 Size uint64 `json:"size"` 319 320 // URL is the source url of file. 321 URL URL `json:"url"` 322 // Proxy is the a proxied url of file. 323 Proxy URL `json:"proxy_url"` 324 325 // Height is the height of the file, if it is an image. 326 Height uint `json:"height,omitempty"` 327 // Width is the width of the file, if it is an image. 328 Width uint `json:"width,omitempty"` 329 } 330 331 // 332 333 // https://discord.com/developers/docs/resources/channel#reaction-object 334 type Reaction struct { 335 // Count is the amount of times the emoji has been used to react. 336 Count int `json:"count"` 337 // Me specifies whether the current user reacted using this emoji. 338 Me bool `json:"me"` 339 // Emoji contains emoji information. 340 Emoji Emoji `json:"emoji"` 341 }