github.com/diamondburned/arikawa@v1.3.14/discord/message.go (about)

     1  package discord
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/diamondburned/arikawa/utils/json/enum"
     7  )
     8  
     9  type Message struct {
    10  	ID        MessageID   `json:"id,string"`
    11  	Type      MessageType `json:"type"`
    12  	ChannelID ChannelID   `json:"channel_id,string"`
    13  	GuildID   GuildID     `json:"guild_id,string,omitempty"`
    14  
    15  	// The author object follows the structure of the user object, but is only
    16  	// a valid user in the case where the message is generated by a user or bot
    17  	// user. If the message is generated by a webhook, the author object
    18  	// corresponds to the webhook's id, username, and avatar. You can tell if a
    19  	// message is generated by a webhook by checking for the webhook_id on the
    20  	// message object.
    21  	Author User `json:"author"`
    22  
    23  	Content string `json:"content"`
    24  
    25  	Timestamp       Timestamp `json:"timestamp,omitempty"`
    26  	EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"`
    27  
    28  	TTS    bool `json:"tts"`
    29  	Pinned bool `json:"pinned"`
    30  
    31  	// The user objects in the mentions array will only have the partial
    32  	// member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from
    33  	// text-based guild channels.
    34  	Mentions []GuildUser `json:"mentions"`
    35  
    36  	MentionRoleIDs  []RoleID `json:"mention_roles"`
    37  	MentionEveryone bool     `json:"mention_everyone"`
    38  
    39  	// Not all channel mentions in a message will appear in mention_channels.
    40  	MentionChannels []ChannelMention `json:"mention_channels,omitempty"`
    41  
    42  	Attachments []Attachment `json:"attachments"`
    43  	Embeds      []Embed      `json:"embeds"`
    44  
    45  	Reactions []Reaction `json:"reactions,omitempty"`
    46  
    47  	// Used for validating a message was sent
    48  	Nonce string `json:"nonce,omitempty"`
    49  
    50  	WebhookID   WebhookID           `json:"webhook_id,string,omitempty"`
    51  	Activity    *MessageActivity    `json:"activity,omitempty"`
    52  	Application *MessageApplication `json:"application,omitempty"`
    53  	Reference   *MessageReference   `json:"message_reference,omitempty"`
    54  	Flags       MessageFlags        `json:"flags"`
    55  }
    56  
    57  // URL generates a Discord client URL to the message. If the message doesn't
    58  // have a GuildID, it will generate a URL with the guild "@me".
    59  func (m Message) URL() string {
    60  	var guildID = "@me"
    61  	if m.GuildID.IsValid() {
    62  		guildID = m.GuildID.String()
    63  	}
    64  
    65  	return fmt.Sprintf(
    66  		"https://discord.com/channels/%s/%s/%s",
    67  		guildID, m.ChannelID.String(), m.ID.String(),
    68  	)
    69  }
    70  
    71  type MessageType uint8
    72  
    73  const (
    74  	DefaultMessage MessageType = iota
    75  	RecipientAddMessage
    76  	RecipientRemoveMessage
    77  	CallMessage
    78  	ChannelNameChangeMessage
    79  	ChannelIconChangeMessage
    80  	ChannelPinnedMessage
    81  	GuildMemberJoinMessage
    82  	NitroBoostMessage
    83  	NitroTier1Message
    84  	NitroTier2Message
    85  	NitroTier3Message
    86  	ChannelFollowAddMessage
    87  	GuildDiscoveryDisqualifiedMessage
    88  	GuildDiscoveryRequalifiedMessage
    89  )
    90  
    91  type MessageFlags enum.Enum
    92  
    93  var (
    94  	NullMessage          MessageFlags = enum.Null
    95  	CrosspostedMessage   MessageFlags = 1
    96  	MessageIsCrosspost   MessageFlags = 2
    97  	SuppressEmbeds       MessageFlags = 4
    98  	SourceMessageDeleted MessageFlags = 8
    99  	UrgentMessage        MessageFlags = 16
   100  )
   101  
   102  type ChannelMention struct {
   103  	ChannelID   ChannelID   `json:"id,string"`
   104  	GuildID     GuildID     `json:"guild_id,string"`
   105  	ChannelType ChannelType `json:"type"`
   106  	ChannelName string      `json:"name"`
   107  }
   108  
   109  type GuildUser struct {
   110  	User
   111  	Member *Member `json:"member,omitempty"`
   112  }
   113  
   114  //
   115  
   116  type MessageActivity struct {
   117  	Type MessageActivityType `json:"type"`
   118  
   119  	// From a Rich Presence event
   120  	PartyID string `json:"party_id,omitempty"`
   121  }
   122  
   123  type MessageActivityType uint8
   124  
   125  const (
   126  	JoinMessage MessageActivityType = iota + 1
   127  	SpectateMessage
   128  	ListenMessage
   129  	JoinRequestMessage
   130  )
   131  
   132  //
   133  
   134  type MessageApplication struct {
   135  	ID          AppID  `json:"id,string"`
   136  	CoverID     string `json:"cover_image,omitempty"`
   137  	Description string `json:"description"`
   138  	Icon        string `json:"icon"`
   139  	Name        string `json:"name"`
   140  }
   141  
   142  //
   143  
   144  type MessageReference struct {
   145  	ChannelID ChannelID `json:"channel_id,string"`
   146  
   147  	// Field might not be provided
   148  	MessageID MessageID `json:"message_id,string,omitempty"`
   149  	GuildID   GuildID   `json:"guild_id,string,omitempty"`
   150  }
   151  
   152  //
   153  
   154  type Attachment struct {
   155  	ID       AttachmentID `json:"id,string"`
   156  	Filename string       `json:"filename"`
   157  	Size     uint64       `json:"size"`
   158  
   159  	URL   URL `json:"url"`
   160  	Proxy URL `json:"proxy_url"`
   161  
   162  	// Only if Image
   163  	Height uint `json:"height,omitempty"`
   164  	Width  uint `json:"width,omitempty"`
   165  }
   166  
   167  //
   168  
   169  type Reaction struct {
   170  	Count int   `json:"count"`
   171  	Me    bool  `json:"me"` // for current user
   172  	Emoji Emoji `json:"emoji"`
   173  }