gateway

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: MPL-2.0 Imports: 12 Imported by: 8

Documentation

Index

Constants

View Source
const Delimiter = ":"

Delimiter between main/sub gateway name in ID (i.e. discord:{CHANNELID})

Variables

View Source
var (
	AccessMax       = AccessLevel(math.MaxInt32)
	AccessOwner     = AccessLevel(1000)
	AccessAdmin     = AccessLevel(300)
	AccessOperator  = AccessLevel(200)
	AccessWhitelist = AccessLevel(100)
	AccessVoice     = AccessLevel(1)
	AccessDefault   = AccessLevel(0)
	AccessIgnore    = AccessLevel(-1)
	AccessKick      = AccessLevel(-100)
	AccessBan       = AccessLevel(-200)
	AccessBlacklist = AccessLevel(-300)
	AccessMin       = AccessLevel(math.MinInt32)

	ConStrings = []string{"max", "owner", "admin", "operator", "whitelist", "voice", "", "ignore", "kick", "ban", "blacklist", "min"}
	ConLevels  = []AccessLevel{AccessMax, AccessOwner, AccessAdmin, AccessOperator, AccessWhitelist, AccessVoice, AccessDefault, AccessIgnore, AccessKick, AccessBan, AccessBlacklist, AccessMin}
)

Access constants

View Source
var (
	ErrUnknownEvent   = errors.New("gw: Unknown event")
	ErrUnknownAccess  = errors.New("gw: Unknown access level")
	ErrNoChannel      = errors.New("gw: No channel")
	ErrNoUser         = errors.New("gw: No user")
	ErrNoPermission   = errors.New("gw: No permission")
	ErrNotImplemented = errors.New("gw: Not implemented")
)

Errors

View Source
var RelayEvents = []interface{}{
	&network.AsyncError{},
	&Clear{},
	&Connected{},
	&Disconnected{},
	&SystemMessage{},
	&Channel{},
	&Chat{},
	&PrivateChat{},
	&Say{},
	&Join{},
	&Leave{},
	&User{},
}

RelayEvents types

Functions

This section is empty.

Types

type AccessLevel

type AccessLevel int32

AccessLevel for user

func (AccessLevel) MarshalText added in v0.9.0

func (l AccessLevel) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler

func (AccessLevel) String added in v0.9.0

func (l AccessLevel) String() string

func (*AccessLevel) UnmarshalText added in v0.9.0

func (l *AccessLevel) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Channel

type Channel struct {
	ID   string
	Name string
}

Channel struct

type Chat

type Chat struct {
	User
	Content string
}

Chat event

type Clear added in v0.9.1

type Clear struct{}

Clear event

type Common added in v0.9.0

type Common struct {
	// contains filtered or unexported fields
}

Common gateway struct

func (*Common) Discriminator added in v0.9.0

func (c *Common) Discriminator() string

Discriminator tag

func (*Common) ID added in v0.9.0

func (c *Common) ID() string

ID returns the unique gateway identifier

func (*Common) SetID added in v0.9.0

func (c *Common) SetID(id string)

SetID set the unique gateway identifier

type Config added in v0.9.0

type Config struct {
	Commands TriggerConfig
}

Config common struct

func (*Config) FindTrigger added in v0.9.0

func (c *Config) FindTrigger(s string) *Trigger

FindTrigger checks if s starts with trigger, return Trigger{} if true

func (*Config) Responder added in v0.9.0

func (c *Config) Responder(gw Gateway, uid string, forcePrivate bool) Responder

Responder for trigger

func (*Config) Trigger added in v0.9.0

func (c *Config) Trigger() string

Trigger for commands

type ConfigUpdate added in v0.9.0

type ConfigUpdate struct{}

ConfigUpdate event

type Connected

type Connected struct{}

Connected event

type Disconnected

type Disconnected struct{}

Disconnected event

type Gateway

type Gateway interface {
	network.Emitter
	network.Listener
	ID() string
	SetID(id string)
	Discriminator() string
	Channel() *Channel
	ChannelUsers() []User
	User(uid string) (*User, error)
	Users() map[string]AccessLevel
	SetUserAccess(uid string, a AccessLevel) (*AccessLevel, error)
	Trigger() string
	Say(s string) error
	SayPrivate(uid string, s string) error
	Kick(uid string) error
	Ban(uid string) error
	Unban(uid string) error
	Ping(uid string) (time.Duration, error)
	Responder(gw Gateway, uid string, forcePrivate bool) Responder
	Run(ctx context.Context) error
	Relay(ev *network.Event, from Gateway) error
}

Gateway interface

type Join

type Join struct {
	User
}

Join event

type Leave

type Leave struct {
	User
}

Leave event

type PrivateChat

type PrivateChat struct {
	User
	Content string
}

PrivateChat event

type Responder added in v0.9.0

type Responder func(s string) error

Responder callback

type Say added in v0.9.0

type Say struct {
	Content string
}

Say event

type SystemMessage

type SystemMessage struct {
	Type    string
	Content string
}

SystemMessage event

type Trigger added in v0.9.0

type Trigger struct {
	User
	Cmd  string
	Raw  []string
	Arg  []string
	Resp Responder
}

Trigger event

func ExtractTrigger added in v0.10.0

func ExtractTrigger(s string) *Trigger

ExtractTrigger from s

func FindTrigger added in v0.9.0

func FindTrigger(t, s string) *Trigger

FindTrigger checks if s starts with trigger t, return Trigger{} if true

type TriggerConfig added in v0.9.0

type TriggerConfig struct {
	Trigger        string
	Access         AccessLevel
	RespondPrivate bool
}

TriggerConfig for commands

type User

type User struct {
	ID        string
	Name      string
	Access    AccessLevel
	AvatarURL string
}

User struct

func FindUser added in v0.9.0

func FindUser(gw Gateway, pat string) []*User

FindUser finds user(s) by pattern

func FindUserInChannel added in v0.9.0

func FindUserInChannel(gw Gateway, pat string) []*User

FindUserInChannel finds user(s) by pattern

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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