mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 21:39:25 +01:00
modes: Correct mode argument handling, only first param is the modestring
This commit is contained in:
parent
3cef5f2c9d
commit
4177522e74
100
irc/commands.go
100
irc/commands.go
@ -450,25 +450,29 @@ func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
|
||||
changes: make(ModeChanges, 0),
|
||||
}
|
||||
|
||||
for _, modeChange := range args {
|
||||
if len(modeChange) == 0 {
|
||||
// account for MODE command with no args to list things
|
||||
if len(args) < 1 {
|
||||
// don't do any further processing
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
modeArg := args[0]
|
||||
op := ModeOp(modeArg[0])
|
||||
if (op == Add) || (op == Remove) {
|
||||
modeArg = modeArg[1:]
|
||||
} else {
|
||||
return nil, ErrParseCommand
|
||||
}
|
||||
|
||||
for _, mode := range modeArg {
|
||||
if mode == '-' || mode == '+' {
|
||||
op = ModeOp(mode)
|
||||
continue
|
||||
}
|
||||
op := ModeOp(modeChange[0])
|
||||
if (op != Add) && (op != Remove) {
|
||||
return nil, ErrParseCommand
|
||||
}
|
||||
|
||||
for _, mode := range modeChange[1:] {
|
||||
if mode == '-' || mode == '+' {
|
||||
op = ModeOp(mode)
|
||||
continue
|
||||
}
|
||||
cmd.changes = append(cmd.changes, &ModeChange{
|
||||
mode: UserMode(mode),
|
||||
op: op,
|
||||
})
|
||||
}
|
||||
cmd.changes = append(cmd.changes, &ModeChange{
|
||||
mode: UserMode(mode),
|
||||
op: op,
|
||||
})
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
@ -531,42 +535,44 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
|
||||
changes: make(ChannelModeChanges, 0),
|
||||
}
|
||||
|
||||
for len(args) > 0 {
|
||||
if len(args[0]) == 0 {
|
||||
args = args[1:]
|
||||
// account for MODE command with no args to list things
|
||||
if len(args) < 1 {
|
||||
// don't do any further processing
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
modeArg := args[0]
|
||||
op := ModeOp(modeArg[0])
|
||||
if (op == Add) || (op == Remove) {
|
||||
modeArg = modeArg[1:]
|
||||
} else {
|
||||
return nil, ErrParseCommand
|
||||
}
|
||||
|
||||
currentArgIndex := 1
|
||||
|
||||
for _, mode := range modeArg {
|
||||
if mode == '-' || mode == '+' {
|
||||
op = ModeOp(mode)
|
||||
continue
|
||||
}
|
||||
|
||||
modeArg := args[0]
|
||||
op := ModeOp(modeArg[0])
|
||||
if (op == Add) || (op == Remove) {
|
||||
modeArg = modeArg[1:]
|
||||
} else {
|
||||
op = List
|
||||
change := &ChannelModeChange{
|
||||
mode: ChannelMode(mode),
|
||||
op: op,
|
||||
}
|
||||
|
||||
skipArgs := 1
|
||||
for _, mode := range modeArg {
|
||||
if mode == '-' || mode == '+' {
|
||||
op = ModeOp(mode)
|
||||
switch change.mode {
|
||||
// TODO(dan): separate this into the type A/B/C/D args and use those lists here
|
||||
case Key, BanMask, ExceptMask, InviteMask, UserLimit,
|
||||
ChannelOperator, ChannelFounder, ChannelAdmin, Halfop, Voice:
|
||||
if len(args) > currentArgIndex {
|
||||
change.arg = args[currentArgIndex]
|
||||
currentArgIndex++
|
||||
} else {
|
||||
// silently skip this mode
|
||||
continue
|
||||
}
|
||||
change := &ChannelModeChange{
|
||||
mode: ChannelMode(mode),
|
||||
op: op,
|
||||
}
|
||||
switch change.mode {
|
||||
// TODO(dan): separate this into the type A/B/C/D args and use those lists here
|
||||
case Key, BanMask, ExceptMask, InviteMask, UserLimit,
|
||||
ChannelOperator, ChannelFounder, ChannelAdmin, Halfop, Voice:
|
||||
if len(args) > skipArgs {
|
||||
change.arg = args[skipArgs]
|
||||
skipArgs += 1
|
||||
}
|
||||
}
|
||||
cmd.changes = append(cmd.changes, change)
|
||||
}
|
||||
args = args[skipArgs:]
|
||||
cmd.changes = append(cmd.changes, change)
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
|
Loading…
Reference in New Issue
Block a user