2020-01-19 21:54:16 +00:00
|
|
|
package gateway
|
|
|
|
|
2020-08-15 01:13:35 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
2020-08-15 01:13:35 +00:00
|
|
|
)
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
type (
|
|
|
|
// ReadyEvent is the struct for a READY event.
|
|
|
|
ReadyEvent struct {
|
|
|
|
Version int `json:"version"`
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
User discord.User `json:"user"`
|
|
|
|
SessionID string `json:"session_id"`
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
PrivateChannels []discord.Channel `json:"private_channels"`
|
|
|
|
Guilds []GuildCreateEvent `json:"guilds"`
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
Shard *Shard `json:"shard,omitempty"`
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
// Undocumented fields
|
2020-02-25 05:50:13 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
UserSettings *UserSettings `json:"user_settings,omitempty"`
|
2020-12-02 02:07:42 +00:00
|
|
|
ReadStates []ReadState `json:"read_state,omitempty"`
|
|
|
|
UserGuildSettings []UserGuildSetting `json:"user_guild_settings,omitempty"`
|
2020-11-29 01:22:03 +00:00
|
|
|
Relationships []discord.Relationship `json:"relationships,omitempty"`
|
2020-12-20 02:46:21 +00:00
|
|
|
Presences []Presence `json:"presences,omitempty"`
|
2020-02-25 05:50:13 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
FriendSuggestionCount int `json:"friend_suggestion_count,omitempty"`
|
|
|
|
GeoOrderedRTCRegions []string `json:"geo_ordered_rtc_regions,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-12-02 02:07:42 +00:00
|
|
|
// ReadState is a single ReadState entry. It is undocumented.
|
2020-11-29 01:22:03 +00:00
|
|
|
ReadState struct {
|
|
|
|
ChannelID discord.ChannelID `json:"id"`
|
|
|
|
LastMessageID discord.MessageID `json:"last_message_id"`
|
|
|
|
LastPinTimestamp discord.Timestamp `json:"last_pin_timestamp"`
|
|
|
|
MentionCount int `json:"mention_count"`
|
|
|
|
}
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
// UserSettings is the struct for (almost) all user settings. It is
|
|
|
|
// undocumented.
|
|
|
|
UserSettings struct {
|
|
|
|
ShowCurrentGame bool `json:"show_current_game"`
|
|
|
|
DefaultGuildsRestricted bool `json:"default_guilds_restricted"`
|
|
|
|
InlineAttachmentMedia bool `json:"inline_attachment_media"`
|
|
|
|
InlineEmbedMedia bool `json:"inline_embed_media"`
|
|
|
|
GIFAutoPlay bool `json:"gif_auto_play"`
|
|
|
|
RenderEmbeds bool `json:"render_embeds"`
|
|
|
|
RenderReactions bool `json:"render_reactions"`
|
|
|
|
AnimateEmoji bool `json:"animate_emoji"`
|
|
|
|
AnimateStickers int `json:"animate_stickers"`
|
|
|
|
EnableTTSCommand bool `json:"enable_tts_command"`
|
|
|
|
MessageDisplayCompact bool `json:"message_display_compact"`
|
|
|
|
ConvertEmoticons bool `json:"convert_emoticons"`
|
|
|
|
ExplicitContentFilter uint8 `json:"explicit_content_filter"` // ???
|
|
|
|
DisableGamesTab bool `json:"disable_games_tab"`
|
|
|
|
DeveloperMode bool `json:"developer_mode"`
|
|
|
|
DetectPlatformAccounts bool `json:"detect_platform_accounts"`
|
|
|
|
StreamNotification bool `json:"stream_notification_enabled"`
|
|
|
|
AccessibilityDetection bool `json:"allow_accessibility_detection"`
|
|
|
|
ContactSync bool `json:"contact_sync_enabled"`
|
|
|
|
NativePhoneIntegration bool `json:"native_phone_integration_enabled"`
|
|
|
|
|
2020-12-20 02:46:21 +00:00
|
|
|
TimezoneOffset int `json:"timezone_offset"`
|
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
Locale string `json:"locale"`
|
|
|
|
Theme string `json:"theme"`
|
|
|
|
|
|
|
|
GuildPositions []discord.GuildID `json:"guild_positions"`
|
|
|
|
GuildFolders []GuildFolder `json:"guild_folders"`
|
|
|
|
RestrictedGuilds []discord.GuildID `json:"restricted_guilds"`
|
|
|
|
|
|
|
|
FriendSourceFlags FriendSourceFlags `json:"friend_source_flags"`
|
|
|
|
|
|
|
|
Status Status `json:"status"`
|
|
|
|
CustomStatus *CustomUserStatus `json:"custom_status"`
|
|
|
|
}
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
// CustomUserStatus is the custom user status that allows setting an emoji
|
|
|
|
// and a piece of text on each user.
|
|
|
|
CustomUserStatus struct {
|
2020-01-19 21:54:16 +00:00
|
|
|
Text string `json:"text"`
|
|
|
|
ExpiresAt discord.Timestamp `json:"expires_at,omitempty"`
|
2020-07-21 20:27:59 +00:00
|
|
|
EmojiID discord.EmojiID `json:"emoji_id,string"`
|
2020-01-19 21:54:16 +00:00
|
|
|
EmojiName string `json:"emoji_name"`
|
2020-11-29 01:22:03 +00:00
|
|
|
}
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-12-02 02:07:42 +00:00
|
|
|
// UserGuildSetting stores the settings for a single guild. It is
|
2020-11-29 01:22:03 +00:00
|
|
|
// undocumented.
|
2020-12-02 02:07:42 +00:00
|
|
|
UserGuildSetting struct {
|
2020-11-29 01:22:03 +00:00
|
|
|
GuildID discord.GuildID `json:"guild_id"`
|
|
|
|
|
2020-12-20 03:06:09 +00:00
|
|
|
SuppressRoles bool `json:"suppress_roles"`
|
|
|
|
SuppressEveryone bool `json:"suppress_everyone"`
|
|
|
|
Muted bool `json:"muted"`
|
|
|
|
MuteConfig *UserMuteConfig `json:"mute_config"`
|
2020-11-29 01:22:03 +00:00
|
|
|
|
2020-12-20 03:22:35 +00:00
|
|
|
MobilePush bool `json:"mobile_push"`
|
|
|
|
Notifications UserNotification `json:"message_notifications"`
|
2020-11-29 01:22:03 +00:00
|
|
|
|
|
|
|
ChannelOverrides []UserChannelOverride `json:"channel_overrides"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// A UserChannelOverride struct describes a channel settings override for a
|
|
|
|
// users guild settings.
|
|
|
|
UserChannelOverride struct {
|
2020-12-20 03:22:35 +00:00
|
|
|
Muted bool `json:"muted"`
|
|
|
|
MuteConfig *UserMuteConfig `json:"mute_config"`
|
|
|
|
Notifications UserNotification `json:"message_notifications"`
|
|
|
|
ChannelID discord.ChannelID `json:"channel_id"`
|
2020-11-29 01:22:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 03:06:09 +00:00
|
|
|
// UserMuteConfig seems to describe the mute settings. It belongs to the
|
|
|
|
// UserGuildSettingEntry and UserChannelOverride structs and is
|
|
|
|
// undocumented.
|
|
|
|
UserMuteConfig struct {
|
|
|
|
SelectedTimeWindow int `json:"selected_time_window"`
|
|
|
|
EndTime discord.Timestamp `json:"end_time"`
|
|
|
|
}
|
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
// GuildFolder holds a single folder that you see in the left guild panel.
|
|
|
|
GuildFolder struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
ID GuildFolderID `json:"id"`
|
|
|
|
GuildIDs []discord.GuildID `json:"guild_ids"`
|
|
|
|
Color discord.Color `json:"color"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// FriendSourceFlags describes sources that friend requests could be sent
|
|
|
|
// from. It belongs to the UserSettings struct and is undocumented.
|
|
|
|
FriendSourceFlags struct {
|
|
|
|
All bool `json:"all,omitempty"`
|
|
|
|
MutualGuilds bool `json:"mutual_guilds,omitempty"`
|
|
|
|
MutualFriends bool `json:"mutual_friends,omitempty"`
|
|
|
|
}
|
|
|
|
)
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-03-27 00:03:19 +00:00
|
|
|
// UserNotification is the notification setting for a channel or guild.
|
|
|
|
type UserNotification uint8
|
2020-03-26 23:28:43 +00:00
|
|
|
|
|
|
|
const (
|
2020-03-27 00:03:19 +00:00
|
|
|
AllNotifications UserNotification = iota
|
2020-03-26 23:28:43 +00:00
|
|
|
OnlyMentions
|
2020-03-27 02:11:25 +00:00
|
|
|
NoNotifications
|
2020-03-26 23:28:43 +00:00
|
|
|
GuildDefaults
|
|
|
|
)
|
|
|
|
|
2020-08-15 01:13:35 +00:00
|
|
|
// GuildFolderID is possibly a snowflake. It can also be 0 (null) or a low
|
|
|
|
// number of unknown significance.
|
2020-08-20 04:54:20 +00:00
|
|
|
type GuildFolderID int64
|
2020-08-15 01:13:35 +00:00
|
|
|
|
|
|
|
func (g *GuildFolderID) UnmarshalJSON(b []byte) error {
|
|
|
|
var body = string(b)
|
|
|
|
if body == "null" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
body = strings.Trim(body, `"`)
|
|
|
|
|
2020-08-20 04:54:20 +00:00
|
|
|
u, err := strconv.ParseInt(body, 10, 64)
|
2020-08-15 01:13:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*g = GuildFolderID(u)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g GuildFolderID) MarshalJSON() ([]byte, error) {
|
|
|
|
if g == 0 {
|
|
|
|
return []byte("null"), nil
|
|
|
|
}
|
|
|
|
|
2020-08-20 04:54:20 +00:00
|
|
|
return []byte(strconv.FormatInt(int64(g), 10)), nil
|
2020-08-15 01:13:35 +00:00
|
|
|
}
|
2020-11-29 01:22:03 +00:00
|
|
|
|
2020-12-20 02:46:21 +00:00
|
|
|
// ReadySupplemental event structs. For now, this event is never used, and its
|
|
|
|
// usage have yet been discovered.
|
2020-11-29 01:22:03 +00:00
|
|
|
type (
|
|
|
|
// ReadySupplementalEvent is the struct for a READY_SUPPLEMENTAL event,
|
|
|
|
// which is an undocumented event.
|
|
|
|
ReadySupplementalEvent struct {
|
2020-12-19 06:51:26 +00:00
|
|
|
Guilds []GuildCreateEvent `json:"guilds"` // only have ID and VoiceStates
|
2020-11-29 01:22:03 +00:00
|
|
|
MergedMembers [][]SupplementalMember `json:"merged_members"`
|
|
|
|
MergedPresences MergedPresences `json:"merged_presences"`
|
|
|
|
}
|
|
|
|
|
2020-12-20 02:46:21 +00:00
|
|
|
// SupplementalMember is the struct for a member in the MergedMembers field
|
|
|
|
// of ReadySupplementalEvent. It has slight differences to discord.Member.
|
|
|
|
SupplementalMember struct {
|
|
|
|
UserID discord.UserID `json:"user_id"`
|
|
|
|
Nick string `json:"nick,omitempty"`
|
|
|
|
RoleIDs []discord.RoleID `json:"roles"`
|
|
|
|
|
|
|
|
GuildID discord.GuildID `json:"guild_id,omitempty"`
|
|
|
|
IsPending bool `json:"is_pending,omitempty"`
|
|
|
|
HoistedRole discord.RoleID `json:"hoisted_role"`
|
|
|
|
|
|
|
|
Mute bool `json:"mute"`
|
|
|
|
Deaf bool `json:"deaf"`
|
|
|
|
|
|
|
|
// Joined specifies when the user joined the guild.
|
|
|
|
Joined discord.Timestamp `json:"joined_at"`
|
|
|
|
|
|
|
|
// BoostedSince specifies when the user started boosting the guild.
|
|
|
|
BoostedSince discord.Timestamp `json:"premium_since,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-11-29 01:22:03 +00:00
|
|
|
// MergedPresences is the struct for presences of guilds' members and
|
2020-11-30 00:57:58 +00:00
|
|
|
// friends. It is undocumented.
|
2020-11-29 01:22:03 +00:00
|
|
|
MergedPresences struct {
|
|
|
|
Guilds [][]SupplementalPresence `json:"guilds"`
|
|
|
|
Friends []SupplementalPresence `json:"friends"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SupplementalPresence is a single presence for either a guild member or
|
|
|
|
// friend. It is used in MergedPresences and is undocumented.
|
|
|
|
SupplementalPresence struct {
|
|
|
|
UserID discord.UserID `json:"user_id"`
|
|
|
|
|
2020-11-29 06:36:33 +00:00
|
|
|
// Status is either "idle", "dnd", "online", or "offline".
|
|
|
|
Status Status `json:"status"`
|
|
|
|
// Activities are the user's current activities.
|
|
|
|
Activities []discord.Activity `json:"activities"`
|
|
|
|
// ClientStaus is the user's platform-dependent status.
|
|
|
|
ClientStatus ClientStatus `json:"client_status"`
|
2020-11-29 01:22:03 +00:00
|
|
|
|
|
|
|
// LastModified is only present in Friends.
|
|
|
|
LastModified discord.UnixMsTimestamp `json:"last_modified,omitempty"`
|
|
|
|
}
|
|
|
|
)
|
2020-11-30 00:57:58 +00:00
|
|
|
|
|
|
|
// ConvertSupplementalMember converts a SupplementalMember to a regular Member.
|
|
|
|
func ConvertSupplementalMember(sm SupplementalMember) discord.Member {
|
|
|
|
return discord.Member{
|
|
|
|
User: discord.User{ID: sm.UserID},
|
|
|
|
Nick: sm.Nick,
|
|
|
|
RoleIDs: sm.RoleIDs,
|
|
|
|
Joined: sm.Joined,
|
|
|
|
BoostedSince: sm.BoostedSince,
|
|
|
|
Deaf: sm.Deaf,
|
|
|
|
Mute: sm.Mute,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertSupplementalPresence converts a SupplementalPresence to a regular
|
2021-05-30 21:16:16 +00:00
|
|
|
// Presence with an empty GuildID.
|
2020-11-30 00:57:58 +00:00
|
|
|
func ConvertSupplementalPresence(sp SupplementalPresence) Presence {
|
|
|
|
return Presence{
|
|
|
|
User: discord.User{ID: sp.UserID},
|
|
|
|
Status: sp.Status,
|
|
|
|
Activities: sp.Activities,
|
|
|
|
ClientStatus: sp.ClientStatus,
|
|
|
|
}
|
|
|
|
}
|