gateway

package
v0.0.0-...-a809f27 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntentGuilds Intents = 1 << iota
	IntentGuildMembers
	IntentGuildBans
	IntentGuildEmojisAndStickers
	IntentGuildIntegrations
	IntentGuildWebhooks
	IntentGuildInvites
	IntentGuildVoiceStates
	IntentGuildPresences
	IntentGuildMessages
	IntentGuildMessageReactions
	IntentGuildMessageTyping
	IntentDirectMessages
	IntentDirectMessageReactions
	IntentDirectMessageTyping
	IntentMessageContent
	IntentGuildScheduledEvents

	IntentAutoModerationConfiguration
	IntentAutoModerationExecution

	IntentsGuild = IntentGuilds |
		IntentGuildMembers |
		IntentGuildBans |
		IntentGuildEmojisAndStickers |
		IntentGuildIntegrations |
		IntentGuildWebhooks |
		IntentGuildInvites |
		IntentGuildVoiceStates |
		IntentGuildPresences |
		IntentGuildMessages |
		IntentGuildMessageReactions |
		IntentGuildMessageTyping |
		IntentGuildScheduledEvents

	IntentsDirectMessage = IntentDirectMessages |
		IntentDirectMessageReactions |
		IntentDirectMessageTyping

	IntentsNonPrivileged = IntentGuilds |
		IntentGuildBans |
		IntentGuildEmojisAndStickers |
		IntentGuildIntegrations |
		IntentGuildWebhooks |
		IntentGuildInvites |
		IntentGuildVoiceStates |
		IntentGuildMessages |
		IntentGuildMessageReactions |
		IntentGuildMessageTyping |
		IntentDirectMessages |
		IntentDirectMessageReactions |
		IntentDirectMessageTyping |
		IntentGuildScheduledEvents |
		IntentAutoModerationConfiguration |
		IntentAutoModerationExecution

	IntentsPrivileged = IntentGuildMembers |
		IntentGuildPresences | IntentMessageContent

	IntentsAll = IntentsNonPrivileged |
		IntentsPrivileged

	IntentsDefault = IntentsNone

	IntentsNone int = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationCommandPermissionsUpdateHandler

type ApplicationCommandPermissionsUpdateHandler struct{}

func (*ApplicationCommandPermissionsUpdateHandler) Handle

type AutoModerationActionExecutionHandler

type AutoModerationActionExecutionHandler struct{}

func (*AutoModerationActionExecutionHandler) Handle

func (_ *AutoModerationActionExecutionHandler) Handle(s *Session, data []byte)

type AutoModerationRuleCreateHandler

type AutoModerationRuleCreateHandler struct{}

func (*AutoModerationRuleCreateHandler) Handle

func (_ *AutoModerationRuleCreateHandler) Handle(s *Session, data []byte)

type AutoModerationRuleDeleteHandler

type AutoModerationRuleDeleteHandler struct{}

func (*AutoModerationRuleDeleteHandler) Handle

func (_ *AutoModerationRuleDeleteHandler) Handle(s *Session, data []byte)

type AutoModerationRuleUpdateHandler

type AutoModerationRuleUpdateHandler struct{}

func (*AutoModerationRuleUpdateHandler) Handle

func (_ *AutoModerationRuleUpdateHandler) Handle(s *Session, data []byte)

type ChannelCreateHandler

type ChannelCreateHandler struct{}

func (*ChannelCreateHandler) Handle

func (_ *ChannelCreateHandler) Handle(s *Session, data []byte)

type ChannelDeleteHandler

type ChannelDeleteHandler struct{}

func (*ChannelDeleteHandler) Handle

func (_ *ChannelDeleteHandler) Handle(s *Session, data []byte)

type ChannelPinsUpdateHandler

type ChannelPinsUpdateHandler struct{}

func (*ChannelPinsUpdateHandler) Handle

func (_ *ChannelPinsUpdateHandler) Handle(s *Session, data []byte)

type ChannelUpdateHandler

type ChannelUpdateHandler struct{}

func (*ChannelUpdateHandler) Handle

func (_ *ChannelUpdateHandler) Handle(s *Session, data []byte)

type EventHandler

type EventHandler interface {
	Handle(s *Session, data []byte)
}

