pkgo – github.com/starshine-sys/pkgo Index | Files

package pkgo

import "github.com/starshine-sys/pkgo"

Index

Constants

const (
	BirthdaySource       = "2006-01-02"
	BirthdayMMDD         = "01-02"
	BirthdayDDMM         = "02-01"
	BirthdayMonthName    = "January 2"
	BirthdayMonthNameRev = "2 January"
)

Birthday format constants

Variables

var (
	ErrNoToken          = errors.New("pkgo: no token in session, can't hit endpoints requiring authentication")
	ErrInvalidID        = errors.New("pkgo: not a 5-character ID")
	ErrInvalidSnowflake = errors.New("pkgo: not a valid Discord snowflake")
	ErrMsgNotFound      = errors.New("pkgo: message not found")
)

Errors

var ErrRateLimit = errors.New("pkgo: hit API rate limits")

ErrRateLimit is returned when the API rate limit is hit

Types

type Color

type Color string

Color holds the color for a member

func (Color) IsValid

func (c Color) IsValid() bool

IsValid returns true if the color is valid for PK

func (Color) ToInt

func (c Color) ToInt() int64

ToInt converts the color to an int64 value

type Config

type Config struct {
	Token  string
	NoRate bool
}

Config is the config struct, passed to (Session).NewToken()

type ErrStatusNot200

type ErrStatusNot200 struct {
	Code   int
	Status string
}

ErrStatusNot200 ...

func (*ErrStatusNot200) Error

func (e *ErrStatusNot200) Error() string

type Front

type Front struct {
	Timestamp time.Time `json:"timestamp,omitempty"`
	Members   []Member  `json:"members"`
}

Front holds the info for a full switch, as queried from /s/id/fronters

type Member

type Member struct {
	ID              string     `json:"id,omitempty"`
	Name            string     `json:"name,omitempty"`
	DisplayName     string     `json:"display_name,omitempty"`
	Description     string     `json:"description,omitempty"`
	Pronouns        string     `json:"pronouns,omitempty"`
	Color           Color      `json:"color,omitempty"`
	AvatarURL       string     `json:"avatar_url,omitempty"`
	Birthday        string     `json:"birthday,omitempty"`
	ProxyTags       []ProxyTag `json:"proxy_tags,omitempty"`
	KeepProxy       bool       `json:"keep_proxy,omitempty"`
	Created         time.Time  `json:"created"`
	Visibility      string     `json:"visibility,omitempty"`
	NamePrivacy     string     `json:"name_privacy,omitempty"`
	DescPrivacy     string     `json:"description_privacy,omitempty"`
	AvatarPrivacy   string     `json:"avatar_privacy,omitempty"`
	BirthdayPrivacy string     `json:"birthday_privacy,omitempty"`
	PronounPrivacy  string     `json:"pronoun_privacy,omitempty"`
	MetadataPrivacy string     `json:"metadata_privacy,omitempty"`
}

Member holds information for a specific system member

func (*Member) BirthdayString

func (m *Member) BirthdayString(format string) string

BirthdayString gives a member's birthday according to a format string

func (*Member) DisplayedName

func (m *Member) DisplayedName() string

DisplayedName returns the member's displayed name--either DisplayName if one is set, otherwise Name

func (*Member) Private

func (m *Member) Private(fields ...Privacy) *Member

Private will set the specified field(s) to private

func (*Member) Public

func (m *Member) Public(fields ...Privacy) *Member

Public will set the specified field(s) to public

func (*Member) SetDescription

func (m *Member) SetDescription(desc string) *Member

SetDescription sets the member's description, honouring limits

func (*Member) SetDisplayName

func (m *Member) SetDisplayName(n string) *Member

SetDisplayName sets the displayname, honouring limits

func (*Member) SetName

func (m *Member) SetName(n string) *Member

SetName sets the member's name, honouring limits

func (*Member) SetPronouns

func (m *Member) SetPronouns(p string) *Member

SetPronouns sets the member's pronouns, honouring limits

type Members

type Members []Member

Members holds multiple members, which can be sorted by creation date

func (Members) Len

func (m Members) Len() int

func (Members) Less

