diff --git a/irc/channel.go b/irc/channel.go index f9b16138..6c59a777 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -224,7 +224,7 @@ func (channel *Channel) Mode(client *Client, changes ChannelModeChanges) { switch change.op { case Add: if change.arg == "" { - // TODO err reply + client.ErrNeedMoreParams("MODE") continue } @@ -243,18 +243,18 @@ func (channel *Channel) Mode(client *Client, changes ChannelModeChanges) { } if change.arg == "" { - // TODO err reply + client.ErrNeedMoreParams("MODE") continue } target := channel.server.clients.Get(change.arg) if target == nil { - // TODO err reply + client.ErrNoSuchNick(change.arg) continue } - if channel.members[target] == nil { - // TODO err reply + if !channel.members.Has(target) { + client.ErrUserNotInChannel(channel, target) continue } @@ -267,6 +267,9 @@ func (channel *Channel) Mode(client *Client, changes ChannelModeChanges) { channel.members[target][change.mode] = false applied = append(applied, change) } + + default: + client.ErrUnknownMode(change.mode, channel) } } diff --git a/irc/reply.go b/irc/reply.go index d729aa61..90678ba7 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -10,18 +10,28 @@ func NewStringReply(source Identifier, code StringCode, format string, args ...interface{}) string { var header string if source == nil { - header = fmt.Sprintf("%s ", code) + header = code.String() + " " } else { header = fmt.Sprintf(":%s %s ", source, code) } - message := fmt.Sprintf(format, args...) + var message string + if len(args) > 0 { + message = fmt.Sprintf(format, args...) + } else { + message = format + } return header + message } func NewNumericReply(target *Client, code NumericCode, format string, args ...interface{}) string { header := fmt.Sprintf(":%s %s %s ", target.server.Id(), code, target.Nick()) - message := fmt.Sprintf(format, args...) + var message string + if len(args) > 0 { + message = fmt.Sprintf(format, args...) + } else { + message = format + } return header + message } @@ -406,3 +416,8 @@ func (target *Client) ErrErroneusNickname(nick string) { target.NumericReply(ERR_ERRONEUSNICKNAME, "%s :Erroneous nickname", nick) } + +func (target *Client) ErrUnknownMode(mode ChannelMode, channel *Channel) { + target.NumericReply(ERR_UNKNOWNMODE, + "%s :is unknown mode char to me for %s", mode, channel) +}