permission

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Disable = "disable"
View Source
const Enable = "enable"

Variables

View Source
var (
	ErrPermissionExist    = errors.New("already exist")
	ErrPermissionNotExist = errors.New("not exist")
	ErrPermissionDenied   = errors.New("permission denied")
	ErrDisabled           = errors.New("disabled")
	ErrGlobalDisabled     = errors.New("global disabled")
	ErrGlobalSilenced     = errors.New("global silenced")
)

Functions

func IsPermissionError added in v0.0.13

func IsPermissionError(err error) bool

Types

type KeySet

type KeySet struct{}

func NewKeySet

func NewKeySet() *KeySet

func (*KeySet) BlockListKey

func (k *KeySet) BlockListKey(keys ...interface{}) string

func (*KeySet) GlobalEnabledKey added in v0.0.16

func (k *KeySet) GlobalEnabledKey(keys ...interface{}) string

func (*KeySet) GlobalSilenceKey added in v0.1.3

func (k *KeySet) GlobalSilenceKey(keys ...interface{}) string

func (*KeySet) GroupEnabledKey

func (k *KeySet) GroupEnabledKey(keys ...interface{}) string

func (*KeySet) GroupPermissionKey

func (k *KeySet) GroupPermissionKey(keys ...interface{}) string

func (*KeySet) GroupSilenceKey added in v0.1.3

func (k *KeySet) GroupSilenceKey(keys ...interface{}) string

func (*KeySet) PermissionKey

func (k *KeySet) PermissionKey(keys ...interface{}) string

type RequireOption

type RequireOption interface {
	Validate(s *StateManager) bool
}

func AdminRoleRequireOption

func AdminRoleRequireOption(uin int64) RequireOption

func GroupAdminRoleRequireOption

func GroupAdminRoleRequireOption(groupCode int64, uin int64) RequireOption

func GroupCommandRequireOption

func GroupCommandRequireOption(groupCode int64, uin int64, command string) RequireOption

func QQAdminRequireOption

func QQAdminRequireOption(groupCode int64, uin int64) RequireOption

type RoleType

type RoleType int64
const (
	Unknown RoleType = 0

	Admin RoleType = 1 << iota
	GroupAdmin
	User
)

func NewRoleFromString added in v0.0.16

func NewRoleFromString(s string) RoleType

func (RoleType) String

func (t RoleType) String() string

type StateManager

type StateManager struct {
	*localdb.ShortCut
	*KeySet
}

func NewStateManager

func NewStateManager() *StateManager

func (*StateManager) AddBlockList

func (c *StateManager) AddBlockList(caller int64, d time.Duration) error

func (*StateManager) CheckAdmin added in v1.0.3

func (c *StateManager) CheckAdmin(caller int64) bool

func (*StateManager) CheckBlockList

func (c *StateManager) CheckBlockList(caller int64) bool

CheckBlockList return true if blocked

func (*StateManager) CheckGlobalCommandDisabled added in v0.0.16

func (c *StateManager) CheckGlobalCommandDisabled(command string) bool

func (*StateManager) CheckGlobalCommandFunc added in v0.0.16

func (c *StateManager) CheckGlobalCommandFunc(command string, f func(val string, exist bool) bool) bool

func (*StateManager) CheckGlobalSilence added in v0.1.3

func (c *StateManager) CheckGlobalSilence() bool

func (*StateManager) CheckGroupAdmin added in v1.0.3

func (c *StateManager) CheckGroupAdmin(groupCode int64, caller int64) bool

func (*StateManager) CheckGroupAdministrator

func (c *StateManager) CheckGroupAdministrator(groupCode int64, caller int64) bool

func (*StateManager) CheckGroupCommandDisabled

func (c *StateManager) CheckGroupCommandDisabled(groupCode int64, command string) bool

CheckGroupCommandDisabled check global first, then check explicit disabled, must exist

func (*StateManager) CheckGroupCommandEnabled

func (c *StateManager) CheckGroupCommandEnabled(groupCode int64, command string) bool

CheckGroupCommandEnabled check global first, check explicit enabled, must exist

func (*StateManager) CheckGroupCommandFunc

func (c *StateManager) CheckGroupCommandFunc(groupCode int64, command string, f func(val string, exist bool) bool) bool

func (*StateManager) CheckGroupCommandPermission

func (c *StateManager) CheckGroupCommandPermission(groupCode int64, caller int64, command string) bool

func (*StateManager) CheckGroupRole

func (c *StateManager) CheckGroupRole(groupCode int64, caller int64, role RoleType) bool

func (*StateManager) CheckGroupSilence added in v0.1.3

func (c *StateManager) CheckGroupSilence(groupCode int64) bool

func (*StateManager) CheckNoAdmin added in v0.0.16

func (c *StateManager) CheckNoAdmin() bool

func (*StateManager) CheckRole

func (c *StateManager) CheckRole(caller int64, role RoleType) bool

func (*StateManager) DeleteBlockList

func (c *StateManager) DeleteBlockList(caller int64) error

func (*StateManager) DisableGroupCommand

func (c *StateManager) DisableGroupCommand(groupCode int64, command string) error

func (*StateManager) EnableGroupCommand

func (c *StateManager) EnableGroupCommand(groupCode int64, command string) error

func (*StateManager) FreshIndex

func (c *StateManager) FreshIndex()

func (*StateManager) GlobalDisableGroupCommand added in v0.0.16

func (c *StateManager) GlobalDisableGroupCommand(command string) error

func (*StateManager) GlobalEnableGroupCommand added in v0.0.16

func (c *StateManager) GlobalEnableGroupCommand(command string) error

func (*StateManager) GlobalSilence added in v0.1.3

func (c *StateManager) GlobalSilence() error

func (*StateManager) GrantGroupRole

func (c *StateManager) GrantGroupRole(groupCode int64, target int64, role RoleType) error

func (*StateManager) GrantPermission

func (c *StateManager) GrantPermission(groupCode int64, target int64, command string) error

func (*StateManager) GrantRole

func (c *StateManager) GrantRole(target int64, role RoleType) error

func (*StateManager) GroupSilence added in v0.1.3

func (c *StateManager) GroupSilence(groupCode int64) error

func (*StateManager) ListAdmin added in v0.1.3

func (c *StateManager) ListAdmin() []int64

func (*StateManager) ListGroupAdmin added in v1.0.4

func (c *StateManager) ListGroupAdmin(groupCode int64) []int64

func (*StateManager) RemoveAllByGroupCode added in v0.0.19

func (c *StateManager) RemoveAllByGroupCode(groupCode int64) ([]string, error)

func (*StateManager) RequireAny

func (c *StateManager) RequireAny(option ...RequireOption) bool

func (*StateManager) UndoGlobalSilence added in v0.1.3

func (c *StateManager) UndoGlobalSilence() error

func (*StateManager) UndoGroupSilence added in v0.1.3

func (c *StateManager) UndoGroupSilence(groupCode int64) error

func (*StateManager) UngrantGroupRole

func (c *StateManager) UngrantGroupRole(groupCode int64, target int64, role RoleType) error

func (*StateManager) UngrantPermission

func (c *StateManager) UngrantPermission(groupCode int64, target int64, command string) error

func (*StateManager) UngrantRole

func (c *StateManager) UngrantRole(target int64, role RoleType) error

Jump to

Keyboard shortcuts

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