session

package
v21.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadData = errors.New("bad data")

ErrBadData is the error returned when upserting State elements if data is an incorrect type or invalid value

View Source
var ErrMissingData = errors.New("missing data")

ErrMissingData is the error returned when upserting State elements is missing required fields

View Source
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

func ChannelFromElement(e etfapi.Element) (Channel, error)

ChannelFromElement creates a new Channel object from the given etf Element. The element should be a Map-type Element

func ChannelFromElementMap

func ChannelFromElementMap(eMap map[string]etfapi.Element) (Channel, error)

ChannelFromElementMap creates a new Channel object from the given data map.

func (*Channel) ID

func (c *Channel) ID() snowflake.Snowflake

ID returns the channel's ID

func (*Channel) UpdateFromElementMap

func (c *Channel) UpdateFromElementMap(eMap map[string]etfapi.Element) error

UpdateFromElementMap updates information about the channel This will not remove known data, only replace it

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

func GuildFromElement(e etfapi.Element) (Guild, error)

GuildFromElement creates a new Guild object from the given Element

func GuildFromElementMap

func GuildFromElementMap(eMap map[string]etfapi.Element) (Guild, error)

GuildFromElementMap creates a new Guild object from the given data

func (*Guild) ChannelWithName

func (g *Guild) ChannelWithName(name string) (snowflake.Snowflake, bool)

ChannelWithName finds the channel id for the channel with the provided name

func (*Guild) HasRole

func (g *Guild) HasRole(uid, rid snowflake.Snowflake) bool

HasRole determines if the user with the provided ID has the role with the provided id

func (*Guild) ID

func (g *Guild) ID() snowflake.Snowflake

ID returns the guild ID

func (*Guild) IsAdmin

func (g *Guild) IsAdmin(uid snowflake.Snowflake) bool

IsAdmin determines if the user with the provided ID has administrator powers in the guild

func (*Guild) OwnsChannel

func (g *Guild) OwnsChannel(cid snowflake.Snowflake) bool

OwnsChannel determines if this guild owns a channel with the provided id

func (*Guild) RoleIsAdministrator

func (g *Guild) RoleIsAdministrator(rid snowflake.Snowflake) bool

RoleIsAdministrator determines if a role has admin powers in the guild

func (*Guild) RoleWithName

func (g *Guild) RoleWithName(name string) (snowflake.Snowflake, bool)

RoleWithName finds the role id for the role with the provided name

func (*Guild) UpdateFromElementMap

func (g *Guild) UpdateFromElementMap(eMap map[string]etfapi.Element) error

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]etfapi.Element) (GuildMember, error)

UpsertMemberFromElementMap upserts a GuildMemeber in the guild from the given data

func (*Guild) UpsertRoleFromElementMap

func (g *Guild) UpsertRoleFromElementMap(eMap map[string]etfapi.Element) (Role, error)

UpsertRoleFromElementMap upserts a Role 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

func RoleFromElement(e etfapi.Element) (Role, error)

RoleFromElement generates a new Role object from the given Element

func (*Role) IsAdmin

func (r *Role) IsAdmin() bool

IsAdmin determines if a role is a server admin

func (*Role) UpdateFromElementMap

func (r *Role) UpdateFromElementMap(eMap map[string]etfapi.Element) error

UpdateFromElementMap updates the data in a role from the given information

This will not remove data, only change and add data

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

func (s *Session) ChannelName(cid snowflake.Snowflake) (string, bool)

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

func (s *Session) Guild(gid snowflake.Snowflake) (Guild, bool)

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

func (s *Session) GuildIDs() []snowflake.Snowflake

GuildIDs finds all the currently stored guild ids in the session state

func (*Session) GuildOfChannel

func (s *Session) GuildOfChannel(cid snowflake.Snowflake) (snowflake.Snowflake, bool)

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

func (s *Session) ID() string

ID returns the session id of the current session (or an empty string if an id has not been set)

func (*Session) IsGuildAdmin

func (s *Session) IsGuildAdmin(gid, uid snowflake.Snowflake) bool

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

func (s *Session) UpdateFromReady(data map[string]etfapi.Element) error

UpdateFromReady updates data in the session state from a session ready message, and updates the session id

func (*Session) UpsertChannelFromElement

func (s *Session) UpsertChannelFromElement(e etfapi.Element) (snowflake.Snowflake, error)

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, error)

UpsertChannelFromElementMap updates data in the session state for a channel based on the given data

func (*Session) UpsertGuildFromElement

func (s *Session) UpsertGuildFromElement(e etfapi.Element) (snowflake.Snowflake, error)

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

func (*Session) UpsertGuildMemberFromElementMap

func (s *Session) UpsertGuildMemberFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, error)

UpsertGuildMemberFromElementMap updates data in the session state for a guild member based on the given data

func (*Session) UpsertGuildRoleFromElementMap

func (s *Session) UpsertGuildRoleFromElementMap(eMap map[string]etfapi.Element) (snowflake.Snowflake, error)

UpsertGuildRoleFromElementMap updates data in the session state for a guild role 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

func UserFromElement(e etfapi.Element) (User, error)

UserFromElement generates a new User object from the given Element

func (*User) UpdateFromElementMap

func (u *User) UpdateFromElementMap(eMap map[string]etfapi.Element) error

UpdateFromElementMap updates the information about a user from the given data

This will not remove information, only change and add information

Jump to

Keyboard shortcuts

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