2020-01-02 19:53:08 +00:00
|
|
|
package discord
|
|
|
|
|
2020-07-17 18:33:57 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-10-28 22:39:59 +00:00
|
|
|
"github.com/diamondburned/arikawa/v2/utils/json/enum"
|
2020-07-17 18:33:57 +00:00
|
|
|
)
|
2020-05-11 22:06:19 +00:00
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
type Message struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ID MessageID `json:"id,string"`
|
2020-01-02 19:53:08 +00:00
|
|
|
Type MessageType `json:"type"`
|
2020-07-21 20:27:59 +00:00
|
|
|
ChannelID ChannelID `json:"channel_id,string"`
|
|
|
|
GuildID GuildID `json:"guild_id,string,omitempty"`
|
2020-01-02 19:53:08 +00:00
|
|
|
|
|
|
|
// The author object follows the structure of the user object, but is only
|
|
|
|
// a valid user in the case where the message is generated by a user or bot
|
|
|
|
// user. If the message is generated by a webhook, the author object
|
|
|
|
// corresponds to the webhook's id, username, and avatar. You can tell if a
|
|
|
|
// message is generated by a webhook by checking for the webhook_id on the
|
|
|
|
// message object.
|
|
|
|
Author User `json:"author"`
|
|
|
|
|
|
|
|
Content string `json:"content"`
|
|
|
|
|
2020-02-11 04:26:22 +00:00
|
|
|
Timestamp Timestamp `json:"timestamp,omitempty"`
|
|
|
|
EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"`
|
2020-01-02 19:53:08 +00:00
|
|
|
|
|
|
|
TTS bool `json:"tts"`
|
|
|
|
Pinned bool `json:"pinned"`
|
|
|
|
|
|
|
|
// The user objects in the mentions array will only have the partial
|
|
|
|
// member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from
|
|
|
|
// text-based guild channels.
|
|
|
|
Mentions []GuildUser `json:"mentions"`
|
|
|
|
|
2020-07-21 20:27:59 +00:00
|
|
|
MentionRoleIDs []RoleID `json:"mention_roles"`
|
|
|
|
MentionEveryone bool `json:"mention_everyone"`
|
2020-01-02 19:53:08 +00:00
|
|
|
|
|
|
|
// Not all channel mentions in a message will appear in mention_channels.
|
|
|
|
MentionChannels []ChannelMention `json:"mention_channels,omitempty"`
|
|
|
|
|
|
|
|
Attachments []Attachment `json:"attachments"`
|
|
|
|
Embeds []Embed `json:"embeds"`
|
|
|
|
|
2020-02-10 15:12:47 +00:00
|
|
|
Reactions []Reaction `json:"reactions,omitempty"`
|
2020-01-02 19:53:08 +00:00
|
|
|
|
|
|
|
// Used for validating a message was sent
|
|
|
|
Nonce string `json:"nonce,omitempty"`
|
|
|
|
|
2020-07-21 20:27:59 +00:00
|
|
|
WebhookID WebhookID `json:"webhook_id,string,omitempty"`
|
2020-01-02 19:53:08 +00:00
|
|
|
Activity *MessageActivity `json:"activity,omitempty"`
|
|
|
|
Application *MessageApplication `json:"application,omitempty"`
|
|
|
|
Reference *MessageReference `json:"message_reference,omitempty"`
|
|
|
|
Flags MessageFlags `json:"flags"`
|
|
|
|
}
|
|
|
|
|
2020-01-24 05:49:34 +00:00
|
|
|
// URL generates a Discord client URL to the message. If the message doesn't
|
|
|
|
// have a GuildID, it will generate a URL with the guild "@me".
|
|
|
|
func (m Message) URL() string {
|
2020-07-17 18:33:57 +00:00
|
|
|
var guildID = "@me"
|
2020-07-29 20:10:17 +00:00
|
|
|
if m.GuildID.IsValid() {
|
2020-07-17 18:33:57 +00:00
|
|
|
guildID = m.GuildID.String()
|
2020-01-24 05:49:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 18:33:57 +00:00
|
|
|
return fmt.Sprintf(
|
|
|
|
"https://discord.com/channels/%s/%s/%s",
|
|
|
|
guildID, m.ChannelID.String(), m.ID.String(),
|
|
|
|
)
|
2020-01-24 05:49:34 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
type MessageType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
DefaultMessage MessageType = iota
|
|
|
|
RecipientAddMessage
|
|
|
|
RecipientRemoveMessage
|
|
|
|
CallMessage
|
|
|
|
ChannelNameChangeMessage
|
|
|
|
ChannelIconChangeMessage
|
|
|
|
ChannelPinnedMessage
|
|
|
|
GuildMemberJoinMessage
|
|
|
|
NitroBoostMessage
|
|
|
|
NitroTier1Message
|
|
|
|
NitroTier2Message
|
|
|
|
NitroTier3Message
|
|
|
|
ChannelFollowAddMessage
|
2020-02-22 07:56:25 +00:00
|
|
|
GuildDiscoveryDisqualifiedMessage
|
|
|
|
GuildDiscoveryRequalifiedMessage
|
2020-01-02 19:53:08 +00:00
|
|
|
)
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
type MessageFlags enum.Enum
|
2020-01-02 19:53:08 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
var (
|
|
|
|
NullMessage MessageFlags = enum.Null
|
|
|
|
CrosspostedMessage MessageFlags = 1
|
|
|
|
MessageIsCrosspost MessageFlags = 2
|
|
|
|
SuppressEmbeds MessageFlags = 4
|
|
|
|
SourceMessageDeleted MessageFlags = 8
|
|
|
|
UrgentMessage MessageFlags = 16
|
2020-01-02 19:53:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ChannelMention struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ChannelID ChannelID `json:"id,string"`
|
|
|
|
GuildID GuildID `json:"guild_id,string"`
|
2020-01-02 19:53:08 +00:00
|
|
|
ChannelType ChannelType `json:"type"`
|
|
|
|
ChannelName string `json:"name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GuildUser struct {
|
|
|
|
User
|
2020-01-04 04:19:24 +00:00
|
|
|
Member *Member `json:"member,omitempty"`
|
2020-01-02 19:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
type MessageActivity struct {
|
|
|
|
Type MessageActivityType `json:"type"`
|
|
|
|
|
|
|
|
// From a Rich Presence event
|
|
|
|
PartyID string `json:"party_id,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessageActivityType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
JoinMessage MessageActivityType = iota + 1
|
|
|
|
SpectateMessage
|
|
|
|
ListenMessage
|
|
|
|
JoinRequestMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
type MessageApplication struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ID AppID `json:"id,string"`
|
|
|
|
CoverID string `json:"cover_image,omitempty"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Icon string `json:"icon"`
|
|
|
|
Name string `json:"name"`
|
2020-01-02 19:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
type MessageReference struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ChannelID ChannelID `json:"channel_id,string"`
|
2020-01-02 19:53:08 +00:00
|
|
|
|
|
|
|
// Field might not be provided
|
2020-07-21 20:27:59 +00:00
|
|
|
MessageID MessageID `json:"message_id,string,omitempty"`
|
|
|
|
GuildID GuildID `json:"guild_id,string,omitempty"`
|
2020-01-02 19:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
type Attachment struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ID AttachmentID `json:"id,string"`
|
|
|
|
Filename string `json:"filename"`
|
|
|
|
Size uint64 `json:"size"`
|
2020-01-02 19:53:08 +00:00
|
|
|
|
|
|
|
URL URL `json:"url"`
|
|
|
|
Proxy URL `json:"proxy_url"`
|
|
|
|
|
|
|
|
// Only if Image
|
|
|
|
Height uint `json:"height,omitempty"`
|
|
|
|
Width uint `json:"width,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
type Reaction struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
Me bool `json:"me"` // for current user
|
|
|
|
Emoji Emoji `json:"emoji"`
|
|
|
|
}
|