diff --git a/chat/command.go b/chat/command.go index e2dc3f9..66e4b98 100644 --- a/chat/command.go +++ b/chat/command.go @@ -13,30 +13,28 @@ import ( "github.com/shazow/ssh-chat/set" ) -// The error returned when an invalid command is issued. +// ErrInvalidCommand is the error returned when an invalid command is issued. var ErrInvalidCommand = errors.New("invalid command") -// The error returned when a command is given without an owner. +// ErrNoOwner is the error returned when a command is given without an owner. var ErrNoOwner = errors.New("command without owner") -// The error returned when a command is performed without the necessary number -// of arguments. +// ErrMissingArg is the error returned when a command is performed without the necessary +// number of arguments. var ErrMissingArg = errors.New("missing argument") -// The error returned when a command is added without a prefix. +// ErrMissingPrefix is the error returned when a command is added without a prefix. var ErrMissingPrefix = errors.New("command missing prefix") // Command is a definition of a handler for a 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 + 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 requires Op permissions - Op bool } // Commands is a registry of available commands. diff --git a/chat/logger.go b/chat/logger.go index 93b2761..477e1d3 100644 --- a/chat/logger.go +++ b/chat/logger.go @@ -5,6 +5,7 @@ import stdlog "log" var logger *stdlog.Logger +// SetLogger changes the logger used for logging inside the package func SetLogger(w io.Writer) { flags := stdlog.Flags() prefix := "[chat] " diff --git a/chat/room.go b/chat/room.go index 96a1a35..31dc393 100644 --- a/chat/room.go +++ b/chat/room.go @@ -14,12 +14,12 @@ import ( const historyLen = 20 const roomBuffer = 10 -// The error returned when a message is sent to a room that is already +// ErrRoomClosed is the error returned when a message is sent to a room that is already // closed. var ErrRoomClosed = errors.New("room closed") -// The error returned when a user attempts to join with an invalid name, such -// as empty string. +// ErrInvalidName is the error returned when a user attempts to join with an invalid name, +// such as empty string. var ErrInvalidName = errors.New("invalid name") // Member is a User with per-Room metadata attached to it. @@ -200,6 +200,7 @@ func (r *Room) Member(u *message.User) (*Member, bool) { return m, true } +// MemberByID Gets a member by an id / name func (r *Room) MemberByID(id string) (*Member, bool) { m, err := r.Members.Get(id) if err != nil {