type GuildBanAddHandler

type GuildBanAddHandler struct{}

func (*GuildBanAddHandler) Handle

func (_ *GuildBanAddHandler) Handle(s *Session, data []byte)

type GuildBanRemoveHandler

type GuildBanRemoveHandler struct{}

func (*GuildBanRemoveHandler) Handle

func (_ *GuildBanRemoveHandler) Handle(s *Session, data []byte)

type GuildCreateHandler

type GuildCreateHandler struct{}

func (*GuildCreateHandler) Handle

func (_ *GuildCreateHandler) Handle(s *Session, data []byte)

type GuildDeleteHandler

type GuildDeleteHandler struct{}

func (*GuildDeleteHandler) Handle

func (_ *GuildDeleteHandler) Handle(s *Session, data []byte)

type GuildEmojisUpdateHandler

type GuildEmojisUpdateHandler struct{}

func (*GuildEmojisUpdateHandler) Handle

func (_ *GuildEmojisUpdateHandler) Handle(s *Session, data []byte)

type GuildIntegrationsUpdateHandler

type GuildIntegrationsUpdateHandler struct{}

func (*GuildIntegrationsUpdateHandler) Handle

func (_ *GuildIntegrationsUpdateHandler) Handle(s *Session, data []byte)

type GuildMemberAddHandler

type GuildMemberAddHandler struct{}

func (*GuildMemberAddHandler) Handle

func (_ *GuildMemberAddHandler) Handle(s *Session, data []byte)

type GuildMemberRemoveHandler

type GuildMemberRemoveHandler struct{}

func (*GuildMemberRemoveHandler) Handle

func (_ *GuildMemberRemoveHandler) Handle(s *Session, data []byte)

type GuildMemberUpdateHandler

type GuildMemberUpdateHandler struct{}

func (*GuildMemberUpdateHandler) Handle

func (_ *GuildMemberUpdateHandler) Handle(s *Session, data []byte)

type GuildMembersChunkHandler

type GuildMembersChunkHandler struct{}

func (*GuildMembersChunkHandler) Handle

func (_ *GuildMembersChunkHandler) Handle(s *Session, data []byte)

type GuildRoleCreateHandler

type GuildRoleCreateHandler struct{}

func (*GuildRoleCreateHandler) Handle

func (_ *GuildRoleCreateHandler) Handle(s *Session, data []byte)

type GuildRoleDeleteHandler

type GuildRoleDeleteHandler struct{}

func (*GuildRoleDeleteHandler) Handle

func (_ *GuildRoleDeleteHandler) Handle(s *Session, data []byte)

type GuildRoleUpdateHandler

type GuildRoleUpdateHandler struct{}

func (*GuildRoleUpdateHandler) Handle

func (_ *GuildRoleUpdateHandler) Handle(s *Session, data []byte)

type GuildStickersUpdateHandler

type GuildStickersUpdateHandler struct{}

func (*GuildStickersUpdateHandler) Handle

func (_ *GuildStickersUpdateHandler) Handle(s *Session, data []byte)

type GuildUpdateHandler

type GuildUpdateHandler struct{}

func (*GuildUpdateHandler) Handle

func (_ *GuildUpdateHandler) Handle(s *Session, data []byte)

type Intents

type Intents int

Intents is a bitfield of intents used to specify the gateway events you want to receive.

type InteractionCreateHandler

type InteractionCreateHandler struct{}

func (*InteractionCreateHandler) Handle

func (_ *InteractionCreateHandler) Handle(s *Session, data []byte)

type MessageCreateHandler

type MessageCreateHandler struct{}

func (*MessageCreateHandler) Handle

func (_ *MessageCreateHandler) Handle(s *Session, data []byte)

type MessageReactionHandler

type MessageReactionHandler struct{}

func (*MessageReactionHandler) Handle

func (_ *MessageReactionHandler) Handle(s *Session, data []byte)

type Options

type Options struct {
	Token   string
	Intents Intents
}

Options is the options for the gateway, it contains the token, intents and some other options.

type PresenceUpdateHandler

type PresenceUpdateHandler struct{}

func (*PresenceUpdateHandler) Handle

func (_ *PresenceUpdateHandler) Handle(s *Session, Data []byte)

type ReadyHandler

type ReadyHandler struct{}

func (*ReadyHandler) Handle

func (_ *ReadyHandler) Handle(s *Session, data []byte)

type ResumedHandler

type ResumedHandler struct{}

func (*ResumedHandler) Handle

func (_ *ResumedHandler) Handle(s *Session, _ []byte)

type Session

type Session struct {
	sync.RWMutex

	// voice conn
	VoiceConnections map[string]*VoiceConnection

	// Rest handlers
	Application *rest.ApplicationHandler
	Channel     *rest.ChannelHandler
	Emoji       *rest.EmojiHandler
	Guild       *rest.GuildHandler
	Interaction *rest.InteractionHandler
	Invite      *rest.InviteHandler
	Template    *rest.TemplateHandler
	User        *rest.UserHandler
	Voice       *rest.VoiceHandler
	Webhook     *rest.WebhookHandler
	// contains filtered or unexported fields
}

func NewSession

func NewSession(options *Options) *Session

func (*Session) Bus

func (s *Session) Bus() *ev.EventBus

Bus returns the event bus of the session.

func (*Session) Close

func (s *Session) Close()

Close closes the session.

func (*Session) CloseWithCode

func (s *Session) CloseWithCode(code int, message string)

CloseWithCode closes the session with a specific close code and message.

func (*Session) JoinVoiceChannel

func (s *Session) JoinVoiceChannel(guildId, channelId string, muted, deafened bool) (*VoiceConnection, error)

JoinVoiceChannel joins a voice channel.

func (*Session) JoinVoiceChannelIncomplete

func (s *Session) JoinVoiceChannelIncomplete(guildId, channelId string, muted, deafened bool) error

func (*Session) Latency

func (s *Session) Latency() time.Duration

Latency returns the latency of the session.

func (*Session) Login

func (s *Session) Login() error

Login connects the session to the gateway.

func (*Session) Me

func (s *Session) Me() *discord.User

Me returns the current user of the session.

func (*Session) On

func (s *Session) On(ev event.EventType, fn any) error

On registers a callback for an event type.

func (*Session) Publish

func (s *Session) Publish(ev event.EventType, args ...any)

Publish publishes an event to the event bus.

func (*Session) Send

func (s *Session) Send(v interface{}) error

Send sends a packet to the gateway.

func (*Session) SetActivity

func (s *Session) SetActivity(activity *discord.Activity) error

SetActivity sets the activity of the session.

func (*Session) SetStatus

func (s *Session) SetStatus(status discord.StatusType) error

SetStatus sets the status of the session.

func (*Session) State

func (s *Session) State() *State

State returns the current state of the session.

func (*Session) Status

func (s *Session) Status() Status

Status returns the current status of the session.

func (*Session) UpdatePresence

func (s *Session) UpdatePresence(status *packet.PresenceUpdate) error

UpdatePresence updates the status and activity of the session.

type State

type State struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewState

func NewState(session *Session) *State

NewState creates a new state

func (*State) AddChannel

func (s *State) AddChannel(channel *discord.Channel)

AddChannel adds a channel to the state

func (*State) AddEmoji

func (s *State) AddEmoji(guildId string, emoji *discord.Emoji) error

AddEmoji adds an emoji to the state

func (*State) AddEmojis

func (s *State) AddEmojis(guildId string, emojis []*discord.Emoji) error

AddEmojis adds emojis to the state

func (*State) AddGuild

func (s *State) AddGuild(guild *discord.Guild)

AddGuild adds a guild to the state

func (*State) AddMember

func (s *State) AddMember(guildID string, member *discord.GuildMember)

AddMember adds a member to the state

func (*State) AddRole

func (s *State) AddRole(guildId string, role *discord.Role) error

AddRole adds a role to the state

func (*State) Channel

func (s *State) Channel(id string) (*discord.Channel, error)

Channel returns a channel from the state

func (*State) Channels

func (s *State) Channels() map[string]*discord.Channel

Channels returns all channels from the state

func (*State) Emoji

func (s *State) Emoji(guildId, emojiId string) (*discord.Emoji, error)

Emoji returns an emoji from the state

func (*State) Guild

func (s *State) Guild(guildID string) (*discord.Guild, error)

