Documentation ¶
Overview ¶
Package session handles the discord session caching/maintenance
Index ¶
- Variables
- type Channel
- type ChannelType
- type Guild
- func (g *Guild) AllAdministratorRoleIDs() []snowflake.Snowflake
- 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]etfapi.Element) error
- func (g *Guild) UpsertMemberFromElementMap(eMap map[string]etfapi.Element) (GuildMember, error)
- func (g *Guild) UpsertRoleFromElementMap(eMap map[string]etfapi.Element) (Role, error)
- type GuildMember
- 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(data map[string]etfapi.Element) error
- func (s *Session) UpsertChannelFromElement(e etfapi.Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertChannelFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, snowflake.Snowflake, error)
- func (s *Session) UpsertGuildFromElement(e etfapi.Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildMemberFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, error)
- func (s *Session) UpsertGuildRoleFromElementMap(eMap map[string]etfapi.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 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
Functions ¶
This section is empty.
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 etfapi.Element) (ChannelType, error)
ChannelTypeFromElement extracts the channel type from a etf Element
func (ChannelType) String ¶
func (t ChannelType) String() string
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) AllAdministratorRoleIDs ¶
AllAdministratorRoleIDs gets the role ids of all roles known to be administrators of the guild
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 ¶
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 ¶
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 etfapi.Element) (GuildMember, error)
GuildMemberFromElement generates a new GuildMember object from the given Element
func (*GuildMember) UpdateFromElementMap ¶
func (m *GuildMember) UpdateFromElementMap(eMap map[string]etfapi.Element) error
UpdateFromElementMap updates the information from the given data
This will not remove data; it will only add and change data
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 ¶
func (s *Session) UpsertChannelFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, snowflake.Snowflake, error)
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 ¶
func (s *Session) UpsertGuildFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, error)
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