2018-08-06 19:10:54 +00:00
|
|
|
// Discordgo - Discord bindings for Go
|
|
|
|
// Available at https://github.com/bwmarrin/discordgo
|
|
|
|
|
|
|
|
// Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// This file contains code related to the Message struct
|
|
|
|
|
|
|
|
package discordgo
|
|
|
|
|
|
|
|
import (
|
2022-03-12 16:06:39 +00:00
|
|
|
"encoding/json"
|
2018-08-06 19:10:54 +00:00
|
|
|
"io"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
2022-03-12 16:06:39 +00:00
|
|
|
"time"
|
2018-08-06 19:10:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MessageType is the type of Message
|
2020-09-04 21:29:13 +00:00
|
|
|
// https://discord.com/developers/docs/resources/channel#message-object-message-types
|
2018-08-06 19:10:54 +00:00
|
|
|
type MessageType int
|
|
|
|
|
|
|
|
// Block contains the valid known MessageType values
|
|
|
|
const (
|
2022-03-12 16:06:39 +00:00
|
|
|
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
|
2018-08-06 19:10:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// A Message stores all data related to a specific Discord message.
|
|
|
|
type Message struct {
|
2018-11-12 23:02:07 +00:00
|
|
|
// The ID of the message.
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
|
|
|
// The ID of the channel in which the message was sent.
|
|
|
|
ChannelID string `json:"channel_id"`
|
|
|
|
|
|
|
|
// The ID of the guild in which the message was sent.
|
|
|
|
GuildID string `json:"guild_id,omitempty"`
|
|
|
|
|
|
|
|
// The content of the message.
|
|
|
|
Content string `json:"content"`
|
|
|
|
|
|
|
|
// The time at which the messsage was sent.
|
|
|
|
// CAUTION: this field may be removed in a
|
|
|
|
// future API version; it is safer to calculate
|
|
|
|
// the creation time via the ID.
|
2022-03-12 16:06:39 +00:00
|
|
|
Timestamp time.Time `json:"timestamp"`
|
2018-11-12 23:02:07 +00:00
|
|
|
|
|
|
|
// The time at which the last edit of the message
|
|
|
|
// occurred, if it has been edited.
|
2022-03-12 16:06:39 +00:00
|
|
|
EditedTimestamp *time.Time `json:"edited_timestamp"`
|
2018-11-12 23:02:07 +00:00
|
|
|
|
|
|
|
// The roles mentioned in the message.
|
|
|
|
MentionRoles []string `json:"mention_roles"`
|
|
|
|
|
|
|
|
// Whether the message is text-to-speech.
|
2020-07-18 15:27:41 +00:00
|
|
|
TTS bool `json:"tts"`
|
2018-11-12 23:02:07 +00:00
|
|
|
|
|
|
|
// Whether the message mentions everyone.
|
|
|
|
MentionEveryone bool `json:"mention_everyone"`
|
|
|
|
|
|
|
|
// The author of the message. This is not guaranteed to be a
|
|
|
|
// valid user (webhook-sent messages do not possess a full author).
|
|
|
|
Author *User `json:"author"`
|
|
|
|
|
|
|
|
// A list of attachments present in the message.
|
|
|
|
Attachments []*MessageAttachment `json:"attachments"`
|
|
|
|
|
2022-03-12 16:06:39 +00:00
|
|
|
// A list of components attached to the message.
|
|
|
|
Components []MessageComponent `json:"-"`
|
|
|
|
|
|
|
|
// A list of embeds present in the message.
|
2018-11-12 23:02:07 +00:00
|
|
|
Embeds []*MessageEmbed `json:"embeds"`
|
|
|
|
|
|
|
|
// A list of users mentioned in the message.
|
|
|
|
Mentions []*User `json:"mentions"`
|
|
|
|
|
|
|
|
// A list of reactions to the message.
|
|
|
|
Reactions []*MessageReactions `json:"reactions"`
|
|
|
|
|
2019-10-26 23:45:57 +00:00
|
|
|
// Whether the message is pinned or not.
|
|
|
|
Pinned bool `json:"pinned"`
|
|
|
|
|
2018-11-12 23:02:07 +00:00
|
|
|
// The type of the message.
|
|
|
|
Type MessageType `json:"type"`
|
|
|
|
|
|
|
|
// The webhook ID of the message, if it was generated by a webhook
|
|
|
|
WebhookID string `json:"webhook_id"`
|
2019-10-26 23:45:57 +00:00
|
|
|
|
|
|
|
// Member properties for this message's author,
|
|
|
|
// contains only partial information
|
|
|
|
Member *Member `json:"member"`
|
|
|
|
|
|
|
|
// Channels specifically mentioned in this message
|
|
|
|
// Not all channel mentions in a message will appear in mention_channels.
|
|
|
|
// Only textual channels that are visible to everyone in a lurkable guild will ever be included.
|
|
|
|
// Only crossposted messages (via Channel Following) currently include mention_channels at all.
|
|
|
|
// If no mentions in the message meet these requirements, this field will not be sent.
|
|
|
|
MentionChannels []*Channel `json:"mention_channels"`
|
|
|
|
|
|
|
|
// Is sent with Rich Presence-related chat embeds
|
|
|
|
Activity *MessageActivity `json:"activity"`
|
|
|
|
|
|
|
|
// Is sent with Rich Presence-related chat embeds
|
|
|
|
Application *MessageApplication `json:"application"`
|
|
|
|
|
2022-03-12 16:06:39 +00:00
|
|
|
// 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().
|
2019-10-26 23:45:57 +00:00
|
|
|
MessageReference *MessageReference `json:"message_reference"`
|
|
|
|
|
2022-03-12 16:06:39 +00:00
|
|
|
// 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"`
|
|
|
|
|
2019-10-26 23:45:57 +00:00
|
|
|
// 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.
|
2020-09-04 21:29:13 +00:00
|
|
|
Flags MessageFlags `json:"flags"`
|
2022-03-12 16:06:39 +00:00
|
|
|
|
|
|
|
// 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
|
2018-08-06 19:10:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 21:29:13 +00:00
|
|
|
// MessageFlags is the flags of "message" (see MessageFlags* consts)
|
|
|
|
// https://discord.com/developers/docs/resources/channel#message-object-message-flags
|
|
|
|
type MessageFlags int
|
|
|
|
|
|
|
|
// Valid MessageFlags values
|
|
|
|
const (
|
2022-03-12 16:06:39 +00:00
|
|
|
// 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
|
2022-04-25 21:50:10 +00:00
|
|
|
// MessageFlagsSuppressEmbeds do not include any embeds when serializing this message.
|
|
|
|
MessageFlagsSuppressEmbeds MessageFlags = 1 << 2
|
|
|
|
// TODO: deprecated, remove when compatibility is not needed
|
2022-03-12 16:06:39 +00:00
|
|
|
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
|
2020-09-04 21:29:13 +00:00
|
|
|
)
|
|
|
|
|
2018-08-06 19:10:54 +00:00
|
|
|
// File stores info about files you e.g. send in messages.
|
|
|
|
type File struct {
|
|
|
|
Name string
|
|
|
|
ContentType string
|
|
|
|
Reader io.Reader
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageSend stores all parameters you can send with ChannelMessageSendComplex.
|
|
|
|
type MessageSend struct {
|
2020-07-18 15:27:41 +00:00
|
|
|
Content string `json:"content,omitempty"`
|
2022-04-25 21:50:10 +00:00
|
|
|
Embeds []*MessageEmbed `json:"embeds"`
|
2020-07-18 15:27:41 +00:00
|
|
|
TTS bool `json:"tts"`
|
2022-03-12 16:06:39 +00:00
|
|
|
Components []MessageComponent `json:"components"`
|
2020-07-18 15:27:41 +00:00
|
|
|
Files []*File `json:"-"`
|
|
|
|
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
|
2020-11-22 18:21:34 +00:00
|
|
|
Reference *MessageReference `json:"message_reference,omitempty"`
|
2018-08-06 19:10:54 +00:00
|
|
|
|
|
|
|
// TODO: Remove this when compatibility is not required.
|
|
|
|
File *File `json:"-"`
|
2022-03-12 16:06:39 +00:00
|
|
|
|
|
|
|
// TODO: Remove this when compatibility is not required.
|
|
|
|
Embed *MessageEmbed `json:"-"`
|
2018-08-06 19:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEdit is used to chain parameters via ChannelMessageEditComplex, which
|
|
|
|
// is also where you should get the instance from.
|
|
|
|
type MessageEdit struct {
|
2020-07-18 15:27:41 +00:00
|
|
|
Content *string `json:"content,omitempty"`
|
2022-03-12 16:06:39 +00:00
|
|
|
Components []MessageComponent `json:"components"`
|
2022-04-25 21:50:10 +00:00
|
|
|
Embeds []*MessageEmbed `json:"embeds"`
|
2020-07-18 15:27:41 +00:00
|
|
|
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
|
2022-04-25 21:50:10 +00:00
|
|
|
Flags MessageFlags `json:"flags,omitempty"`
|
2023-01-28 21:57:53 +00:00
|
|
|
// Files to append to the message
|
|
|
|
Files []*File `json:"-"`
|
|
|
|
// Overwrite existing attachments
|
|
|
|
Attachments *[]*MessageAttachment `json:"attachments,omitempty"`
|
2018-08-06 19:10:54 +00:00
|
|
|
|
|
|
|
ID string
|
|
|
|
Channel string
|
2022-03-12 16:06:39 +00:00
|
|
|
|
|
|
|
// TODO: Remove this when compatibility is not required.
|
|
|
|
Embed *MessageEmbed `json:"-"`
|
2018-08-06 19:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewMessageEdit returns a MessageEdit struct, initialized
|
|
|
|
// with the Channel and ID.
|
|
|
|
func NewMessageEdit(channelID string, messageID string) *MessageEdit {
|
|
|
|
return &MessageEdit{
|
|
|
|
Channel: channelID,
|
|
|
|
ID: messageID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetContent is the same as setting the variable Content,
|
|
|
|
// except it doesn't take a pointer.
|
|
|
|
func (m *MessageEdit) SetContent(str string) *MessageEdit {
|
|
|
|
m.Content = &str
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEmbed is a convenience function for setting the embed,
|
|
|
|
// so you can chain commands.
|
|
|
|
func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit {
|
2022-03-12 16:06:39 +00:00
|
|
|
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
|
2018-08-06 19:10:54 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-07-18 15:27:41 +00:00
|
|
|
// AllowedMentionType describes the types of mentions used
|
|
|
|
// in the MessageAllowedMentions type.
|
|
|
|
type AllowedMentionType string
|
|
|
|
|
|
|
|
// The types of mentions used in MessageAllowedMentions.
|
|
|
|
const (
|
|
|
|
AllowedMentionTypeRoles AllowedMentionType = "roles"
|
|
|
|
AllowedMentionTypeUsers AllowedMentionType = "users"
|
|
|
|
AllowedMentionTypeEveryone AllowedMentionType = "everyone"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MessageAllowedMentions allows the user to specify which mentions
|
|
|
|
// Discord is allowed to parse in this message. This is useful when
|
|
|
|
// sending user input as a message, as it prevents unwanted mentions.
|
|
|
|
// If this type is used, all mentions must be explicitly whitelisted,
|
|
|
|
// either by putting an AllowedMentionType in the Parse slice
|
|
|
|
// (allowing all mentions of that type) or, in the case of roles and
|
|
|
|
// users, explicitly allowing those mentions on an ID-by-ID basis.
|
|
|
|
// For more information on this functionality, see:
|
|
|
|
// https://discordapp.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mentions-reference
|
|
|
|
type MessageAllowedMentions struct {
|
|
|
|
// The mention types that are allowed to be parsed in this message.
|
|
|
|
// Please note that this is purposely **not** marked as omitempty,
|
|
|
|
// so if a zero-value MessageAllowedMentions object is provided no
|
|
|
|
// mentions will be allowed.
|
|
|
|
Parse []AllowedMentionType `json:"parse"`
|
|
|
|
|
|
|
|
// A list of role IDs to allow. This cannot be used when specifying
|
|
|
|
// AllowedMentionTypeRoles in the Parse slice.
|
|
|
|
Roles []string `json:"roles,omitempty"`
|
|
|
|
|
|
|
|
// A list of user IDs to allow. This cannot be used when specifying
|
|
|
|
// AllowedMentionTypeUsers in the Parse slice.
|
|
|
|
Users []string `json:"users,omitempty"`
|
2022-09-05 19:00:54 +00:00
|
|
|
|
|
|
|
// For replies, whether to mention the author of the message being replied to
|
|
|
|
RepliedUser bool `json:"replied_user"`
|
2020-07-18 15:27:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 19:10:54 +00:00
|
|
|
// A MessageAttachment stores data for message attachments.
|
|
|
|
type MessageAttachment struct {
|
2022-03-12 16:06:39 +00:00
|
|
|
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"`
|
2018-08-06 19:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedFooter is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedFooter struct {
|
|
|
|
Text string `json:"text,omitempty"`
|
|
|
|
IconURL string `json:"icon_url,omitempty"`
|
|
|
|
ProxyIconURL string `json:"proxy_icon_url,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedImage is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedImage struct {
|
2022-04-25 21:50:10 +00:00
|
|
|
URL string `json:"url"`
|
2018-08-06 19:10:54 +00:00
|
|
|
ProxyURL string `json:"proxy_url,omitempty"`
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
Height int `json:"height,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedThumbnail is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedThumbnail struct {
|
2022-04-25 21:50:10 +00:00
|
|
|
URL string `json:"url"`
|
2018-08-06 19:10:54 +00:00
|
|
|
ProxyURL string `json:"proxy_url,omitempty"`
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
Height int `json:"height,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedVideo is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedVideo struct {
|
2020-09-04 21:29:13 +00:00
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
Height int `json:"height,omitempty"`
|
2018-08-06 19:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedProvider is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedProvider struct {
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedAuthor is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedAuthor struct {
|
|
|
|
URL string `json:"url,omitempty"`
|
2022-04-25 21:50:10 +00:00
|
|
|
Name string `json:"name"`
|
2018-08-06 19:10:54 +00:00
|
|
|
IconURL string `json:"icon_url,omitempty"`
|
|
|
|
ProxyIconURL string `json:"proxy_icon_url,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageEmbedField is a part of a MessageEmbed struct.
|
|
|
|
type MessageEmbedField struct {
|
2023-01-28 21:57:53 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Value string `json:"value"`
|
2018-08-06 19:10:54 +00:00
|
|
|
Inline bool `json:"inline,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// An MessageEmbed stores data for message embeds.
|
|
|
|
type MessageEmbed struct {
|
|
|
|
URL string `json:"url,omitempty"`
|
2020-09-04 21:29:13 +00:00
|
|
|
Type EmbedType `json:"type,omitempty"`
|
2018-08-06 19:10:54 +00:00
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Timestamp string `json:"timestamp,omitempty"`
|
|
|
|
Color int `json:"color,omitempty"`
|
|
|
|
Footer *MessageEmbedFooter `json:"footer,omitempty"`
|
|
|
|
Image *MessageEmbedImage `json:"image,omitempty"`
|
|
|
|
Thumbnail *MessageEmbedThumbnail `json:"thumbnail,omitempty"`
|
|
|
|
Video *MessageEmbedVideo `json:"video,omitempty"`
|
|
|
|
Provider *MessageEmbedProvider `json:"provider,omitempty"`
|
|
|
|
Author *MessageEmbedAuthor `json:"author,omitempty"`
|
|
|
|
Fields []*MessageEmbedField `json:"fields,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-09-04 21:29:13 +00:00
|
|
|
// EmbedType is the type of embed
|
|
|
|
// https://discord.com/developers/docs/resources/channel#embed-object-embed-types
|
|
|
|
type EmbedType string
|
|
|
|
|
|
|
|
// Block of valid EmbedTypes
|
|
|
|
const (
|
|
|
|
EmbedTypeRich EmbedType = "rich"
|
|
|
|
EmbedTypeImage EmbedType = "image"
|
|
|
|
EmbedTypeVideo EmbedType = "video"
|
|
|
|
EmbedTypeGifv EmbedType = "gifv"
|
|
|
|
EmbedTypeArticle EmbedType = "article"
|
|
|
|
EmbedTypeLink EmbedType = "link"
|
|
|
|
)
|
|
|
|
|
2018-08-06 19:10:54 +00:00
|
|
|
// MessageReactions holds a reactions object for a message.
|
|
|
|
type MessageReactions struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
Me bool `json:"me"`
|
|
|
|
Emoji *Emoji `json:"emoji"`
|
|
|
|
}
|
|
|
|
|
2019-10-26 23:45:57 +00:00
|
|
|
// MessageActivity is sent with Rich Presence-related chat embeds
|
|
|
|
type MessageActivity struct {
|
|
|
|
Type MessageActivityType `json:"type"`
|
|
|
|
PartyID string `json:"party_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageActivityType is the type of message activity
|
|
|
|
type MessageActivityType int
|
|
|
|
|
|
|
|
// Constants for the different types of Message Activity
|
|
|
|
const (
|
2022-03-12 16:06:39 +00:00
|
|
|
MessageActivityTypeJoin MessageActivityType = 1
|
|
|
|
MessageActivityTypeSpectate MessageActivityType = 2
|
|
|
|
MessageActivityTypeListen MessageActivityType = 3
|
|
|
|
MessageActivityTypeJoinRequest MessageActivityType = 5
|
2019-10-26 23:45:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MessageApplication is sent with Rich Presence-related chat embeds
|
|
|
|
type MessageApplication struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
CoverImage string `json:"cover_image"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Icon string `json:"icon"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageReference contains reference data sent with crossposted messages
|
|
|
|
type MessageReference struct {
|
|
|
|
MessageID string `json:"message_id"`
|
2022-09-05 19:00:54 +00:00
|
|
|
ChannelID string `json:"channel_id,omitempty"`
|
2021-02-01 20:29:04 +00:00
|
|
|
GuildID string `json:"guild_id,omitempty"`
|
2019-10-26 23:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 18:21:34 +00:00
|
|
|
// Reference returns MessageReference of given message
|
|
|
|
func (m *Message) Reference() *MessageReference {
|
|
|
|
return &MessageReference{
|
|
|
|
GuildID: m.GuildID,
|
|
|
|
ChannelID: m.ChannelID,
|
|
|
|
MessageID: m.ID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 19:10:54 +00:00
|
|
|
// ContentWithMentionsReplaced will replace all @<id> mentions with the
|
|
|
|
// username of the mention.
|
|
|
|
func (m *Message) ContentWithMentionsReplaced() (content string) {
|
|
|
|
content = m.Content
|
|
|
|
|
|
|
|
for _, user := range m.Mentions {
|
|
|
|
content = strings.NewReplacer(
|
|
|
|
"<@"+user.ID+">", "@"+user.Username,
|
|
|
|
"<@!"+user.ID+">", "@"+user.Username,
|
|
|
|
).Replace(content)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var patternChannels = regexp.MustCompile("<#[^>]*>")
|
|
|
|
|
|
|
|
// ContentWithMoreMentionsReplaced will replace all @<id> mentions with the
|
|
|
|
// username of the mention, but also role IDs and more.
|
|
|
|
func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, err error) {
|
|
|
|
content = m.Content
|
|
|
|
|
|
|
|
if !s.StateEnabled {
|
|
|
|
content = m.ContentWithMentionsReplaced()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
channel, err := s.State.Channel(m.ChannelID)
|
|
|
|
if err != nil {
|
|
|
|
content = m.ContentWithMentionsReplaced()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, user := range m.Mentions {
|
|
|
|
nick := user.Username
|
|
|
|
|
|
|
|
member, err := s.State.Member(channel.GuildID, user.ID)
|
|
|
|
if err == nil && member.Nick != "" {
|
|
|
|
nick = member.Nick
|
|
|
|
}
|
|
|
|
|
|
|
|
content = strings.NewReplacer(
|
|
|
|
"<@"+user.ID+">", "@"+user.Username,
|
|
|
|
"<@!"+user.ID+">", "@"+nick,
|
|
|
|
).Replace(content)
|
|
|
|
}
|
|
|
|
for _, roleID := range m.MentionRoles {
|
|
|
|
role, err := s.State.Role(channel.GuildID, roleID)
|
|
|
|
if err != nil || !role.Mentionable {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
content = strings.Replace(content, "<@&"+role.ID+">", "@"+role.Name, -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string {
|
|
|
|
channel, err := s.State.Channel(mention[2 : len(mention)-1])
|
|
|
|
if err != nil || channel.Type == ChannelTypeGuildVoice {
|
|
|
|
return mention
|
|
|
|
}
|
|
|
|
|
|
|
|
return "#" + channel.Name
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2022-03-12 16:06:39 +00:00
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|