ws

package
v0.1.16-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGatewayNotConnected     = errors.New("gateway is disconnected from Discord")
	ErrFetchingMembersTimedOut = errors.New("could not wait longer for guild members chunk")
)

Functions

This section is empty.

Types

type ChannelPinsUpdateEvent

type ChannelPinsUpdateEvent struct {
	GuildID          snowflake.ID      `json:"guild_id,omitempty"`
	ChannelID        snowflake.ID      `json:"channel_id,omitempty"`
	LastPinTimestamp discord.Timestamp `json:"last_pin_timestamp,omitempty"`
}

type Config

type Config struct {
	URL           string
	ID            uint16
	ShardCount    uint16
	Logger        golog.Logger
	Compression   bool
	Token         string
	Intents       GatewayIntent
	GlobalLimiter *rate.Limiter
}

type ErrNotFound

type ErrNotFound []snowflake.ID

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type Event

type Event struct {
	OpCode uint            `json:"op"`
	Data   json.RawMessage `json:"d"`
	Seq    uint64          `json:"s"`
	Event  string          `json:"t"`
	// contains filtered or unexported fields
}

func (*Event) Dereference

func (e *Event) Dereference()

type Gateway

type Gateway interface {
	Listen() (events <-chan any, cancel func())
	Disconnect()
	Connect(ctx context.Context) error
	Config() Config
	Status() Status
	Log() golog.Logger
	FetchMembers(ctx context.Context, params RequestGuildMembersParams) ([]discord.MemberWithUser, []discord.Presence, error)
}

func NewGateway

func NewGateway(cfg Config) Gateway

type GatewayIntent

type GatewayIntent uint
const (
	GatewayIntentGuilds                      GatewayIntent = 1 << 0
	GatewayIntentGuildMembers                GatewayIntent = 1 << 1
	GatewayIntentGuildModeration             GatewayIntent = 1 << 2
	GatewayIntentGuildEmojisAndStickers      GatewayIntent = 1 << 3
	GatewayIntentGuildIntegrations           GatewayIntent = 1 << 4
	GatewayIntentGuildWebhooks               GatewayIntent = 1 << 5
	GatewayIntentGuildInvites                GatewayIntent = 1 << 6
	GatewayIntentGuildVoiceStates            GatewayIntent = 1 << 7
	GatewayIntentGuildPresences              GatewayIntent = 1 << 8
	GatewayIntentGuildMessages               GatewayIntent = 1 << 9
	GatewayIntentGuildMessageReactions       GatewayIntent = 1 << 10
	GatewayIntentGuildMessageTyping          GatewayIntent = 1 << 11
	GatewayIntentGuildDirectMessages         GatewayIntent = 1 << 12
	GatewayIntentDirectMessageReactions      GatewayIntent = 1 << 13
	GatewayIntentDirectMessageTyping         GatewayIntent = 1 << 14
	GatewayIntentMessageContent              GatewayIntent = 1 << 15
	GatewayIntentGuildScheduledEvents        GatewayIntent = 1 << 16
	GatewayIntentAutoModerationConfiguration GatewayIntent = 1 << 20
	GatewayIntentAutoModerationExecution     GatewayIntent = 1 << 21
	GatewayIntentGuildMessagePolls           GatewayIntent = 1 << 24
	GatewayIntentDirectMessagePolls          GatewayIntent = 1 << 25

	GatewayIntentDefault = GatewayIntentGuilds | GatewayIntentGuildMembers | GatewayIntentGuildModeration | GatewayIntentGuildEmojisAndStickers | GatewayIntentGuildIntegrations | GatewayIntentGuildWebhooks | GatewayIntentGuildInvites | GatewayIntentGuildVoiceStates | GatewayIntentGuildMessages | GatewayIntentGuildMessageReactions | GatewayIntentGuildDirectMessages | GatewayIntentDirectMessageReactions | GatewayIntentMessageContent | GatewayIntentGuildScheduledEvents | GatewayIntentAutoModerationConfiguration | GatewayIntentAutoModerationExecution | GatewayIntentGuildMessagePolls | GatewayIntentDirectMessagePolls
)

type GuildBanEvent

