3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

add error responses for mode command

This commit is contained in:
Jeremy Latt 2014-02-22 12:15:34 -08:00
parent 1283bd35c7
commit 21337cda7f
2 changed files with 26 additions and 8 deletions

View File

@ -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)
}
}

View File

@ -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)
}