diff options
Diffstat (limited to 'vendor/github.com/bwmarrin/discordgo/message.go')
-rw-r--r-- | vendor/github.com/bwmarrin/discordgo/message.go | 200 |
1 files changed, 146 insertions, 54 deletions
diff --git a/vendor/github.com/bwmarrin/discordgo/message.go b/vendor/github.com/bwmarrin/discordgo/message.go index 61cd0d9..eb2f496 100644 --- a/vendor/github.com/bwmarrin/discordgo/message.go +++ b/vendor/github.com/bwmarrin/discordgo/message.go @@ -10,9 +10,11 @@ package discordgo import ( + "encoding/json" "io" "regexp" "strings" + "time" ) // MessageType is the type of Message @@ -21,23 +23,26 @@ type MessageType int // Block contains the valid known MessageType values const ( - MessageTypeDefault MessageType = iota - MessageTypeRecipientAdd - MessageTypeRecipientRemove - MessageTypeCall - MessageTypeChannelNameChange - MessageTypeChannelIconChange - MessageTypeChannelPinnedMessage - MessageTypeGuildMemberJoin - MessageTypeUserPremiumGuildSubscription - MessageTypeUserPremiumGuildSubscriptionTierOne - MessageTypeUserPremiumGuildSubscriptionTierTwo - MessageTypeUserPremiumGuildSubscriptionTierThree - MessageTypeChannelFollowAdd - MessageTypeGuildDiscoveryDisqualified = iota + 1 - MessageTypeGuildDiscoveryRequalified - MessageTypeReply = iota + 4 - MessageTypeApplicationCommand + MessageTypeDefault MessageType = 0 + MessageTypeRecipientAdd MessageType = 1 + MessageTypeRecipientRemove MessageType = 2 + MessageTypeCall MessageType = 3 + MessageTypeChannelNameChange MessageType = 4 + MessageTypeChannelIconChange MessageType = 5 + MessageTypeChannelPinnedMessage MessageType = 6 + MessageTypeGuildMemberJoin MessageType = 7 + MessageTypeUserPremiumGuildSubscription MessageType = 8 + MessageTypeUserPremiumGuildSubscriptionTierOne MessageType = 9 + MessageTypeUserPremiumGuildSubscriptionTierTwo MessageType = 10 + MessageTypeUserPremiumGuildSubscriptionTierThree MessageType = 11 + MessageTypeChannelFollowAdd MessageType = 12 + MessageTypeGuildDiscoveryDisqualified MessageType = 14 + MessageTypeGuildDiscoveryRequalified MessageType = 15 + MessageTypeThreadCreated MessageType = 18 + MessageTypeReply MessageType = 19 + MessageTypeChatInputCommand MessageType = 20 + MessageTypeThreadStarterMessage MessageType = 21 + MessageTypeContextMenuCommand MessageType = 23 ) // A Message stores all data related to a specific Discord message. @@ -58,11 +63,11 @@ type Message struct { // CAUTION: this field may be removed in a // future API version; it is safer to calculate // the creation time via the ID. - Timestamp Timestamp `json:"timestamp"` + Timestamp time.Time `json:"timestamp"` // The time at which the last edit of the message // occurred, if it has been edited. - EditedTimestamp Timestamp `json:"edited_timestamp"` + EditedTimestamp *time.Time `json:"edited_timestamp"` // The roles mentioned in the message. MentionRoles []string `json:"mention_roles"` @@ -80,8 +85,10 @@ type Message struct { // A list of attachments present in the message. Attachments []*MessageAttachment `json:"attachments"` - // A list of embeds present in the message. Multiple - // embeds can currently only be sent by webhooks. + // A list of components attached to the message. + Components []MessageComponent `json:"-"` + + // A list of embeds present in the message. Embeds []*MessageEmbed `json:"embeds"` // A list of users mentioned in the message. @@ -116,13 +123,70 @@ type Message struct { // Is sent with Rich Presence-related chat embeds Application *MessageApplication `json:"application"` - // MessageReference contains reference data sent with crossposted messages + // MessageReference contains reference data sent with crossposted or reply messages. + // This does not contain the reference *to* this message; this is for when *this* message references another. + // To generate a reference to this message, use (*Message).Reference(). MessageReference *MessageReference `json:"message_reference"` + // The message associated with the message_reference + // NOTE: This field is only returned for messages with a type of 19 (REPLY) or 21 (THREAD_STARTER_MESSAGE). + // If the message is a reply but the referenced_message field is not present, + // the backend did not attempt to fetch the message that was being replied to, so its state is unknown. + // If the field exists but is null, the referenced message was deleted. + ReferencedMessage *Message `json:"referenced_message"` + + // Is sent when the message is a response to an Interaction, without an existing message. + // This means responses to message component interactions do not include this property, + // instead including a MessageReference, as components exist on preexisting messages. + Interaction *MessageInteraction `json:"interaction"` + // The flags of the message, which describe extra features of a message. // This is a combination of bit masks; the presence of a certain permission can // be checked by performing a bitwise AND between this int and the flag. Flags MessageFlags `json:"flags"` + + // The thread that was started from this message, includes thread member object + Thread *Channel `json:"thread,omitempty"` + + // An array of Sticker objects, if any were sent. + StickerItems []*Sticker `json:"sticker_items"` +} + +// UnmarshalJSON is a helper function to unmarshal the Message. +func (m *Message) UnmarshalJSON(data []byte) error { + type message Message + var v struct { + message + RawComponents []unmarshalableMessageComponent `json:"components"` + } + err := json.Unmarshal(data, &v) + if err != nil { + return err + } + *m = Message(v.message) + m.Components = make([]MessageComponent, len(v.RawComponents)) + for i, v := range v.RawComponents { + m.Components[i] = v.MessageComponent + } + return err +} + +// GetCustomEmojis pulls out all the custom (Non-unicode) emojis from a message and returns a Slice of the Emoji struct. +func (m *Message) GetCustomEmojis() []*Emoji { + var toReturn []*Emoji + emojis := EmojiRegex.FindAllString(m.Content, -1) + if len(emojis) < 1 { + return toReturn + } + for _, em := range emojis { + parts := strings.Split(em, ":") + toReturn = append(toReturn, &Emoji{ + ID: parts[2][:len(parts[2])-1], + Name: parts[1], + Animated: strings.HasPrefix(em, "<a:"), + }) + } + return toReturn } // MessageFlags is the flags of "message" (see MessageFlags* consts) @@ -131,11 +195,24 @@ type MessageFlags int // Valid MessageFlags values const ( - MessageFlagsCrossPosted MessageFlags = 1 << iota - MessageFlagsIsCrossPosted - MessageFlagsSupressEmbeds - MessageFlagsSourceMessageDeleted - MessageFlagsUrgent + // MessageFlagsCrossPosted This message has been published to subscribed channels (via Channel Following). + MessageFlagsCrossPosted MessageFlags = 1 << 0 + // MessageFlagsIsCrossPosted this message originated from a message in another channel (via Channel Following). + MessageFlagsIsCrossPosted MessageFlags = 1 << 1 + // MessageFlagsSupressEmbeds do not include any embeds when serializing this message. + MessageFlagsSupressEmbeds MessageFlags = 1 << 2 + // MessageFlagsSourceMessageDeleted the source message for this crosspost has been deleted (via Channel Following). + MessageFlagsSourceMessageDeleted MessageFlags = 1 << 3 + // MessageFlagsUrgent this message came from the urgent message system. + MessageFlagsUrgent MessageFlags = 1 << 4 + // MessageFlagsHasThread this message has an associated thread, with the same id as the message. + MessageFlagsHasThread MessageFlags = 1 << 5 + // MessageFlagsEphemeral this message is only visible to the user who invoked the Interaction. + MessageFlagsEphemeral MessageFlags = 1 << 6 + // MessageFlagsLoading this message is an Interaction Response and the bot is "thinking". + MessageFlagsLoading MessageFlags = 1 << 7 + // MessageFlagsFailedToMentionSomeRolesInThread this message failed to mention some roles and add their members to the thread. + MessageFlagsFailedToMentionSomeRolesInThread MessageFlags = 1 << 8 ) // File stores info about files you e.g. send in messages. @@ -148,25 +225,33 @@ type File struct { // MessageSend stores all parameters you can send with ChannelMessageSendComplex. type MessageSend struct { Content string `json:"content,omitempty"` - Embed *MessageEmbed `json:"embed,omitempty"` + Embeds []*MessageEmbed `json:"embeds,omitempty"` TTS bool `json:"tts"` + Components []MessageComponent `json:"components"` Files []*File `json:"-"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` Reference *MessageReference `json:"message_reference,omitempty"` // TODO: Remove this when compatibility is not required. File *File `json:"-"` + + // TODO: Remove this when compatibility is not required. + Embed *MessageEmbed `json:"-"` } // MessageEdit is used to chain parameters via ChannelMessageEditComplex, which // is also where you should get the instance from. type MessageEdit struct { Content *string `json:"content,omitempty"` - Embed *MessageEmbed `json:"embed,omitempty"` + Components []MessageComponent `json:"components"` + Embeds []*MessageEmbed `json:"embeds,omitempty"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` ID string Channel string + + // TODO: Remove this when compatibility is not required. + Embed *MessageEmbed `json:"-"` } // NewMessageEdit returns a MessageEdit struct, initialized @@ -188,7 +273,14 @@ func (m *MessageEdit) SetContent(str string) *MessageEdit { // SetEmbed is a convenience function for setting the embed, // so you can chain commands. func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit { - m.Embed = embed + m.Embeds = []*MessageEmbed{embed} + return m +} + +// SetEmbeds is a convenience function for setting the embeds, +// so you can chain commands. +func (m *MessageEdit) SetEmbeds(embeds []*MessageEmbed) *MessageEdit { + m.Embeds = embeds return m } @@ -230,13 +322,15 @@ type MessageAllowedMentions struct { // A MessageAttachment stores data for message attachments. type MessageAttachment struct { - ID string `json:"id"` - URL string `json:"url"` - ProxyURL string `json:"proxy_url"` - Filename string `json:"filename"` - Width int `json:"width"` - Height int `json:"height"` - Size int `json:"size"` + ID string `json:"id"` + URL string `json:"url"` + ProxyURL string `json:"proxy_url"` + Filename string `json:"filename"` + ContentType string `json:"content_type"` + Width int `json:"width"` + Height int `json:"height"` + Size int `json:"size"` + Ephemeral bool `json:"ephemeral"` } // MessageEmbedFooter is a part of a MessageEmbed struct. @@ -339,23 +433,10 @@ type MessageActivityType int // Constants for the different types of Message Activity const ( - MessageActivityTypeJoin MessageActivityType = iota + 1 - MessageActivityTypeSpectate - MessageActivityTypeListen - MessageActivityTypeJoinRequest -) - -// MessageFlag describes an extra feature of the message -type MessageFlag int - -// Constants for the different bit offsets of Message Flags -const ( - // This message has been published to subscribed channels (via Channel Following) - MessageFlagCrossposted MessageFlag = 1 << iota - // This message originated from a message in another channel (via Channel Following) - MessageFlagIsCrosspost - // Do not include any embeds when serializing this message - MessageFlagSuppressEmbeds + MessageActivityTypeJoin MessageActivityType = 1 + MessageActivityTypeSpectate MessageActivityType = 2 + MessageActivityTypeListen MessageActivityType = 3 + MessageActivityTypeJoinRequest MessageActivityType = 5 ) // MessageApplication is sent with Rich Presence-related chat embeds @@ -447,3 +528,14 @@ func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, e }) return } + +// MessageInteraction contains information about the application command interaction which generated the message. +type MessageInteraction struct { + ID string `json:"id"` + Type InteractionType `json:"type"` + Name string `json:"name"` + User *User `json:"user"` + + // Member is only present when the interaction is from a guild. + Member *Member `json:"member"` +} |