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

DRY mode apply code

ParseUserModeChanges and ParseChannelModeChanges already validate
that the modes are modifiable, so there's no need to repeat it here.
This commit is contained in:
Shivaram Lingamneni 2020-10-01 19:52:50 -04:00
parent b426ba628a
commit c279b2d14c
2 changed files with 16 additions and 16 deletions

View File

@ -33,8 +33,7 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool,
applied := make(modes.ModeChanges, 0)
for _, change := range changes {
switch change.Mode {
case modes.Bot, modes.Invisible, modes.WallOps, modes.UserRoleplaying, modes.Operator, modes.LocalOperator, modes.RegisteredOnly, modes.UserNoCTCP:
if change.Mode != modes.ServerNotice {
switch change.Op {
case modes.Add:
if (change.Mode == modes.Operator || change.Mode == modes.LocalOperator) && !(force && oper != nil) {
@ -73,8 +72,8 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool,
}
}
}
case modes.ServerNotice:
} else {
// server notices are weird
if !client.HasMode(modes.Operator) {
continue
}
@ -98,8 +97,6 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool,
applied = append(applied, change)
}
}
// can't do anything to TLS mode
}
if len(applied) != 0 {
@ -271,15 +268,6 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
applied = append(applied, change)
}
case modes.InviteOnly, modes.Moderated, modes.NoOutside, modes.OpOnlyTopic, modes.RegisteredOnly, modes.Secret, modes.ChanRoleplaying, modes.NoCTCP, modes.RegisteredOnlySpeak:
if change.Op == modes.List {
continue
}
if channel.flags.SetMode(change.Mode, change.Op == modes.Add) {
applied = append(applied, change)
}
case modes.ChannelFounder, modes.ChannelAdmin, modes.ChannelOperator, modes.Halfop, modes.Voice:
if change.Op == modes.List {
continue
@ -295,6 +283,16 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
if success {
applied = append(applied, change)
}
default:
// all channel modes with no args, e.g., InviteOnly, Secret
if change.Op == modes.List {
continue
}
if channel.flags.SetMode(change.Mode, change.Op == modes.Add) {
applied = append(applied, change)
}
}
}

View File

@ -430,8 +430,10 @@ func (a ByCodepoint) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByCodepoint) Less(i, j int) bool { return a[i] < a[j] }
func RplMyInfo() (param1, param2, param3 string) {
userModes := make(Modes, len(SupportedUserModes))
userModes := make(Modes, len(SupportedUserModes), len(SupportedUserModes)+1)
copy(userModes, SupportedUserModes)
// TLS is not in SupportedUserModes because it can't be modified
userModes = append(userModes, TLS)
sort.Sort(ByCodepoint(userModes))
channelModes := make(Modes, len(SupportedChannelModes)+len(ChannelUserModes))