Documentation ¶
Index ¶
- Variables
- func InitCommands(c *Commands)
- func NewCommandsHelp(c []*Command) fmt.Stringer
- func SanitizeData(s string) string
- func SanitizeName(s string) string
- func SetLogger(w io.Writer)
- type Command
- type Commands
- type Member
- type Room
- func (r *Room) Close()
- func (r *Room) HandleMsg(m message.Message)
- func (r *Room) History(u *message.User)
- func (r *Room) IsMaster(u *message.User) bool
- func (r *Room) IsOp(u *message.User) bool
- func (r *Room) Join(u *message.User) (*Member, error)
- func (r *Room) Leave(u message.Identifier) error
- func (r *Room) Member(u *message.User) (*Member, bool)
- func (r *Room) MemberByID(id string) (*Member, bool)
- func (r *Room) NamesPrefix(prefix string) []string
- func (r *Room) Rename(oldID string, u message.Identifier) error
- func (r *Room) Send(m message.Message)
- func (r *Room) Serve()
- func (r *Room) SetCommands(commands Commands)
- func (r *Room) SetLogging(out io.Writer)
- func (r *Room) SetTopic(s string)
- func (r *Room) Topic() string
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCommand = errors.New("invalid command")
The error returned when an invalid command is issued.
var ErrInvalidName = errors.New("invalid name")
The error returned when a user attempts to join with an invalid name, such as empty string.
var ErrMissingArg = errors.New("missing argument")
The error returned when a command is performed without the necessary number of arguments.
var ErrMissingPrefix = errors.New("command missing prefix")
The error returned when a command is added without a prefix.
var ErrNoOwner = errors.New("command without owner")
The error returned when a command is given without an owner.
var ErrRoomClosed = errors.New("room closed")
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 ¶
NewCommandsHelp creates a help container from a commands container.
func SanitizeData ¶
SanitizeData returns a string with only allowed characters for client-provided metadata inputs.
func SanitizeName ¶
SanitizeName returns a name with only allowed characters and a reasonable length
Types ¶
type Command ¶
type Command struct { // The command's key, such as /foo Prefix string // Extra help regarding arguments PrefixHelp string // If omitted, command is hidden from /help Help string Handler func(*Room, message.CommandMsg) error // Command requires Op permissions Op bool // command requires Admin permissions Admin bool }
Command is a definition of a handler for a command.
type Commands ¶
Commands is a registry of available commands.
func (Commands) Add ¶
Add will register a command. If help string is empty, it will be hidden from Help().
func (Commands) Alias ¶
Alias will add another command for the same handler, won't get added to help.
type Room ¶
type Room struct { Members *set.Set Ops *set.Set Masters *set.Set // contains filtered or unexported fields }
Room definition, also a Set of User Items
func (*Room) Leave ¶
func (r *Room) Leave(u message.Identifier) error
Leave the room as a user, will announce. Mostly used during setup.
func (*Room) Member ¶
Member returns a corresponding Member object to a User if the Member is present in this room.
func (*Room) NamesPrefix ¶
NamesPrefix lists all members' names with a given prefix, used to query for autocompletion purposes.
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) Serve ¶
func (r *Room) Serve()
Serve will consume the broadcast room and handle the messages, should be run in a goroutine.
func (*Room) SetCommands ¶
SetCommands sets the room's command handlers.
func (*Room) SetLogging ¶
SetLogging sets logging output for the room's history