github.com/diamondburned/arikawa/v2@v2.1.0/gateway/events.go (about)

     1  package gateway
     2  
     3  import "github.com/diamondburned/arikawa/v2/discord"
     4  
     5  // Rules: VOICE_STATE_UPDATE -> VoiceStateUpdateEvent
     6  
     7  // https://discord.com/developers/docs/topics/gateway#connecting-and-resuming
     8  type (
     9  	HelloEvent struct {
    10  		HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
    11  	}
    12  
    13  	// Ready is too big, so it's moved to ready.go
    14  
    15  	ResumedEvent struct{}
    16  
    17  	// InvalidSessionEvent indicates if the event is resumable.
    18  	InvalidSessionEvent bool
    19  )
    20  
    21  // https://discord.com/developers/docs/topics/gateway#channels
    22  type (
    23  	ChannelCreateEvent struct {
    24  		discord.Channel
    25  	}
    26  	ChannelUpdateEvent struct {
    27  		discord.Channel
    28  	}
    29  	ChannelDeleteEvent struct {
    30  		discord.Channel
    31  	}
    32  	ChannelPinsUpdateEvent struct {
    33  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
    34  		ChannelID discord.ChannelID `json:"channel_id,omitempty"`
    35  		LastPin   discord.Timestamp `json:"timestamp,omitempty"`
    36  	}
    37  
    38  	ChannelUnreadUpdateEvent struct {
    39  		GuildID discord.GuildID `json:"guild_id"`
    40  
    41  		ChannelUnreadUpdates []struct {
    42  			ID            discord.ChannelID `json:"id"`
    43  			LastMessageID discord.MessageID `json:"last_message_id"`
    44  		}
    45  	}
    46  )
    47  
    48  // https://discord.com/developers/docs/topics/gateway#guilds
    49  type (
    50  	GuildCreateEvent struct {
    51  		discord.Guild
    52  
    53  		Joined      discord.Timestamp `json:"joined_at,omitempty"`
    54  		Large       bool              `json:"large,omitempty"`
    55  		Unavailable bool              `json:"unavailable,omitempty"`
    56  		MemberCount uint64            `json:"member_count,omitempty"`
    57  
    58  		VoiceStates []discord.VoiceState `json:"voice_states,omitempty"`
    59  		Members     []discord.Member     `json:"members,omitempty"`
    60  		Channels    []discord.Channel    `json:"channels,omitempty"`
    61  		Presences   []Presence           `json:"presences,omitempty"`
    62  	}
    63  	GuildUpdateEvent struct {
    64  		discord.Guild
    65  	}
    66  	GuildDeleteEvent struct {
    67  		ID discord.GuildID `json:"id"`
    68  		// Unavailable if false == removed
    69  		Unavailable bool `json:"unavailable"`
    70  	}
    71  
    72  	GuildBanAddEvent struct {
    73  		GuildID discord.GuildID `json:"guild_id"`
    74  		User    discord.User    `json:"user"`
    75  	}
    76  	GuildBanRemoveEvent struct {
    77  		GuildID discord.GuildID `json:"guild_id"`
    78  		User    discord.User    `json:"user"`
    79  	}
    80  
    81  	GuildEmojisUpdateEvent struct {
    82  		GuildID discord.GuildID `json:"guild_id"`
    83  		Emojis  []discord.Emoji `json:"emoji"`
    84  	}
    85  
    86  	GuildIntegrationsUpdateEvent struct {
    87  		GuildID discord.GuildID `json:"guild_id"`
    88  	}
    89  
    90  	GuildMemberAddEvent struct {
    91  		discord.Member
    92  		GuildID discord.GuildID `json:"guild_id"`
    93  	}
    94  	GuildMemberRemoveEvent struct {
    95  		GuildID discord.GuildID `json:"guild_id"`
    96  		User    discord.User    `json:"user"`
    97  	}
    98  	GuildMemberUpdateEvent struct {
    99  		GuildID discord.GuildID  `json:"guild_id"`
   100  		RoleIDs []discord.RoleID `json:"roles"`
   101  		User    discord.User     `json:"user"`
   102  		Nick    string           `json:"nick"`
   103  	}
   104  
   105  	// GuildMembersChunkEvent is sent when Guild Request Members is called.
   106  	GuildMembersChunkEvent struct {
   107  		GuildID discord.GuildID  `json:"guild_id"`
   108  		Members []discord.Member `json:"members"`
   109  
   110  		ChunkIndex int `json:"chunk_index"`
   111  		ChunkCount int `json:"chunk_count"`
   112  
   113  		// Whatever's not found goes here
   114  		NotFound []string `json:"not_found,omitempty"`
   115  
   116  		// Only filled if requested
   117  		Presences []Presence `json:"presences,omitempty"`
   118  		Nonce     string     `json:"nonce,omitempty"`
   119  	}
   120  
   121  	// GuildMemberListUpdate is an undocumented event. It's received when the
   122  	// client sends over GuildSubscriptions with the Channels field used.
   123  	// The State package does not handle this event.
   124  	GuildMemberListUpdate struct {
   125  		ID          string          `json:"id"`
   126  		GuildID     discord.GuildID `json:"guild_id"`
   127  		MemberCount uint64          `json:"member_count"`
   128  		OnlineCount uint64          `json:"online_count"`
   129  
   130  		// Groups is all the visible role sections.
   131  		Groups []GuildMemberListGroup `json:"groups"`
   132  
   133  		Ops []GuildMemberListOp `json:"ops"`
   134  	}
   135  	GuildMemberListGroup struct {
   136  		ID    string `json:"id"` // either discord.RoleID, "online" or "offline"
   137  		Count uint64 `json:"count"`
   138  	}
   139  	GuildMemberListOp struct {
   140  		// Mysterious string, so far spotted to be [SYNC, INSERT, UPDATE, DELETE].
   141  		Op string `json:"op"`
   142  
   143  		// NON-SYNC ONLY
   144  		// Only available for Ops that aren't "SYNC".
   145  		Index int                   `json:"index,omitempty"`
   146  		Item  GuildMemberListOpItem `json:"item,omitempty"`
   147  
   148  		// SYNC ONLY
   149  		// Range requested in GuildSubscribeData.
   150  		Range [2]int `json:"range,omitempty"`
   151  		// Items is basically a linear list of roles and members, similarly to
   152  		// how the client renders it. No, it's not nested.
   153  		Items []GuildMemberListOpItem `json:"items,omitempty"`
   154  	}
   155  	// GuildMemberListOpItem is an enum. Either of the fields are provided, but
   156  	// never both. Refer to (*GuildMemberListUpdate).Ops for more.
   157  	GuildMemberListOpItem struct {
   158  		Group  *GuildMemberListGroup `json:"group,omitempty"`
   159  		Member *struct {
   160  			discord.Member
   161  			HoistedRole string   `json:"hoisted_role"`
   162  			Presence    Presence `json:"presence"`
   163  		} `json:"member,omitempty"`
   164  	}
   165  
   166  	GuildRoleCreateEvent struct {
   167  		GuildID discord.GuildID `json:"guild_id"`
   168  		Role    discord.Role    `json:"role"`
   169  	}
   170  	GuildRoleUpdateEvent struct {
   171  		GuildID discord.GuildID `json:"guild_id"`
   172  		Role    discord.Role    `json:"role"`
   173  	}
   174  	GuildRoleDeleteEvent struct {
   175  		GuildID discord.GuildID `json:"guild_id"`
   176  		RoleID  discord.RoleID  `json:"role_id"`
   177  	}
   178  )
   179  
   180  func (u GuildMemberUpdateEvent) Update(m *discord.Member) {
   181  	m.RoleIDs = u.RoleIDs
   182  	m.User = u.User
   183  	m.Nick = u.Nick
   184  }
   185  
   186  // https://discord.com/developers/docs/topics/gateway#invites
   187  type (
   188  	InviteCreateEvent struct {
   189  		Code      string            `json:"code"`
   190  		CreatedAt discord.Timestamp `json:"created_at"`
   191  		ChannelID discord.ChannelID `json:"channel_id"`
   192  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
   193  
   194  		// Similar to discord.Invite
   195  		Inviter    *discord.User          `json:"inviter,omitempty"`
   196  		Target     *discord.User          `json:"target_user,omitempty"`
   197  		TargetType discord.InviteUserType `json:"target_user_type,omitempty"`
   198  
   199  		discord.InviteMetadata
   200  	}
   201  	InviteDeleteEvent struct {
   202  		Code      string            `json:"code"`
   203  		ChannelID discord.ChannelID `json:"channel_id"`
   204  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
   205  	}
   206  )
   207  
   208  // https://discord.com/developers/docs/topics/gateway#messages
   209  type (
   210  	MessageCreateEvent struct {
   211  		discord.Message
   212  		Member *discord.Member `json:"member,omitempty"`
   213  	}
   214  	MessageUpdateEvent struct {
   215  		discord.Message
   216  		Member *discord.Member `json:"member,omitempty"`
   217  	}
   218  	MessageDeleteEvent struct {
   219  		ID        discord.MessageID `json:"id"`
   220  		ChannelID discord.ChannelID `json:"channel_id"`
   221  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
   222  	}
   223  	MessageDeleteBulkEvent struct {
   224  		IDs       []discord.MessageID `json:"ids"`
   225  		ChannelID discord.ChannelID   `json:"channel_id"`
   226  		GuildID   discord.GuildID     `json:"guild_id,omitempty"`
   227  	}
   228  
   229  	MessageReactionAddEvent struct {
   230  		UserID    discord.UserID    `json:"user_id"`
   231  		ChannelID discord.ChannelID `json:"channel_id"`
   232  		MessageID discord.MessageID `json:"message_id"`
   233  
   234  		Emoji discord.Emoji `json:"emoji,omitempty"`
   235  
   236  		GuildID discord.GuildID `json:"guild_id,omitempty"`
   237  		Member  *discord.Member `json:"member,omitempty"`
   238  	}
   239  	MessageReactionRemoveEvent struct {
   240  		UserID    discord.UserID    `json:"user_id"`
   241  		ChannelID discord.ChannelID `json:"channel_id"`
   242  		MessageID discord.MessageID `json:"message_id"`
   243  		Emoji     discord.Emoji     `json:"emoji"`
   244  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
   245  	}
   246  	MessageReactionRemoveAllEvent struct {
   247  		ChannelID discord.ChannelID `json:"channel_id"`
   248  		MessageID discord.MessageID `json:"message_id"`
   249  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
   250  	}
   251  	MessageReactionRemoveEmojiEvent struct {
   252  		ChannelID discord.ChannelID `json:"channel_id"`
   253  		MessageID discord.MessageID `json:"message_id"`
   254  		Emoji     discord.Emoji     `json:"emoji"`
   255  		GuildID   discord.GuildID   `json:"guild_id,omitempty"`
   256  	}
   257  
   258  	MessageAckEvent struct {
   259  		MessageID discord.MessageID `json:"message_id"`
   260  		ChannelID discord.ChannelID `json:"channel_id"`
   261  	}
   262  )
   263  
   264  // Status is the enumerate type for a user's status.
   265  type Status string
   266  
   267  const (
   268  	UnknownStatus      Status = ""
   269  	OnlineStatus       Status = "online"
   270  	DoNotDisturbStatus Status = "dnd"
   271  	IdleStatus         Status = "idle"
   272  	InvisibleStatus    Status = "invisible"
   273  	OfflineStatus      Status = "offline"
   274  )
   275  
   276  // https://discord.com/developers/docs/topics/gateway#presence
   277  type (
   278  	// Presence represents a partial Presence structure used by other structs to be
   279  	// easily embedded. It does not contain any ID to identify who it belongs
   280  	// to. For more information, refer to the PresenceUpdateEvent struct.
   281  	Presence struct {
   282  		// User is the user presence is being updated for. Only the ID field is
   283  		// guaranteed to be valid per Discord documentation.
   284  		User discord.User `json:"user"`
   285  		// GuildID is the id of the guild
   286  		GuildID discord.GuildID `json:"guild_id"`
   287  		// Status is either "idle", "dnd", "online", or "offline".
   288  		Status Status `json:"status"`
   289  		// Activities are the user's current activities.
   290  		Activities []discord.Activity `json:"activities"`
   291  		// ClientStatus is the user's platform-dependent status.
   292  		ClientStatus ClientStatus `json:"client_status"`
   293  	}
   294  
   295  	// ClientStatus is the user's platform-dependent status.
   296  	//
   297  	// https://discord.com/developers/docs/topics/gateway#client-status-object
   298  	ClientStatus struct {
   299  		// Desktop is the user's status set for an active desktop (Windows,
   300  		// Linux, Mac) application session.
   301  		Desktop Status `json:"desktop,omitempty"`
   302  		// Mobile is the user's status set for an active mobile (iOS, Android)
   303  		// application session.
   304  		Mobile Status `json:"mobile,omitempty"`
   305  		// Web is the user's status set for an active web (browser, bot
   306  		// account) application session.
   307  		Web Status `json:"web,omitempty"`
   308  	}
   309  
   310  	// PresenceUpdateEvent represents the structure of the Presence Update Event
   311  	// object.
   312  	//
   313  	// https://discord.com/developers/docs/topics/gateway#presence-update-presence-update-event-fields
   314  	PresenceUpdateEvent struct {
   315  		Presence
   316  	}
   317  
   318  	PresencesReplaceEvent []PresenceUpdateEvent
   319  
   320  	// SessionsReplaceEvent is an undocumented user event. It's likely used for
   321  	// current user's presence updates.
   322  	SessionsReplaceEvent []struct {
   323  		Status    Status `json:"status"`
   324  		SessionID string `json:"session_id"`
   325  
   326  		Activities []discord.Activity `json:"activities"`
   327  
   328  		ClientInfo struct {
   329  			Version int    `json:"version"`
   330  			OS      string `json:"os"`
   331  			Client  string `json:"client"`
   332  		} `json:"client_info"`
   333  
   334  		Active bool `json:"active"`
   335  	}
   336  
   337  	TypingStartEvent struct {
   338  		ChannelID discord.ChannelID     `json:"channel_id"`
   339  		UserID    discord.UserID        `json:"user_id"`
   340  		Timestamp discord.UnixTimestamp `json:"timestamp"`
   341  
   342  		GuildID discord.GuildID `json:"guild_id,omitempty"`
   343  		Member  *discord.Member `json:"member,omitempty"`
   344  	}
   345  
   346  	UserUpdateEvent struct {
   347  		discord.User
   348  	}
   349  )
   350  
   351  // https://discord.com/developers/docs/topics/gateway#voice
   352  type (
   353  	VoiceStateUpdateEvent struct {
   354  		discord.VoiceState
   355  	}
   356  	VoiceServerUpdateEvent struct {
   357  		Token    string          `json:"token"`
   358  		GuildID  discord.GuildID `json:"guild_id"`
   359  		Endpoint string          `json:"endpoint"`
   360  	}
   361  )
   362  
   363  // https://discord.com/developers/docs/topics/gateway#webhooks
   364  type (
   365  	WebhooksUpdateEvent struct {
   366  		GuildID   discord.GuildID   `json:"guild_id"`
   367  		ChannelID discord.ChannelID `json:"channel_id"`
   368  	}
   369  )
   370  
   371  // https://discord.com/developers/docs/topics/gateway#interactions
   372  type (
   373  	InteractionCreateEvent struct {
   374  		ID        discord.InteractionID `json:"id"`
   375  		Type      InteractionType       `json:"type"`
   376  		Data      InteractionData       `json:"data"`
   377  		GuildID   discord.GuildID       `json:"guild_id"`
   378  		ChannelID discord.ChannelID     `json:"channel_id"`
   379  		Member    discord.Member        `json:"member"`
   380  		Token     string                `json:"token"`
   381  		Version   int                   `json:"version"`
   382  	}
   383  )
   384  
   385  type InteractionType uint
   386  
   387  const (
   388  	PingInteraction InteractionType = iota + 1
   389  	CommandInteraction
   390  )
   391  
   392  type InteractionData struct {
   393  	ID      discord.CommandID   `json:"id"`
   394  	Name    string              `json:"name"`
   395  	Options []InteractionOption `json:"options"`
   396  }
   397  
   398  type InteractionOption struct {
   399  	Name    string              `json:"name"`
   400  	Value   string              `json:"value"`
   401  	Options []InteractionOption `json:"options"`
   402  }
   403  
   404  // Undocumented
   405  type (
   406  	UserGuildSettingsUpdateEvent struct {
   407  		UserGuildSetting
   408  	}
   409  	UserSettingsUpdateEvent struct {
   410  		UserSettings
   411  	}
   412  	UserNoteUpdateEvent struct {
   413  		ID   discord.UserID `json:"id"`
   414  		Note string         `json:"note"`
   415  	}
   416  )
   417  
   418  type (
   419  	RelationshipAddEvent struct {
   420  		discord.Relationship
   421  	}
   422  	RelationshipRemoveEvent struct {
   423  		discord.Relationship
   424  	}
   425  )
   426  
   427  type (
   428  	ApplicationCommandUpdateEvent struct {
   429  		discord.Command
   430  		GuildID discord.GuildID `json:"guild_id"`
   431  	}
   432  )