3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

modes: Correct mode argument handling, only first param is the modestring

This commit is contained in:
Daniel Oaks 2016-04-14 21:22:17 +10:00
parent 3cef5f2c9d
commit 4177522e74

View File

@ -450,16 +450,21 @@ func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
changes: make(ModeChanges, 0), changes: make(ModeChanges, 0),
} }
for _, modeChange := range args { // account for MODE command with no args to list things
if len(modeChange) == 0 { if len(args) < 1 {
continue // don't do any further processing
return cmd, nil
} }
op := ModeOp(modeChange[0])
if (op != Add) && (op != Remove) { modeArg := args[0]
op := ModeOp(modeArg[0])
if (op == Add) || (op == Remove) {
modeArg = modeArg[1:]
} else {
return nil, ErrParseCommand return nil, ErrParseCommand
} }
for _, mode := range modeChange[1:] { for _, mode := range modeArg {
if mode == '-' || mode == '+' { if mode == '-' || mode == '+' {
op = ModeOp(mode) op = ModeOp(mode)
continue continue
@ -469,7 +474,6 @@ func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
op: op, op: op,
}) })
} }
}
return cmd, nil return cmd, nil
} }
@ -531,10 +535,10 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
changes: make(ChannelModeChanges, 0), changes: make(ChannelModeChanges, 0),
} }
for len(args) > 0 { // account for MODE command with no args to list things
if len(args[0]) == 0 { if len(args) < 1 {
args = args[1:] // don't do any further processing
continue return cmd, nil
} }
modeArg := args[0] modeArg := args[0]
@ -542,10 +546,11 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
if (op == Add) || (op == Remove) { if (op == Add) || (op == Remove) {
modeArg = modeArg[1:] modeArg = modeArg[1:]
} else { } else {
op = List return nil, ErrParseCommand
} }
skipArgs := 1 currentArgIndex := 1
for _, mode := range modeArg { for _, mode := range modeArg {
if mode == '-' || mode == '+' { if mode == '-' || mode == '+' {
op = ModeOp(mode) op = ModeOp(mode)
@ -559,15 +564,16 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
// TODO(dan): separate this into the type A/B/C/D args and use those lists here // TODO(dan): separate this into the type A/B/C/D args and use those lists here
case Key, BanMask, ExceptMask, InviteMask, UserLimit, case Key, BanMask, ExceptMask, InviteMask, UserLimit,
ChannelOperator, ChannelFounder, ChannelAdmin, Halfop, Voice: ChannelOperator, ChannelFounder, ChannelAdmin, Halfop, Voice:
if len(args) > skipArgs { if len(args) > currentArgIndex {
change.arg = args[skipArgs] change.arg = args[currentArgIndex]
skipArgs += 1 currentArgIndex++
} else {
// silently skip this mode
continue
} }
} }
cmd.changes = append(cmd.changes, change) cmd.changes = append(cmd.changes, change)
} }
args = args[skipArgs:]
}
return cmd, nil return cmd, nil
} }