type GuildBanEvent struct {
	GuildID snowflake.ID `json:"guild_id,omitempty"`
	User    discord.User `json:"user,omitempty"`
}

type GuildCreateEvent

type GuildCreateEvent struct {
	discord.Guild
	JoinedAt             discord.Timestamp        `json:"joined_at,omitempty"`
	Large                bool                     `json:"large,omitempty"`
	Unavailable          bool                     `json:"unavailable,omitempty"`
	MemberCount          uint                     `json:"member_count,omitempty"`
	Members              []discord.MemberWithUser `json:"members,omitempty"`
	Channels             []discord.Channel        `json:"channels,omitempty"`
	Threads              []discord.Channel        `json:"threads,omitempty"`
	Presences            []discord.Presence       `json:"presences,omitempty"`
	GuildScheduledEvents []discord.ScheduledEvent `json:"guild_scheduled_events,omitempty"`
	StageInstances       []discord.StageInstance  `json:"stage_instances,omitempty"`
	VoiceStates          []discord.VoiceState     `json:"voice_states,omitempty"`
}

type GuildMemberAddEvent

type GuildMemberAddEvent struct {
	discord.MemberWithUser
	GuildID snowflake.ID `json:"guild_id,omitempty"`
}

type GuildMemberRemoveEvent

type GuildMemberRemoveEvent struct {
	User    discord.User `json:"user,omitempty"`
	GuildID snowflake.ID `json:"guild_id,omitempty"`
}

type GuildMemberUpdateEvent

type GuildMemberUpdateEvent struct {
	discord.MemberWithUser
	GuildID snowflake.ID `json:"guild_id,omitempty"`
}

type GuildMembersChunkEvent

type GuildMembersChunkEvent struct {
	GuildID    snowflake.ID             `json:"guild_id,omitempty"`
	Members    []discord.MemberWithUser `json:"members,omitempty"`
	ChunkIndex int                      `json:"chunk_index,omitempty"`
	ChunkCount int                      `json:"chunk_count,omitempty"`
	NotFound   []snowflake.ID           `json:"not_found,omitempty"`
	Presences  []discord.Presence       `json:"presences,omitempty"`
	Nonce      string                   `json:"nonce,omitempty"`
}

type GuildRoleDeleteEvent

type GuildRoleDeleteEvent struct {
	RoleID  snowflake.ID `json:"role_id,omitempty"`
	GuildID snowflake.ID `json:"guild_id,omitempty"`
}

type GuildRoleEvent

type GuildRoleEvent struct {
	GuildID snowflake.ID `json:"guild_id,omitempty"`
	Role    discord.Role `json:"role"`
}

type GuildScheduledUserEvent

type GuildScheduledUserEvent struct {
	GuildScheduledEventID snowflake.ID `json:"guild_scheduled_event_id,omitempty"`
	UserID                snowflake.ID `json:"user_id,omitempty"`
	GuildID               snowflake.ID `json:"guild_id,omitempty"`
}

type HelloOp

type HelloOp struct {
	HeartbeatInterval uint `json:"heartbeat_interval"`
}

type Identify

type Identify struct {
	Token          string             `json:"token"`
	Properties     IdentifyProperties `json:"properties"`
	Compress       bool               `json:"compress,omitempty"`
	LargeThreshold int                `json:"large_threshold,omitempty"`
	Shard          []uint16           `json:"shard"`
	Intents        GatewayIntent      `json:"intents"`
}

type IdentifyProperties

type IdentifyProperties struct {
	OS      string `json:"os"`
	Browser string `json:"browser"`
	Device  string `json:"device"`
}

type InternalConnectionClosed

type InternalConnectionClosed struct{}

InternalConnectionClosed is sent when Gateway Status changes to StatusDisconnected

type InternalDispatchEvent

type InternalDispatchEvent = *Event

type InternalEventAllocator

type InternalEventAllocator interface {
	Dereference()
	// contains filtered or unexported methods
}

type InternalHeartbeatEvent

type InternalHeartbeatEvent struct {
	Start time.Time
	End   time.Time
}

type InternalMaxReconnectionLimitReached

type InternalMaxReconnectionLimitReached struct{}

