xirc: move ChannelStatus over
This commit is contained in:
parent
4af7a1b8e5
commit
997fe723f0
20
irc.go
20
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
|
||||
|
@ -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
|
||||
}
|
||||
|
21
xirc/xirc.go
21
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user