Documentation
¶
Index ¶
- Constants
- Variables
- func MapAndIDFromElement(e Element) (eMap map[string]Element, id snowflake.Snowflake, err error)
- func SnowflakeFromElement(e Element) (s snowflake.Snowflake, err error)
- type Channel
- type ChannelType
- type ETFCode
- type Element
- func ElementMapToElementSlice(m map[string]Element) ([]Element, error)
- func NewAtomElement(val string) (e Element, err error)
- func NewBinaryElement(val []byte) (e Element, err error)
- func NewBoolElement(val bool) (e Element, err error)
- func NewElement(code ETFCode, val interface{}) (e Element, err error)
- func NewInt32Element(val int) (e Element, err error)
- func NewInt8Element(val int) (e Element, err error)
- func NewListElement(val []Element) (e Element, err error)
- func NewMapElement(val map[string]Element) (e Element, err error)
- func NewNilElement() (e Element, err error)
- func NewSmallBigElement(val int64) (e Element, err error)
- func NewStringElement(val string) (e Element, err error)
- func (e *Element) IsCollection() bool
- func (e *Element) IsFalse() bool
- func (e *Element) IsList() bool
- func (e *Element) IsNil() bool
- func (e *Element) IsNumeric() bool
- func (e *Element) IsStringish() bool
- func (e *Element) IsTrue() bool
- func (e *Element) PrettyString(indent string, skipFirstIndent bool) string
- func (e Element) String() string
- func (e *Element) ToBytes() ([]byte, error)
- func (e *Element) ToInt() (int, error)
- func (e *Element) ToInt64() (int64, error)
- func (e *Element) ToList() ([]Element, error)
- func (e *Element) ToMap() (map[string]Element, error)
- func (e *Element) ToString() (string, error)
- func (e *Element) WriteTo(b io.Writer) (int64, error)
- type Guild
- func (g *Guild) ChannelWithName(name string) (snowflake.Snowflake, bool)
- func (g *Guild) ID() snowflake.Snowflake
- func (g *Guild) IsAdmin(uid snowflake.Snowflake) bool
- func (g *Guild) OwnsChannel(cid snowflake.Snowflake) bool
- func (g *Guild) UpdateFromElementMap(eMap map[string]Element) (err error)
- func (g *Guild) UpsertMemberFromElementMap(eMap map[string]Element) (m GuildMember, err error)
- func (g *Guild) UpsertRoleFromElementMap(eMap map[string]Element) (r Role, err error)
- type GuildMember
- type Message
- type MessageType
- type Payload
- type Role
- type Session
- func (s *Session) ChannelName(cid snowflake.Snowflake) (string, bool)
- func (s *Session) Guild(gid snowflake.Snowflake) (Guild, bool)
- func (s *Session) GuildOfChannel(cid snowflake.Snowflake) (snowflake.Snowflake, bool)
- func (s *Session) ID() string
- func (s *Session) IsGuildAdmin(gid snowflake.Snowflake, uid snowflake.Snowflake) bool
- func (s *Session) UpdateFromReady(p *Payload) (err error)
- func (s *Session) UpsertChannelFromElement(e Element) (err error)
- func (s *Session) UpsertChannelFromElementMap(eMap map[string]Element) (err error)
- func (s *Session) UpsertGuildFromElement(e Element) (err error)
- func (s *Session) UpsertGuildFromElementMap(eMap map[string]Element) (err error)
- func (s *Session) UpsertGuildMemberFromElementMap(eMap map[string]Element) (err error)
- func (s *Session) UpsertGuildRoleFromElementMap(eMap map[string]Element) (err error)
- type User
Constants ¶
const ( GuildTextChannel ChannelType = 0 DMChannel = 1 GuildVoiceChannel = 2 GroupDMChannel = 3 GuildCategoryChannel = 4 )
These are the known discord channel types
const ( Map ETFCode = 116 Atom = 100 List = 108 Binary = 109 Int8 = 97 Int32 = 98 Float = 70 String = 107 EmptyList = 106 SmallBig = 110 LargeBig = 111 )
These are the ETF type codes that this library knows about
const ( DefaultMessage MessageType = 0 RecipientAddMessage = 1 RecipientRemoveMessage = 2 CallMessage = 3 ChannelNameChangeMessage = 4 ChannelIconChangeMessage = 5 ChannelPinnedMessageMessage = 6 GuildMemberJoinMessage = 7 )
These are the known message types
Variables ¶
var ErrBadData = errors.New("bad data")
ErrBadData is the error returned when upserting State elements if data is an incorrect type or invalid value
var ErrBadElementData = errors.New("bad element data")
ErrBadElementData is the error returned when attempting to create a new element but the data provided does not match the ETFCode
var ErrBadFieldType = errors.New("bad field type")
ErrBadFieldType is the error returned when attempting to unmarshal an etf payload and a field is an incorrect type (like non-string-like map keys)
var ErrBadMarshalData = errors.New("bad marshal data")
ErrBadMarshalData is the error returned when attempting to marshal an etf payload to []byte and the data in an Element doesn't match the ETFCode
var ErrBadParity = errors.New("non-even list parity")
ErrBadParity is the error returned when a list that should be even parity is not (usually when trying to deal with Map Elements)
var ErrBadPayload = errors.New("bad payload format")
ErrBadPayload is the error returned when attempting to unmarshal an etf payload fails due to bad formatting
var ErrBadTarget = errors.New("bad element unmarshal target")
ErrBadTarget is the error returned when trying to convert an Element to an incorrect type
var ErrMissingData = errors.New("missing data")
ErrMissingData is the error returned when upserting State elements is missing required fields
var ErrNotFound = errors.New("not found")
ErrNotFound is the error returned when upserting State elements and the element to update is not found
var ErrOutOfBounds = errors.New("int value out of bounds")
ErrOutOfBounds is the error returned when integer values are out of the bounds of the type code
Functions ¶
func MapAndIDFromElement ¶
MapAndIDFromElement converts a Map element into a string->Element map and attempts to extract an id Snowflake from the "id" field
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel represents known information about a discord channel
func ChannelFromElement ¶
ChannelFromElement creates a new Channel object from the given etf Element. The element should be a Map-type Element
func ChannelFromElementMap ¶
ChannelFromElementMap creates a new Channel object from the given data map.
type ChannelType ¶
type ChannelType int
ChannelType represents the type of a discord channel
func ChannelTypeFromElement ¶
func ChannelTypeFromElement(e Element) (t ChannelType, err error)
ChannelTypeFromElement extracts the channel type from a etf Element
func (ChannelType) String ¶
func (t ChannelType) String() string
type ETFCode ¶
type ETFCode int
ETFCode is a type alias for representing ETF type codes
func (ETFCode) IsCollection ¶
IsCollection determines if an ETFCode is a collection of other elements
func (ETFCode) IsStringish ¶
IsStringish determines if an ETFCode is string-like
type Element ¶
Element is a container for arbitrary etf-formatted data
func ElementMapToElementSlice ¶
ElementMapToElementSlice converts an string->Element map into a slice of Elements (kv pairs)
func NewAtomElement ¶
NewAtomElement generates a new Element representing an Atom value
func NewBinaryElement ¶
NewBinaryElement generates a new Element representing Binary data
func NewBoolElement ¶
NewBoolElement generates a new Element representing a boolean value
func NewElement ¶
NewElement generates a new Element to hold data.
If the code is a collection-type (determined by code.IsCollection), then val should be a []Elelemt. Otherwise, val should be a []byte
func NewInt32Element ¶
NewInt32Element generates a new Element representing a 32-bit unsigned integer value; Bounds checking will happen inside the function
func NewInt8Element ¶
NewInt8Element generates a new Element representing an 8-bit unsigned integer value; Bounds checking will happen inside the function.
func NewListElement ¶
NewListElement generates a new Element representing a List
NOTE: empty lists are likely not handled well
func NewMapElement ¶
NewMapElement generates a new Element representing a Map
Keys are encoded as Binary type elements
func NewNilElement ¶
NewNilElement generates a new Element representing "nil"
func NewSmallBigElement ¶
NewSmallBigElement generates a new Element representing a 64-bit unsigned integer value
func NewStringElement ¶
NewStringElement generates a new Element representing a String value
func (*Element) IsCollection ¶
IsCollection determines if an element is a collection (map or list)
func (*Element) IsStringish ¶
IsStringish determines if an element is string-like
func (*Element) PrettyString ¶
PrettyString generates a pretty, human-readable representation of an Element
type Guild ¶
type Guild struct {
// contains filtered or unexported fields
}
Guild represents the known data about a discord guild
func GuildFromElement ¶
GuildFromElement creates a new Guild object from the given Element
func GuildFromElementMap ¶
GuildFromElementMap creates a new Guild object from the given data
func (*Guild) ChannelWithName ¶
ChannelWithName finds the channel id for the channel with the provided name
func (*Guild) IsAdmin ¶
IsAdmin determines if the user with the provided ID has administrator powers in the guild
func (*Guild) OwnsChannel ¶
OwnsChannel determines if this guild owns a channel with the provided id
func (*Guild) UpdateFromElementMap ¶
UpdateFromElementMap updates information about the guild from the provided data
This will not delete data; it will only add and change data
func (*Guild) UpsertMemberFromElementMap ¶
func (g *Guild) UpsertMemberFromElementMap(eMap map[string]Element) (m GuildMember, err error)
UpsertMemberFromElementMap upserts a GuildMemeber in the guild from the given data
type GuildMember ¶
type GuildMember struct {
// contains filtered or unexported fields
}
GuildMember represents the information about a known guild membership
func GuildMemberFromElement ¶
func GuildMemberFromElement(e Element) (m GuildMember, err error)
GuildMemberFromElement generates a new GuildMember object from the given Element
func (*GuildMember) UpdateFromElementMap ¶
func (m *GuildMember) UpdateFromElementMap(eMap map[string]Element) (err error)
UpdateFromElementMap updates the information from the given data
This will not remove data; it will only add and change data
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message represents the data about a message in a discord channel
func MessageFromElement ¶
MessageFromElement generates a new Message object from the given Element
func MessageFromElementMap ¶
MessageFromElementMap generates a new Message object from the given data
func (*Message) ContentString ¶
ContentString returns the content of the message
func (*Message) MessageType ¶
func (m *Message) MessageType() MessageType
MessageType returns the MessageType of the message
type MessageType ¶
type MessageType int
MessageType represents the type of message received in a discord channel
func MessageTypeFromElement ¶
func MessageTypeFromElement(e Element) (t MessageType, err error)
MessageTypeFromElement generates a MessageType representation from the given message-type Element
func (MessageType) String ¶
func (t MessageType) String() string
type Payload ¶
type Payload struct { OpCode discordapi.OpCode SeqNum *int EventName string Data map[string]Element DataList []Element }
Payload represents the data in a etf api payload (both for sending and receiving)
func (*Payload) Marshal ¶
Marshal converts a payload into a properly formatted []byte that can be sent over a websocket connection
func (*Payload) PrettyString ¶
PrettyString generates a pretty, multi-line, human-readable representation of a Payload
type Role ¶
type Role struct {
// contains filtered or unexported fields
}
Role represents a discord guild role
func RoleFromElement ¶
RoleFromElement generates a new Role object from the given Element
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a discord bot's session with an api gateway
The primary purpose of this wrapper is to wrap and lock access to a State field for safe access from multiple goroutines
func NewSession ¶
func NewSession() *Session
NewSession creates a new session object in an unlocked state and with empty session id
func (*Session) ChannelName ¶
ChannelName returns the name of the channel with the provided id, if one is known
The second return value will be alse if not such channel was found
func (*Session) Guild ¶
Guild finds a guild with the given ID in the current session state, if it exists
The second return value will be false if no such guild was found
func (*Session) GuildOfChannel ¶
GuildOfChannel returns the id of the guild that owns the channel with the provided id, if one is known
The second return value will be false if no such guild was found
func (*Session) ID ¶
ID returns the session id of the current session (or an empty string if an id has not been set)
func (*Session) IsGuildAdmin ¶
IsGuildAdmin returns true if the user with the given uid has Admin powers in the guild with the given gid. If the guild is not found, this will return false
func (*Session) UpdateFromReady ¶
UpdateFromReady updates data in the session state from a session ready message, and updates the session id
func (*Session) UpsertChannelFromElement ¶
UpsertChannelFromElement updates data in the session state for a channel based on the given Element
func (*Session) UpsertChannelFromElementMap ¶
UpsertChannelFromElementMap updates data in the session state for a channel based on the given data
func (*Session) UpsertGuildFromElement ¶
UpsertGuildFromElement updates data in the session state for a guild based on the given Element
func (*Session) UpsertGuildFromElementMap ¶
UpsertGuildFromElementMap updates data in the session state for a guild based on the given data
func (*Session) UpsertGuildMemberFromElementMap ¶
UpsertGuildMemberFromElementMap updates data in the session state for a guild member based on the given data
type User ¶
type User struct {
// contains filtered or unexported fields
}
User represents the data about a discord user
func UserFromElement ¶
UserFromElement generates a new User object from the given Element