func (m Members) Less(i, j int) bool

func (Members) Swap

func (m Members) Swap(i, j int)

func (Members) ToMaps

func (m Members) ToMaps() (map[string]string, map[string]string)

ToMaps returns two maps, one of name-ID, one of ID-name. Note that the name-ID map may be incomplete if multiple members have the same name

type Message

type Message struct {
	Timestamp time.Time `json:"timestamp"`
	ID        string    `json:"id"`
	Original  string    `json:"original"`
	Sender    string    `json:"sender"`
	Channel   string    `json:"channel"`
	System    System    `json:"system"`
	Member    Member    `json:"member"`
}

Message is a proxied message

type Privacy

type Privacy int

Privacy is a privacy field

const (
	Visibility Privacy = iota
	NamePrivacy
	DescPrivacy
	AvatarPrivacy
	BirthdayPrivacy
	PronounPrivacy
	MetadataPrivacy
)

Privacy field constants

type ProxyTag

type ProxyTag struct {
	Prefix string `json:"prefix,omitempty"`
	Suffix string `json:"suffix,omitempty"`
}

ProxyTag is a single proxy tag for a member, in the format <prefix>text<suffix>

func (*ProxyTag) String

func (p *ProxyTag) String() string

String returns a <prefix>text<suffix> formatted version of the proxy tag

type Session

type Session struct {

	// NoRate disables client-side rate limiting
	NoRate bool
	// contains filtered or unexported fields
}

Session is the PluralKit API session, including a token

func NewSession

func NewSession(c *Config) *Session

NewSession returns a session

func (*Session) GetFronters

func (s *Session) GetFronters(id string) (f Front, err error)

GetFronters gets the current fronters for a system

func (*Session) GetMembers

func (s *Session) GetMembers(id string) (Members, error)

GetMembers gets all members of a system

func (*Session) GetMessage

func (s *Session) GetMessage(id string) (m *Message, err error)

GetMessage gets a message by Discord snowflake

func (*Session) GetSystem

func (s *Session) GetSystem() (sys *System, err error)

GetSystem gets the current token's system

func (*Session) GetSystemByID

func (s *Session) GetSystemByID(id string) (sys *System, err error)

GetSystemByID gets a system by its 5-character system ID

func (*Session) GetSystemByUserID

func (s *Session) GetSystemByUserID(id string) (sys *System, err error)

GetSystemByUserID gets a system by a Discord snowflake (user ID)

func (*Session) RateLimit

func (s *Session) RateLimit()

RateLimit blocks until we can be *sure* we won't hit the rate limit. Gets a lock on s.rate, waits 500ms, and unlocks it.

func (*Session) RegisterSwitch

func (s *Session) RegisterSwitch(ids ...string) (err error)

RegisterSwitch registers a switch with the given member IDs

func (*Session) UpdateMember

func (s *Session) UpdateMember(id string, member *Member) (*Member, error)

UpdateMember updates a member by ID

type Switch

type Switch struct {
	Timestamp time.Time `json:"timestamp,omitempty"`
	Members   []string  `json:"members"`
}

Switch holds the info for a simple switch, as queried from /s/id/switches

type System

type System struct {
	ID                  string    `json:"id"`
	Name                string    `json:"name,omitempty"`
	Description         string    `json:"description,omitempty"`
	Tag                 string    `json:"tag,omitempty"`
	AvatarURL           string    `json:"avatar_url,omitempty"`
	Timezone            string    `json:"tz,omitempty"`
	Created             time.Time `json:"created"`
	DescPrivacy         string    `json:"description_privacy,omitempty"`
	MemberListPrivacy   string    `json:"member_list_privacy,omitempty"`
	FrontPrivacy        string    `json:"front_privacy,omitempty"`
	FrontHistoryPrivacy string    `json:"front_history_privacy,omitempty"`
}

System holds all the data for a system

Source Files

api.go errors.go limits.go member.go member_api.go member_objects.go members.go message.go session.go switches.go system.go validators.go

Version
v0.3.1
Published
Apr 15, 2021
Platform
linux/amd64
Imports
11 packages
Last checked
now

Tools for package owners.