From 4dfb7cc7ae3a5cbbbdc62edfde2d93a6f0697a87 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 3 Feb 2025 20:51:08 -0500 Subject: [PATCH] use slices.Contains in irc/modes --- irc/modes/modes.go | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/irc/modes/modes.go b/irc/modes/modes.go index ad160169..c9483bb4 100644 --- a/irc/modes/modes.go +++ b/irc/modes/modes.go @@ -7,6 +7,7 @@ package modes import ( "fmt" + "slices" "sort" "strings" @@ -219,19 +220,11 @@ func ParseUserModeChanges(params ...string) (ModeChanges, map[rune]bool) { } } - var isKnown bool - for _, supportedMode := range SupportedUserModes { - if rune(supportedMode) == mode { - isKnown = true - break - } - } - if !isKnown { + if slices.Contains(SupportedUserModes, Mode(mode)) { + changes = append(changes, change) + } else { unknown[mode] = true - continue } - - changes = append(changes, change) } } @@ -304,25 +297,11 @@ func ParseChannelModeChanges(params ...string) (ModeChanges, map[rune]bool) { } } - var isKnown bool - for _, supportedMode := range SupportedChannelModes { - if rune(supportedMode) == mode { - isKnown = true - break - } - } - for _, supportedMode := range ChannelUserModes { - if rune(supportedMode) == mode { - isKnown = true - break - } - } - if !isKnown { + if slices.Contains(SupportedChannelModes, Mode(mode)) || slices.Contains(ChannelUserModes, Mode(mode)) { + changes = append(changes, change) + } else { unknown[mode] = true - continue } - - changes = append(changes, change) } }