chat: Better comments

This commit is contained in:
UlisseMini 2019-01-25 12:18:57 -05:00 committed by Andrey Petrov
parent a1b891aae2
commit 40f6957e93
3 changed files with 16 additions and 16 deletions

View File

@ -13,30 +13,28 @@ import (
"github.com/shazow/ssh-chat/set" "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") 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") var ErrNoOwner = errors.New("command without owner")
// The error returned when a command is performed without the necessary number // ErrMissingArg is the error returned when a command is performed without the necessary
// of arguments. // number of arguments.
var ErrMissingArg = errors.New("missing argument") 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") var ErrMissingPrefix = errors.New("command missing prefix")
// Command is a definition of a handler for a command. // Command is a definition of a handler for a command.
type Command struct { type Command struct {
// The command's key, such as /foo Prefix string // The command's key, such as /foo
Prefix string PrefixHelp string // Extra help regarding arguments
// Extra help regarding arguments Help string // help text, if omitted, command is hidden from /help
PrefixHelp string Op bool // does the command require Op permissions?
// If omitted, command is hidden from /help
Help string // Handler for the command
Handler func(*Room, message.CommandMsg) error Handler func(*Room, message.CommandMsg) error
// Command requires Op permissions
Op bool
} }
// Commands is a registry of available commands. // Commands is a registry of available commands.

View File

@ -5,6 +5,7 @@ import stdlog "log"
var logger *stdlog.Logger var logger *stdlog.Logger
// SetLogger changes the logger used for logging inside the package
func SetLogger(w io.Writer) { func SetLogger(w io.Writer) {
flags := stdlog.Flags() flags := stdlog.Flags()
prefix := "[chat] " prefix := "[chat] "

View File

@ -14,12 +14,12 @@ import (
const historyLen = 20 const historyLen = 20
const roomBuffer = 10 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. // closed.
var ErrRoomClosed = errors.New("room closed") var ErrRoomClosed = errors.New("room closed")
// The error returned when a user attempts to join with an invalid name, such // ErrInvalidName is the error returned when a user attempts to join with an invalid name,
// as empty string. // such as empty string.
var ErrInvalidName = errors.New("invalid name") var ErrInvalidName = errors.New("invalid name")
// Member is a User with per-Room metadata attached to it. // 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 return m, true
} }
// MemberByID Gets a member by an id / name
func (r *Room) MemberByID(id string) (*Member, bool) { func (r *Room) MemberByID(id string) (*Member, bool) {
m, err := r.Members.Get(id) m, err := r.Members.Get(id)
if err != nil { if err != nil {