type InternalReadyEvent

type InternalReadyEvent = *ReadyEvent

type InternalStatusChangeEvent

type InternalStatusChangeEvent Status

type InviteCreateEvent

type InviteCreateEvent struct {
	ChannelID         snowflake.ID
	Code              string
	CreatedAt         discord.Timestamp
	GuildID           snowflake.ID
	Inviter           discord.User
	MaxAge            int
	MaxUses           int
	TargetType        discord.InviteTargetType
	TargetUser        discord.User
	TargetApplication discord.Application
	Temporary         bool
	Uses              int
}

type InviteDeleteEvent

type InviteDeleteEvent struct {
	ChannelID snowflake.ID `json:"channel_id,omitempty"`
	GuildID   snowflake.ID `json:"guild_id,omitempty"`
	Code      string       `json:"code,omitempty"`
}

type MessageCreateEvent

type MessageCreateEvent struct {
	discord.Message
	GuildID  snowflake.ID   `json:"guild_id,omitempty"`
	Member   discord.Member `json:"member,omitempty"`
	Mentions []struct {
		discord.User
		Member discord.Member `json:"member,omitempty"`
	} `json:"mentions,omitempty"`
}

type MessageDeleteEvent

type MessageDeleteEvent struct {
	ID        snowflake.ID `json:"id,omitempty"`
	ChannelID snowflake.ID `json:"channel_id,omitempty"`
	GuildID   snowflake.ID `json:"guild_id,omitempty"`
}

type ReadyEvent

type ReadyEvent struct {
	Version          uint                `json:"v"`
	User             discord.User        `json:"user"`
	Guilds           []UnavailableGuild  `json:"guilds"`
	SessionID        string              `json:"session_id"`
	Shard            [2]uint16           `json:"shard"`
	Application      discord.Application `json:"application"`
	ResumeGatewayURL string              `json:"resume_gateway_url"`
}

type RequestGuildMembersParams

type RequestGuildMembersParams struct {
	GuildID   snowflake.ID   `json:"guild_id,omitempty"`
	Query     string         `json:"query,omitempty"`
	Limit     uint           `json:"limit,omitempty"`
	Presences bool           `json:"presences,omitempty"`
	UserIDs   []snowflake.ID `json:"user_i_ds,omitempty"`
	Nonce     string         `json:"nonce,omitempty"`
}

type Status

type Status string
const (
	StatusConnected    Status = "connected"
	StatusConnecting   Status = "connecting"
	StatusReconnecting Status = "reconnecting"
	StatusDisconnected Status = "disconnected"
)

type ThreadCreateEvent

type ThreadCreateEvent struct {
	discord.Channel
	NewlyCreated bool `json:"newly_created,omitempty"`
}

type ThreadDeleteEvent

type ThreadDeleteEvent struct {
	ID       snowflake.ID        `json:"id,omitempty"`
	GuildID  snowflake.ID        `json:"guild_id,omitempty"`
	ParentID snowflake.ID        `json:"parent_id,omitempty"`
	Type     discord.ChannelType `json:"type,omitempty"`
}

type ThreadListSyncEvent

type ThreadListSyncEvent struct {
	GuildID    snowflake.ID           `json:"guild_id,omitempty"`
	ChannelIDs []snowflake.ID         `json:"channel_i_ds,omitempty"`
	Threads    []discord.Channel      `json:"threads,omitempty"`
	Members    []discord.ThreadMember `json:"members,omitempty"`
}

type ThreadMembersUpdateEvent

type ThreadMembersUpdateEvent struct {
	ID               snowflake.ID           `json:"id,omitempty"`
	GuildID          snowflake.ID           `json:"guild_id,omitempty"`
	MemberCount      int                    `json:"member_count,omitempty"`
	AddedMembers     []discord.ThreadMember `json:"added_members,omitempty"`
	RemovedMemberIDs []snowflake.ID         `json:"removed_member_i_ds,omitempty"`
}

type UnavailableGuild

type UnavailableGuild struct {
	Name        string       `json:"name,omitempty"`
	ID          snowflake.ID `json:"id,omitempty"`
	Unavailable bool         `json:"unavailable,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL