ratelimit

package
v0.0.0-...-cccb011 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: BSD-3-Clause Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const IdentifyWait = 6 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStore

type MemoryStore struct {
	sync.Mutex
	Cache *ttlcache.Cache // handles mutex for us
	// contains filtered or unexported fields
}

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) UpdateGlobalRateLimit

func (s *MemoryStore) UpdateGlobalRateLimit(resetAfter time.Duration)

func (*MemoryStore) UpdateRateLimit

func (s *MemoryStore) UpdateRateLimit(route Route, remaining int, resetAfter time.Duration) error

type RateLimitStore

type RateLimitStore interface {
	UpdateRateLimit(route Route, remaining int, resetAfter time.Duration) error
	UpdateGlobalRateLimit(resetAfter time.Duration)
	// contains filtered or unexported methods
}

type Ratelimiter

type Ratelimiter struct {
	sync.Mutex
	Store RateLimitStore
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(store RateLimitStore, largeShardingBuckets int) *Ratelimiter

func (*Ratelimiter) ExecuteCall

func (l *Ratelimiter) ExecuteCall(route Route, ch chan error)

func (*Ratelimiter) IdentifyWait

func (l *Ratelimiter) IdentifyWait(shardId int) error

type RedisStore

type RedisStore struct {
	*redis.Client

	ContextBuilder func() context.Context
	// contains filtered or unexported fields
}

func NewRedisStore

func NewRedisStore(client *redis.Client, keyPrefix string) *RedisStore

func (*RedisStore) UpdateGlobalRateLimit

func (s *RedisStore) UpdateGlobalRateLimit(resetAfter time.Duration)

func (*RedisStore) UpdateRateLimit

func (s *RedisStore) UpdateRateLimit(route Route, remaining int, resetAfter time.Duration) error

type Route

type Route struct {
	Type      RouteType
	Id        RouteId
	Snowflake uint64
}

func NewApplicationRoute

func NewApplicationRoute(id RouteId, snowflake uint64) Route

func NewChannelRoute

func NewChannelRoute(id RouteId, snowflake uint64) Route

func NewGuildRoute

func NewGuildRoute(id RouteId, snowflake uint64) Route

func NewOtherRoute

func NewOtherRoute(id RouteId, snowflake uint64) Route

func NewRoute

func NewRoute(routeType RouteType, id RouteId, snowflake uint64) Route

func NewWebhookRoute

func NewWebhookRoute(id RouteId, snowflake uint64) Route

type RouteId

type RouteId uint16
const (
	// /guilds/:id/audit-logs
	RouteGetGuildAuditLog RouteId = iota

	// /channels/:id/...
	RouteGetChannel
	RouteModifyChannel
	RouteDeleteChannel
	RouteGetChannelMessages
	RouteGetChannelMessage
	RouteCreateMessage
	RouteCrosspostMessage
	RouteCreateReaction
	RouteDeleteOwnReaction
	RouteDeleteUserReaction
	RouteGetReactions
	RouteDeleteAllReactions
	RouteDeleteAllReactionsForEmoji
	RouteEditMessage
	RouteDeleteMessage
	RouteBulkDeleteMessages
	RouteEditChannelPermissions
	RouteGetChannelInvites
	RouteCreateChannelInvite
	RouteDeleteChannelPermission
	RouteFollowNewsChannel
	RouteTriggerTypingIndicator
	RouteGetPinnedMessages
	RouteAddPinnedChannelMessage
	RouteDeletePinnedChannelMessage
	RouteJoinThread
	RouteAddThreadMember
	RouteLeaveThread
	RouteRemoveThreadMember
	RouteListThreadMembers
	RouteGetThreadMember
	RouteStartThreadWithMessage
	RouteStartThreadWithoutMessage
	RouteGetActiveThreads
	RouteGetArchivedPrivateSelfThreads
	RouteGetArchivedPublicThreads
	RouteGetArchivedPrivateThreads
	RouteGroupDMAddRecipient
	RouteGroupDMRemoveRecipient

	// /guilds/:id/emojis
	RouteListGuildEmojis
	RouteGetGuildEmoji
	RouteCreateGuildEmoji
	RouteModifyGuildEmoji
	RouteDeleteGuildEmoji

	// /guilds/:id/...
	RouteCreateGuild
	RouteGetGuild
	RouteGetGuildPreview
	RouteModifyGuild
	RouteDeleteGuild
	RouteGetGuildChannels
	RouteCreateGuildChannel
	RouteModifyGuildChannelPositions
	RouteGetGuildMember
	RouteSearchGuildMembers
	RouteListGuildMembers
	RouteAddGuildMember
	RouteModifyGuildMember
	RouteModifyCurrentUserNick
	RouteAddGuildMemberRole
	RouteRemoveGuildMemberRole
	RouteRemoveGuildMember
	RouteGetGuildBans
	RouteGetGuildBan
	RouteCreateGuildBan
	RouteRemoveGuildBan
	RouteGetGuildRoles
	RouteCreateGuildRole
	RouteModifyGuildRolePositions
	RouteModifyGuildRole
	RouteDeleteGuildRole
	RouteGetGuildPruneCount
	RouteBeginGuildPrune
	RouteGetGuildVoiceRegions
	RouteGetGuildInvites
	RouteGetGuildIntegrations
	RouteCreateGuildIntegration
	RouteModifyGuildIntegration
	RouteDeleteGuildIntegration
	RouteSyncGuildIntegration
	RouteGetGuildWidgetSettings
	RouteModifyGuildWidget
	RouteGetGuildWidget
	RouteGetGuildVanityURL
	RouteGuildWidgetImage

	// /invites/:id
	// Invites seemingly don't have ratelimits, but we need these enums internally
	RouteGetInvite
	RouteDeleteInvite

	// /guilds/templates/:code
	// Also seemingly no ratelimits
	RouteGetTemplate
	RouteCreateGuildTemplate

	// /users/:id/...
	// Again, seemingly no ratelimits but we need these internally
	RouteGetCurrentUser
	RouteGetUser
	RouteModifyCurrentUser
	RouteGetCurrentUserGuilds
	RouteLeaveGuild
	RouteGetUserDMs
	RouteCreateDM
	RouteCreateGroupDM
	RouteGetUserConnections

	// /voice/regions
	RouteListVoiceRegions

	// /channels/:id/webhooks
	RouteCreateWebhook
	RouteGetChannelWebhooks

	// /guilds/:id/webhooks
	RouteGetGuildWebhooks

	// /webhooks/:id/...
	RouteGetWebhook
	RouteGetWebhookWithToken
	RouteModifyWebhook
	RouteModifyWebhookWithToken
	RouteDeleteWebhook
	RouteDeleteWebhookWithToken
	RouteExecuteWebhook
	RouteEditWebhookMessage

	// /applications/:id/...
	RouteGetGlobalCommands
	RouteCreateGlobalCommand
	RouteModifyGlobalCommand
	RouteModifyGlobalCommands
	RouteDeleteGlobalCommand

	// /applications/:id/guild/...
	RouteGetGuildCommands
	RouteCreateGuildCommand
	RouteModifyGuildCommand
	RouteModifyGuildCommands
	RouteDeleteGuildCommand

	// /applications/:id/guild/.../permissions
	RouteGetCommandPermissions
	RouteGetBulkCommandPermissions
	RouteEditCommandPermissions
	RouteEditBulkCommandPermissions

	// /webhooks/:id/:token/...
	RouteGetOriginalInteractionResponse
	RouteEditOriginalInteractionResponse
	RouteDeleteOriginalInteractionResponse
	RouteCreateFollowupMessage
	RouteGetFollowupMessage
	RouteEditFollowupMessage
	RouteDeleteFollowupMessage

	// /applications/@me
	RouteGetCurrentApplication
	RouteEditCurrentApplication

	///applications/:id/entitlements
	RouteListEntitlements
	RouteConsumeEntitlement
	RouteCreateTestEntitlement
	RouteDeleteTestEntitlement

	// /oauth2/
	RouteOauth2TokenExchange
	RouteOauth2TokenRevoke
)

type RouteType

type RouteType uint8
const (
	RouteTypeGuild RouteType = iota
	RouteTypeChannel
	RouteTypeWebhook
	RouteTypeApplication
	RouteTypeOther
)

Jump to

Keyboard shortcuts

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