user

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeCanSendChatMessages will allow sending chat messages as itself.
	ScopeCanSendChatMessages = "CAN_SEND_MESSAGES"
	// ScopeCanSendSystemMessages will allow sending chat messages as the system.
	ScopeCanSendSystemMessages = "CAN_SEND_SYSTEM_MESSAGES"
	// ScopeHasAdminAccess will allow performing administrative actions on the server.
	ScopeHasAdminAccess = "HAS_ADMIN_ACCESS"
)

Variables

This section is empty.

Functions

func ChangeUserColor added in v0.1.0

func ChangeUserColor(userID string, color int) error

ChangeUserColor will change the user associated to userID from one display name to another.

func ChangeUsername

func ChangeUsername(userID string, username string) error

ChangeUsername will change the user associated to userID from one display name to another.

func DeleteExternalAPIUser

func DeleteExternalAPIUser(token string) error

DeleteExternalAPIUser will delete a token from the database.

func GetIntegrationNameForAccessToken

func GetIntegrationNameForAccessToken(token string) *string

GetIntegrationNameForAccessToken will return the integration name associated with a specific access token.

func HasValidScopes

func HasValidScopes(scopes []string) bool

HasValidScopes will verify that all the scopes provided are valid.

func InsertExternalAPIUser

func InsertExternalAPIUser(token string, name string, color int, scopes []string) error

InsertExternalAPIUser will add a new API user to the database.

func IsDisplayNameAvailable added in v0.0.12

func IsDisplayNameAvailable(displayName string) (bool, error)

IsDisplayNameAvailable will check if the proposed name is available for use.

func SetAccessTokenToOwner added in v0.0.12

func SetAccessTokenToOwner(token, userID string) error

SetAccessTokenToOwner will reassign an access token to be owned by a different user. Used for logging in with external auth.

func SetEnabled

func SetEnabled(userID string, enabled bool) error

SetEnabled will set the enabled status of a single user by ID.

func SetExternalAPIUserAccessTokenAsUsed

func SetExternalAPIUserAccessTokenAsUsed(token string) error

SetExternalAPIUserAccessTokenAsUsed will update the last used timestamp for a token.

func SetModerator added in v0.0.11

func SetModerator(userID string, isModerator bool) error

SetModerator will add or remove moderator status for a single user by ID.

func SetUserAsAuthenticated added in v0.0.12

func SetUserAsAuthenticated(userID string) error

SetUserAsAuthenticated will mark that a user has been authenticated in some way.

func SetupUsers

func SetupUsers()

SetupUsers will perform the initial initialization of the user package.

Types

type ExternalAPIUser

type ExternalAPIUser struct {
	CreatedAt    time.Time  `json:"createdAt"`
	LastUsedAt   *time.Time `json:"lastUsedAt,omitempty"`
	ID           string     `json:"id"`
	AccessToken  string     `json:"accessToken"`
	DisplayName  string     `json:"displayName"`
	Type         string     `json:"type,omitempty"` // Should be API
	Scopes       []string   `json:"scopes"`
	DisplayColor int        `json:"displayColor"`
	IsBot        bool       `json:"isBot"`
}

ExternalAPIUser represents a single 3rd party integration that uses an access token. This struct mostly matches the User struct so they can be used interchangeably.

func GetExternalAPIUser

func GetExternalAPIUser() ([]ExternalAPIUser, error)

GetExternalAPIUser will return all API users with access tokens.

func GetExternalAPIUserForAccessTokenAndScope

func GetExternalAPIUserForAccessTokenAndScope(token string, scope string) (*ExternalAPIUser, error)

GetExternalAPIUserForAccessTokenAndScope will determine if a specific token has access to perform a scoped action.

type User

type User struct {
	CreatedAt       time.Time  `json:"createdAt"`
	DisabledAt      *time.Time `json:"disabledAt,omitempty"`
	NameChangedAt   *time.Time `json:"nameChangedAt,omitempty"`
	AuthenticatedAt *time.Time `json:"-"`
	ID              string     `json:"id"`
	DisplayName     string     `json:"displayName"`
	PreviousNames   []string   `json:"previousNames"`
	Scopes          []string   `json:"scopes,omitempty"`
	DisplayColor    int        `json:"displayColor"`
	IsBot           bool       `json:"isBot"`
	Authenticated   bool       `json:"authenticated"`
}

User represents a single chat user.

func CreateAnonymousUser

func CreateAnonymousUser(displayName string) (*User, string, error)

CreateAnonymousUser will create a new anonymous user with the provided display name.

func GetDisabledUsers

func GetDisabledUsers() []*User

GetDisabledUsers will return back all the currently disabled users that are not API users.

func GetModeratorUsers added in v0.0.11

func GetModeratorUsers() []*User

GetModeratorUsers will return a list of users with moderator access.

func GetUserByID added in v0.0.9

func GetUserByID(id string) *User

GetUserByID will return a user by a user ID.

func GetUserByToken

func GetUserByToken(token string) *User

GetUserByToken will return a user by an access token.

func (*User) IsEnabled

func (u *User) IsEnabled() bool

IsEnabled will return if this single user is enabled.

func (*User) IsModerator added in v0.0.11

func (u *User) IsModerator() bool

IsModerator will return if the user has moderation privileges.

Jump to

Keyboard shortcuts

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