xirc: move ChannelStatus over

This commit is contained in:
Simon Ser 2022-05-29 17:28:25 +02:00
parent 4af7a1b8e5
commit 997fe723f0
3 changed files with 23 additions and 22 deletions

20
irc.go
View file

@ -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

View file

@ -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
}

View file

@ -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)
}
}