throttler

package
v0.0.0-...-4e18fe8 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package throttler provides implementations for the plugin.Throttler interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PerChannel

func PerChannel(maxInvokes uint, duration time.Duration) plugin.Throttler

PerChannel returns a new plugin.Throttler that works on a per-channel basis. It allows at maximum the passed number of invokes in the passed duration.

func PerGuild

func PerGuild(maxInvokes uint, duration time.Duration) plugin.Throttler

PerGuild returns a new plugin.Throttler that works on a per-guild basis. It allows at maximum the passed number of invokes in the passed duration.

All commands invoked in direct messages will be throttled on a per-user basis.

func PerMember

func PerMember(maxInvokes uint, duration time.Duration) plugin.Throttler

PerMember returns a new plugin.Throttler that works on a per-member basis. It allows at maximum the passed number of invokes in the passed duration. Effectively, this is the same as PerUser but filtered additionally by guild.

All commands invoked in direct messages will be throttled on a per-user basis.

func PerUser

func PerUser(maxInvokes uint, duration time.Duration) plugin.Throttler

PerUser returns a new plugin.Throttler that works on a per-user basis. It allows at maximum the passed number of invokes in the passed duration.

Types

type Condition

type Condition struct {
	// Restrictions is the restriction a user must fulfill to use the
	// throttler in this condition.
	//
	// Restrictions is considered fulfilled, if it returns nil.
	Restrictions plugin.RestrictionFunc
	// Throttler is the plugin.Throttler used if the Restrictions are
	// fulfilled.
	Throttler plugin.Throttler
}

Condition is a single conditional throttler.

type Conditional

type Conditional struct {
	// Conditions contains the conditional throttlers.
	Conditions []Condition
	// Default is the fallback throttler.
	// If it is nil, users encountering this won't be throttled.
	Default plugin.Throttler
}

Conditional is a plugin.Throttler that uses different cooldowns based on restrictions. It will attempt to find the firstmost Condition, where a call to Condition.Restrictions returns nil. If there is no such Condition, the default throttler will be used.

If the throttler of a condition or the default throttler is nil, the encountering user will be regarded as exempt from throttling.

func (Conditional) Check

func (c Conditional) Check(s *state.State, ctx *plugin.Context) (func(), error)

Jump to

Keyboard shortcuts

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