mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-26 22:09:24 +01:00
mode: Parse more advanced mode changes
This commit is contained in:
parent
63f5f34f28
commit
9b32d7d6b8
@ -428,12 +428,11 @@ func (changes ModeChanges) String() string {
|
|||||||
op := changes[0].op
|
op := changes[0].op
|
||||||
str := changes[0].op.String()
|
str := changes[0].op.String()
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
if change.op == op {
|
if change.op != op {
|
||||||
str += change.mode.String()
|
|
||||||
} else {
|
|
||||||
op = change.op
|
op = change.op
|
||||||
str += " " + change.op.String()
|
str += change.op.String()
|
||||||
}
|
}
|
||||||
|
str += change.mode.String()
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
@ -444,7 +443,7 @@ type ModeCommand struct {
|
|||||||
changes ModeChanges
|
changes ModeChanges
|
||||||
}
|
}
|
||||||
|
|
||||||
// MODE <nickname> *( ( "+" / "-" ) *( "i" / "w" / "o" / "O" / "r" ) )
|
// MODE <nickname> ( "+" / "-" )? *( "+" / "-" / <mode character> )
|
||||||
func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
|
func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
|
||||||
cmd := &ModeCommand{
|
cmd := &ModeCommand{
|
||||||
nickname: nickname,
|
nickname: nickname,
|
||||||
@ -461,6 +460,10 @@ func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, mode := range modeChange[1:] {
|
for _, mode := range modeChange[1:] {
|
||||||
|
if mode == '-' || mode == '+' {
|
||||||
|
op = ModeOp(mode)
|
||||||
|
continue
|
||||||
|
}
|
||||||
cmd.changes = append(cmd.changes, &ModeChange{
|
cmd.changes = append(cmd.changes, &ModeChange{
|
||||||
mode: UserMode(mode),
|
mode: UserMode(mode),
|
||||||
op: op,
|
op: op,
|
||||||
@ -490,25 +493,29 @@ func (change *ChannelModeChange) String() (str string) {
|
|||||||
|
|
||||||
type ChannelModeChanges []*ChannelModeChange
|
type ChannelModeChanges []*ChannelModeChange
|
||||||
|
|
||||||
func (changes ChannelModeChanges) String() (str string) {
|
func (changes ChannelModeChanges) String() string {
|
||||||
if len(changes) == 0 {
|
if len(changes) == 0 {
|
||||||
return
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
str = "+"
|
op := changes[0].op
|
||||||
if changes[0].op == Remove {
|
str := changes[0].op.String()
|
||||||
str = "-"
|
|
||||||
}
|
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
|
if change.op != op {
|
||||||
|
op = change.op
|
||||||
|
str += change.op.String()
|
||||||
|
}
|
||||||
str += change.mode.String()
|
str += change.mode.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
if change.arg == "" {
|
if change.arg == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
str += " " + change.arg
|
str += " " + change.arg
|
||||||
}
|
}
|
||||||
return
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelModeCommand struct {
|
type ChannelModeCommand struct {
|
||||||
@ -517,7 +524,7 @@ type ChannelModeCommand struct {
|
|||||||
changes ChannelModeChanges
|
changes ChannelModeChanges
|
||||||
}
|
}
|
||||||
|
|
||||||
// MODE <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
|
// MODE <channel> ( "+" / "-" )? *( "+" / "-" / <mode character> ) *<modeparams>
|
||||||
func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
|
func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
|
||||||
cmd := &ChannelModeCommand{
|
cmd := &ChannelModeCommand{
|
||||||
channel: channel,
|
channel: channel,
|
||||||
@ -540,6 +547,10 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
|
|||||||
|
|
||||||
skipArgs := 1
|
skipArgs := 1
|
||||||
for _, mode := range modeArg {
|
for _, mode := range modeArg {
|
||||||
|
if mode == '-' || mode == '+' {
|
||||||
|
op = ModeOp(mode)
|
||||||
|
continue
|
||||||
|
}
|
||||||
change := &ChannelModeChange{
|
change := &ChannelModeChange{
|
||||||
mode: ChannelMode(mode),
|
mode: ChannelMode(mode),
|
||||||
op: op,
|
op: op,
|
||||||
|
Loading…
Reference in New Issue
Block a user