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 = "#&+!"
|
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 {
|
type membership struct {
|
||||||
Mode byte
|
Mode byte
|
||||||
Prefix byte
|
Prefix byte
|
||||||
|
@ -77,7 +77,7 @@ type upstreamChannel struct {
|
|||||||
Topic string
|
Topic string
|
||||||
TopicWho *irc.Prefix
|
TopicWho *irc.Prefix
|
||||||
TopicTime time.Time
|
TopicTime time.Time
|
||||||
Status channelStatus
|
Status xirc.ChannelStatus
|
||||||
modes channelModes
|
modes channelModes
|
||||||
creationTime string
|
creationTime string
|
||||||
Members membershipsCasemapMap
|
Members membershipsCasemapMap
|
||||||
@ -1353,7 +1353,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := parseChannelStatus(statusStr)
|
status, err := xirc.ParseChannelStatus(statusStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
21
xirc/xirc.go
21
xirc/xirc.go
@ -2,6 +2,7 @@
|
|||||||
package xirc
|
package xirc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -60,3 +61,23 @@ func ParseCTCPMessage(msg *irc.Message) (cmd string, params string, ok bool) {
|
|||||||
|
|
||||||
return cmd, params, true
|
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