chat

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCommand = errors.New("invalid command")

ErrInvalidCommand is the error returned when an invalid command is issued.

View Source
var ErrInvalidName = errors.New("invalid name")

ErrInvalidName is the error returned when a user attempts to join with an invalid name, such as empty string.

View Source
var ErrMissingArg = errors.New("missing argument")

ErrMissingArg is the error returned when a command is performed without the necessary number of arguments.

View Source
var ErrMissingPrefix = errors.New("command missing prefix")

ErrMissingPrefix is the error returned when a command is added without a prefix.

View Source
var ErrNoOwner = errors.New("command without owner")

ErrNoOwner is the error returned when a command is given without an owner.

View Source
var ErrRoomClosed = errors.New("room closed")

ErrRoomClosed is the error returned when a message is sent to a room that is already closed.

Functions

func InitCommands

func InitCommands(c *Commands)

InitCommands injects default commands into a Commands registry.

func NewCommandsHelp

func NewCommandsHelp(c []*Command) fmt.Stringer

NewCommandsHelp creates a help container from a commands container.

func SetLogger

func SetLogger(w io.Writer)

SetLogger changes the logger used for logging inside the package

Types

type Command

type Command struct {
	Prefix     string // The command's key, such as /foo
	PrefixHelp string // Extra help regarding arguments
	Help       string // help text, if omitted, command is hidden from /help
	Op         bool   // does the command require Op permissions?

	// Handler for the command
	Handler func(*Room, message.CommandMsg) error
}

Command is a definition of a handler for a command.

type Commands

type Commands map[string]*Command

Commands is a registry of available commands.

func (Commands) Add

func (c Commands) Add(cmd Command) error

Add will register a command. If help string is empty, it will be hidden from Help().

func (Commands) Alias

func (c Commands) Alias(command string, alias string) error

Alias will add another command for the same handler, won't get added to help.

func (Commands) Help

func (c Commands) Help(showOp bool) string

Help will return collated help text as one string.

func (Commands) Run

func (c Commands) Run(room *Room, msg message.CommandMsg) error

Run executes a command message.

type Member

type Member struct {
	*message.User
	IsOp bool
}

Member is a User with per-Room metadata attached to it.

type Room

type Room struct {
	Members *set.Set
	// contains filtered or unexported fields
}

Room definition, also a Set of User Items

func NewRoom

func NewRoom() *Room

NewRoom creates a new room.

func (*Room) Close

func (r *Room) Close()

Close the room and all the users it contains.

func (*Room) HandleMsg

func (r *Room) HandleMsg(m message.Message)

HandleMsg reacts to a message, will block until done.

func (*Room) History

func (r *Room) History(u *message.User)

History feeds the room's recent message history to the user's handler.

func (*Room) IsOp

func (r *Room) IsOp(u *message.User) bool

IsOp returns whether a user is an operator in this room.

func (*Room) Join

func (r *Room) Join(u *message.User) (*Member, error)

Join the room as a user, will announce.

func (*Room) Leave

func (r *Room) Leave(u *message.User) error

Leave the room as a user, will announce. Mostly used during setup.

func (*Room) Member

func (r *Room) Member(u *message.User) (*Member, bool)

Member returns a corresponding Member object to a User if the Member is present in this room.

func (*Room) MemberByID

func (r *Room) MemberByID(id string) (*Member, bool)

MemberByID Gets a member by an id / name

func (*Room) NamesPrefix

func (r *Room) NamesPrefix(prefix string) []string

NamesPrefix lists all members' names with a given prefix, used to query for autocompletion purposes. Sorted by which user was last active.

func (*Room) Rename

func (r *Room) Rename(oldID string, u message.Identifier) error

Rename member with a new identity. This will not call rename on the member.

func (*Room) Send

func (r *Room) Send(m message.Message)

Send message, buffered by a chan.

func (*Room) Serve

func (r *Room) Serve()

Serve will consume the broadcast room and handle the messages, should be run in a goroutine.

func (*Room) SetCommands

func (r *Room) SetCommands(commands Commands)

SetCommands sets the room's command handlers.

func (*Room) SetLogging

func (r *Room) SetLogging(out io.Writer)

SetLogging sets logging output for the room's history

func (*Room) SetTopic

func (r *Room) SetTopic(s string)

SetTopic will set the topic of the room.

func (*Room) Topic

func (r *Room) Topic() string

Topic of the room.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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