Guild returns a guild from the state

func (*State) Guilds

func (s *State) Guilds() map[string]*discord.Guild

Guilds returns all guilds from the state

func (*State) Member

func (s *State) Member(guildID string, userID string) (*discord.GuildMember, error)

Member returns a member from the state

func (*State) Members

func (s *State) Members() map[string]map[string]*discord.GuildMember

Members returns all members from the state

func (*State) RemoveChannel

func (s *State) RemoveChannel(channel *discord.Channel)

RemoveChannel removes a channel from the state

func (*State) RemoveGuild

func (s *State) RemoveGuild(guild *discord.Guild) error

RemoveGuild removes a guild from the state

func (*State) RemoveMember

func (s *State) RemoveMember(guildId string, memberId string)

RemoveMember removes a member from the state

func (*State) RemoveRole

func (s *State) RemoveRole(guildId, roleId string) error

RemoveRole removes a role from the state

func (*State) Role

func (s *State) Role(guildId, roleId string) (*discord.Role, error)

Role returns a role from the state

func (*State) UpdateVoiceState

func (s *State) UpdateVoiceState(ev *event.VoiceStateUpdate) error

UpdateVoiceState updates a voice state in the state

func (*State) VoiceState

func (s *State) VoiceState(guildId, userId string) (*discord.VoiceState, error)

VoiceState returns a voice state from the state

type Status

type Status int
const (
	StatusUnconnected Status = iota
	StatusConnecting
	StatusWaitingForHello
	StatusWaitingForReady
	StatusIdentifying
	StatusReady
	StatusResuming
	StatusDisconnected
)

type ThreadCreateHandler

type ThreadCreateHandler struct{}

func (*ThreadCreateHandler) Handle

func (_ *ThreadCreateHandler) Handle(s *Session, data []byte)

type ThreadDeleteHandler

type ThreadDeleteHandler struct{}

func (*ThreadDeleteHandler) Handle

func (_ *ThreadDeleteHandler) Handle(s *Session, data []byte)

type ThreadListSyncHandler

type ThreadListSyncHandler struct{}

func (*ThreadListSyncHandler) Handle

func (_ *ThreadListSyncHandler) Handle(s *Session, data []byte)

type ThreadMemberUpdateHandler

type ThreadMemberUpdateHandler struct{}

func (*ThreadMemberUpdateHandler) Handle

func (_ *ThreadMemberUpdateHandler) Handle(s *Session, data []byte)

type ThreadMembersUpdateHandler

type ThreadMembersUpdateHandler struct{}

func (*ThreadMembersUpdateHandler) Handle

func (_ *ThreadMembersUpdateHandler) Handle(s *Session, data []byte)

type ThreadUpdateHandler

type ThreadUpdateHandler struct{}

func (*ThreadUpdateHandler) Handle

func (_ *ThreadUpdateHandler) Handle(s *Session, data []byte)

type VoiceConnection

type VoiceConnection struct {
	sync.RWMutex

	UserId    string
	GuildId   string
	ChannelId string
	// contains filtered or unexported fields
}

func (*VoiceConnection) Close

func (v *VoiceConnection) Close()

Close closes the voice connection.

func (*VoiceConnection) Disconnect

func (v *VoiceConnection) Disconnect() (err error)

Disconnect disconnects the bot from the voice channel and closes the voice connection.

func (*VoiceConnection) Ready

func (v *VoiceConnection) Ready() bool

Ready returns whether the voice connection is ready.

func (*VoiceConnection) Speaking

func (v *VoiceConnection) Speaking(speaking bool) error

Speaking sets the speaking state of the voice connection.

func (*VoiceConnection) Write

func (v *VoiceConnection) Write(b []byte) (int, error)

Write sends a frame of audio to the voice connection.

type VoiceServerUpdateHandler

type VoiceServerUpdateHandler struct{}

func (*VoiceServerUpdateHandler) Handle

func (_ *VoiceServerUpdateHandler) Handle(s *Session, data []byte)

type VoiceStateUpdateHandler

type VoiceStateUpdateHandler struct{}

func (*VoiceStateUpdateHandler) Handle

func (_ *VoiceStateUpdateHandler) Handle(s *Session, data []byte)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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