From 997fe723f07ca074b6c7af3bb4d0b881c8083b3f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 29 May 2022 17:28:25 +0200 Subject: [PATCH] xirc: move ChannelStatus over --- irc.go | 20 -------------------- upstream.go | 4 ++-- xirc/xirc.go | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/irc.go b/irc.go index 5322d65..9c51d52 100644 --- a/irc.go +++ b/irc.go @@ -185,26 +185,6 @@ func (cm channelModes) Format() (modeString string, parameters []string) { const stdChannelTypes = "#&+!" -type channelStatus byte - -const ( - channelPublic channelStatus = '=' - channelSecret channelStatus = '@' - channelPrivate channelStatus = '*' -) - -func parseChannelStatus(s string) (channelStatus, error) { - if len(s) > 1 { - return 0, fmt.Errorf("invalid channel status %q: more than one character", s) - } - switch cs := channelStatus(s[0]); cs { - case channelPublic, channelSecret, channelPrivate: - return cs, nil - default: - return 0, fmt.Errorf("invalid channel status %q: unknown status", s) - } -} - type membership struct { Mode byte Prefix byte diff --git a/upstream.go b/upstream.go index 767f245..bc597bf 100644 --- a/upstream.go +++ b/upstream.go @@ -77,7 +77,7 @@ type upstreamChannel struct { Topic string TopicWho *irc.Prefix TopicTime time.Time - Status channelStatus + Status xirc.ChannelStatus modes channelModes creationTime string Members membershipsCasemapMap @@ -1353,7 +1353,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err return nil } - status, err := parseChannelStatus(statusStr) + status, err := xirc.ParseChannelStatus(statusStr) if err != nil { return err } diff --git a/xirc/xirc.go b/xirc/xirc.go index 6271d9b..f58c571 100644 --- a/xirc/xirc.go +++ b/xirc/xirc.go @@ -2,6 +2,7 @@ package xirc import ( + "fmt" "strings" "time" @@ -60,3 +61,23 @@ func ParseCTCPMessage(msg *irc.Message) (cmd string, params string, ok bool) { return cmd, params, true } + +type ChannelStatus byte + +const ( + ChannelPublic ChannelStatus = '=' + ChannelSecret ChannelStatus = '@' + ChannelPrivate ChannelStatus = '*' +) + +func ParseChannelStatus(s string) (ChannelStatus, error) { + if len(s) > 1 { + return 0, fmt.Errorf("invalid channel status %q: more than one character", s) + } + switch cs := ChannelStatus(s[0]); cs { + case ChannelPublic, ChannelSecret, ChannelPrivate: + return cs, nil + default: + return 0, fmt.Errorf("invalid channel status %q: unknown status", s) + } +}