permissions

package
v0.0.0-...-d931726 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PermCommand

type PermCommand interface {
	Domain() string
	SubDomains() []SubPermission
}

type Permissions

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

Permissions is a command handler middleware processing permissions for command execution.

func NewPermissions

func NewPermissions(container di.Container) *Permissions

NewPermissions returns a new PermissionsMiddleware instance with the passed database and config instances.

func (*Permissions) Before

func (m *Permissions) Before(ctx *ken.Ctx) (next bool, err error)

func (*Permissions) CheckPermissions

func (m *Permissions) CheckPermissions(s discordutil.ISession, guildID string, userID string, dns ...string) (bool, bool, error)

CheckPermissions tries to fetch the permissions of the specified user on the specified guild and returns true, if any of the passed dns match the fetched permissions array. Also, the override status is returned as well as errors occured during permissions fetching.

If the userID matches the configured bot owner, all bot owner permissions will be added to the fetched permissions array.

If guildID is passed as non-mepty string, all configured guild owner permissions will be added to the fetched permissions array as well.

func (*Permissions) CheckSubPerm

func (m *Permissions) CheckSubPerm(
	ctx ken.Context,
	subDN string,
	explicit bool,
	message ...string,
) (ok bool, err error)

CheckSubPerm takes a command context and checks is the given subDN is permitted.

func (*Permissions) GetMemberPermission

func (m *Permissions) GetMemberPermission(s discordutil.ISession, guildID string, memberID string) (permissions.PermissionArray, error)

GetMemberPermission returns a PermissionsArray based on the passed members roles permissions rulesets for the given guild.

func (*Permissions) GetPermissions

func (m *Permissions) GetPermissions(s discordutil.ISession, guildID, userID string) (perm permissions.PermissionArray, overrideExplicits bool, err error)

GetPermissions tries to fetch the permissions array of the passed user of the specified guild. The merged permissions array is returned as well as the override, which is true when the specified user is the bot owner, guild owner or an admin of the guild.

func (*Permissions) HandleWs

func (m *Permissions) HandleWs(s discordutil.ISession, required string) fiber.Handler

type Provider

type Provider interface {
	ken.MiddlewareBefore

	HandleWs(s discordutil.ISession, required string) fiber.Handler

	// GetPermissions tries to fetch the permissions array of
	// the passed user of the specified guild. The merged
	// permissions array is returned as well as the override,
	// which is true when the specified user is the bot owner,
	// guild owner or an admin of the guild.
	GetPermissions(
		s discordutil.ISession,
		guildID string,
		userID string,
	) (perm permissions.PermissionArray, overrideExplicits bool, err error)

	// CheckPermissions tries to fetch the permissions of the specified user
	// on the specified guild and returns true, if any of the passed dns match
	// the fetched permissions array. Also, the override status is returned as
	// well as errors occured during permissions fetching.
	//
	// If the userID matches the configured bot owner, all bot owner permissions
	// will be added to the fetched permissions array.
	//
	// If guildID is passed as non-mepty string, all configured guild owner
	// permissions will be added to the fetched permissions array as well.
	CheckPermissions(
		s discordutil.ISession,
		guildID string,
		userID string,
		dns ...string,
	) (bool, bool, error)

	// GetMemberPermissions returns a PermissionsArray based on the passed
	// members roles permissions rulesets for the given guild.
	GetMemberPermission(
		s discordutil.ISession,
		guildID string,
		memberID string,
	) (permissions.PermissionArray, error)

	// CheckSubPerm takes a command context and checks is the given
	// subDN is permitted.
	CheckSubPerm(
		ctx ken.Context,
		subDN string,
		explicit bool,
		message ...string,
	) (ok bool, err error)
}

type SubPermission

type SubPermission struct {
	Term        string `json:"term"`
	Explicit    bool   `json:"explicit"`
	Description string `json:"description"`
}

Jump to

Keyboard shortcuts

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