Documentation ¶
Index ¶
- Variables
- func MapAndIDFromElement(e Element) (map[string]Element, snowflake.Snowflake, error)
- func SnowflakeFromElement(e Element) (snowflake.Snowflake, error)
- type Channel
- type ChannelType
- type ETFCode
- type Element
- func ElementMapToElementSlice(m map[string]Element) ([]Element, error)
- func NewAtomElement(val []byte) (Element, error)
- func NewBasicElement(code ETFCode, val []byte) (Element, error)
- func NewBinaryElement(val []byte) (Element, error)
- func NewBoolElement(val bool) (Element, error)
- func NewCollectionElement(code ETFCode, val []Element) (Element, error)
- func NewInt32Element(val int) (Element, error)
- func NewInt8Element(val int) (Element, error)
- func NewListElement(val []Element) (Element, error)
- func NewMapElement(val map[string]Element) (Element, error)
- func NewNilElement() (Element, error)
- func NewSmallBigElement(val int64) (Element, error)
- func NewStringElement(val string) (Element, 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) Marshal() ([]byte, error)
- func (e *Element) MarshalTo(b io.Writer) error
- 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)
- type Guild
- func (g *Guild) ChannelWithName(name string) (snowflake.Snowflake, bool)
- func (g *Guild) HasRole(uid, rid 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) RoleIsAdministrator(rid snowflake.Snowflake) bool
- func (g *Guild) RoleWithName(name string) (snowflake.Snowflake, bool)
- func (g *Guild) UpdateFromElementMap(eMap map[string]Element) error
- func (g *Guild) UpsertMemberFromElementMap(eMap map[string]Element) (GuildMember, error)
- func (g *Guild) UpsertRoleFromElementMap(eMap map[string]Element) (Role, error)
- type GuildMember
- type Message
- type MessageType
- type Payload
- type Reaction
- 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) GuildIDs() []snowflake.Snowflake
- func (s *Session) GuildOfChannel(cid snowflake.Snowflake) (snowflake.Snowflake, bool)
- func (s *Session) ID() string
- func (s *Session) IsGuildAdmin(gid, uid snowflake.Snowflake) bool
- func (s *Session) UpdateFromReady(p *Payload) error
- func (s *Session) UpsertChannelFromElement(e Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertChannelFromElementMap(eMap map[string]Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildFromElement(e Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildFromElementMap(eMap map[string]Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildMemberFromElementMap(eMap map[string]Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildRoleFromElementMap(eMap map[string]Element) (snowflake.Snowflake, error)
- type User
Constants ¶
This section is empty.
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
const ( GuildTextChannel ChannelType = 0 DMChannel ChannelType = 1 GuildVoiceChannel ChannelType = 2 GroupDMChannel ChannelType = 3 GuildCategoryChannel ChannelType = 4 )
These are the known discord channel types
func ChannelTypeFromElement ¶
func ChannelTypeFromElement(e Element) (ChannelType, 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
const ( Map ETFCode = 116 Atom ETFCode = 100 List ETFCode = 108 Binary ETFCode = 109 Int8 ETFCode = 97 Int32 ETFCode = 98 Float ETFCode = 70 String ETFCode = 107 EmptyList ETFCode = 106 SmallBig ETFCode = 110 LargeBig ETFCode = 111 )
These are the ETF type codes that this library knows about
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 NewBasicElement ¶
NewBasicElement generates a new Element to hold data for non-collection types.
func NewBinaryElement ¶
NewBinaryElement generates a new Element representing Binary data
func NewBoolElement ¶
NewBoolElement generates a new Element representing a boolean value
func NewCollectionElement ¶
NewCollectionElement generates a new Element to hold data for collection types.
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) MarshalTo ¶
MarshalTo formats the data in the given element in etf binary format and writes it to the provided writer
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) HasRole ¶
HasRole determines if the user with the provided ID has the role with the provided id
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) RoleIsAdministrator ¶ added in v18.2.0
RoleIsAdministrator determines if a role has admin powers in the guild
func (*Guild) RoleWithName ¶
RoleWithName finds the role id for the role with the provided name
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) (GuildMember, 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) (GuildMember, error)
GuildMemberFromElement generates a new GuildMember object from the given Element
func (*GuildMember) UpdateFromElementMap ¶
func (m *GuildMember) UpdateFromElementMap(eMap map[string]Element) 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
const ( DefaultMessage MessageType = 0 RecipientAddMessage MessageType = 1 RecipientRemoveMessage MessageType = 2 CallMessage MessageType = 3 ChannelNameChangeMessage MessageType = 4 ChannelIconChangeMessage MessageType = 5 ChannelPinnedMessageMessage MessageType = 6 GuildMemberJoinMessage MessageType = 7 )
These are the known message types
func MessageTypeFromElement ¶
func MessageTypeFromElement(e Element) (MessageType, 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)
type Reaction ¶
type Reaction struct {
// contains filtered or unexported fields
}
Message represents the data about a message in a discord channel
func ReactionFromElement ¶
ReactionFromElement generates a new Reaction object from the given Element
func ReactionFromElementMap ¶
ReactionFromElementMap generates a new Reaction object from the given data
func (*Reaction) Emoji ¶
Emoji returns the emoji of the reaction ChannelID returns the ID of the channel the reaction was to
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) GuildIDs ¶ added in v18.0.7
GuildIDs finds all the currently stored guild ids in the session state
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
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