roles

package
v0.0.0-...-905e761 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTimeout       = time.Second * 30
	DefaultRetryInterval = time.Millisecond * 1500
)

Functions

func ApplyRole

func ApplyRole(applyCtx context.Context, session *discordgo.Session, guildID, userID, roleID uint64, add bool) (result <-chan ApplyRoleResult)

ApplyRole starts a retry loop to try to apply a role before a specified deadline.

Give this a context that can be canceled by a GUILD_MEMBER_UPDATE event pre-empting the next retry. https://discord.com/developers/docs/topics/gateway#guild-member-update

From observed behavior, we can infer that role application is an asynchronous/eventually consistent API call that sometimes fails to work on large (>5000 user) servers. So we just keep applying the role until it finally works or *we* time out trying to apply it.

Types

type ApplyRoleResult

type ApplyRoleResult struct {
	Attempts int
	Error    error
}

type RoleUpdateTrackData

type RoleUpdateTrackData struct {
	// Fields extracted from *discordgo.GuildMemberUpdate
	GuildID string   // gmu.GuildID
	UserID  string   // gmu.User.ID
	Roles   []string // gmu.Roles

	// If this information comes from polling instead of an actual GUILD_MEMBER_UPDATE event
	Polled bool
}

type RoleUpdateTrackFunc

type RoleUpdateTrackFunc func(RoleUpdateTrackData) (removeHook bool)

type RoleUpdateTracker

type RoleUpdateTracker struct {
	// contains filtered or unexported fields
}

func NewRoleUpdateTracker

func NewRoleUpdateTracker(session *discordgo.Session) *RoleUpdateTracker

func (*RoleUpdateTracker) TrackHook

func (r *RoleUpdateTracker) TrackHook(guildID, userID string, trackFunc RoleUpdateTrackFunc)

TrackHook executes a function on GUILD_MEMBER_UPDATE.

Jump to

Keyboard shortcuts

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