func (cp *ChanPrivs) Equals(other *ChanPrivs) bool {
	return reflect.DeepEqual(cp, other)
}
Test ChanPrivs equality.
package state
import (
	"github.com/fluffle/goirc/logging"
	"reflect"
	"strconv"
)
type Channel struct {
	Name, Topic string
	Modes       *ChanMode
	Nicks       map[string]*ChanPrivs
}
type channel struct {
	name, topic string
	modes       *ChanMode
	lookup      map[string]*nick
	nicks       map[*nick]*ChanPrivs
}
type ChanMode struct {
	Private, Secret, ProtectedTopic, NoExternalMsg, Moderated bool
	InviteOnly, OperOnly, SSLOnly bool
	Registered, AllSSL bool
	Key string
	Limit int
}
type ChanPrivs struct {
	Owner, Admin, Op, HalfOp, Voice bool
}
var StringToChanMode = map[string]string{}
var ChanModeToString = map[string]string{
	"Private":        "p",
	"Secret":         "s",
	"ProtectedTopic": "t",
	"NoExternalMsg":  "n",
	"Moderated":      "m",
	"InviteOnly":     "i",
	"OperOnly":       "O",
	"SSLOnly":        "z",
	"Registered":     "r",
	"AllSSL":         "Z",
	"Key":            "k",
	"Limit":          "l",
}
var StringToChanPriv = map[string]string{}
var ChanPrivToString = map[string]string{
	"Owner":  "q",
	"Admin":  "a",
	"Op":     "o",
	"HalfOp": "h",
	"Voice":  "v",
}
var ModeCharToChanPriv = map[byte]string{}
var ChanPrivToModeChar = map[string]byte{
	"Owner":  '~',
	"Admin":  '&',
	"Op":     '@',
	"HalfOp": '%',
	"Voice":  '+',
}
func init() {
	for k, v := range ChanModeToString {
		StringToChanMode[v] = k
	}
	for k, v := range ChanPrivToString {
		StringToChanPriv[v] = k
	}
	for k, v := range ChanPrivToModeChar {
		ModeCharToChanPriv[v] = k
	}
}
func newChannel(name string) *channel {
	return &channel{
		name:   name,
		modes:  new(ChanMode),
		nicks:  make(map[*nick]*ChanPrivs),
		lookup: make(map[string]*nick),
	}
}
func (ch *channel) Channel() *Channel {
	c := &Channel{
		Name:  ch.name,
		Topic: ch.topic,
		Modes: ch.modes.Copy(),
		Nicks: make(map[string]*ChanPrivs),
	}
	for n, cp := range ch.nicks {
		c.Nicks[n.nick] = cp.Copy()
	}
	return c
}
func (ch *channel) isOn(nk *nick) (*ChanPrivs, bool) {
	cp, ok := ch.nicks[nk]
	return cp.Copy(), ok
}
func (ch *channel) addNick(nk *nick, cp *ChanPrivs) {
	if _, ok := ch.nicks[nk]; !ok {
		ch.nicks[nk] = cp
		ch.lookup[nk.nick] = nk
	} else {
		logging.Warn("Channel.addNick(): %s already on %s.", nk.nick, ch.name)
	}
}
func (ch *channel) delNick(nk *nick) {
	if _, ok := ch.nicks[nk]; ok {
		delete(ch.nicks, nk)
		delete(ch.lookup, nk.nick)
	} else {
		logging.Warn("Channel.delNick(): %s not on %s.", nk.nick, ch.name)
	}
}
func (ch *channel) parseModes(modes string, modeargs ...string) {
	var modeop bool  
	var modestr string
	for i := 0; i < len(modes); i++ {
		switch m := modes[i]; m {
		case '+':
			modeop = true
			modestr = string(m)
		case '-':
			modeop = false
			modestr = string(m)
		case 'i':
			ch.modes.InviteOnly = modeop
		case 'm':
			ch.modes.Moderated = modeop
		case 'n':
			ch.modes.NoExternalMsg = modeop
		case 'p':
			ch.modes.Private = modeop
		case 'r':
			ch.modes.Registered = modeop
		case 's':
			ch.modes.Secret = modeop
		case 't':
			ch.modes.ProtectedTopic = modeop
		case 'z':
			ch.modes.SSLOnly = modeop
		case 'Z':
			ch.modes.AllSSL = modeop
		case 'O':
			ch.modes.OperOnly = modeop
		case 'k':
			if modeop && len(modeargs) != 0 {
				ch.modes.Key, modeargs = modeargs[0], modeargs[1:]
			} else if !modeop {
				ch.modes.Key = ""
			} else {
				logging.Warn("Channel.ParseModes(): not enough arguments to "+
					"process MODE %s %s%c", ch.name, modestr, m)
			}
		case 'l':
			if modeop && len(modeargs) != 0 {
				ch.modes.Limit, _ = strconv.Atoi(modeargs[0])
				modeargs = modeargs[1:]
			} else if !modeop {
				ch.modes.Limit = 0
			} else {
				logging.Warn("Channel.ParseModes(): not enough arguments to "+
					"process MODE %s %s%c", ch.name, modestr, m)
			}
		case 'q', 'a', 'o', 'h', 'v':
			if len(modeargs) != 0 {
				if nk, ok := ch.lookup[modeargs[0]]; ok {
					cp := ch.nicks[nk]
					switch m {
					case 'q':
						cp.Owner = modeop
					case 'a':
						cp.Admin = modeop
					case 'o':
						cp.Op = modeop
					case 'h':
						cp.HalfOp = modeop
					case 'v':
						cp.Voice = modeop
					}
					modeargs = modeargs[1:]
				} else {
					logging.Warn("Channel.ParseModes(): untracked nick %s "+
						"received MODE on channel %s", modeargs[0], ch.name)
				}
			} else {
				logging.Warn("Channel.ParseModes(): not enough arguments to "+
					"process MODE %s %s%c", ch.name, modestr, m)
			}
		default:
			logging.Info("Channel.ParseModes(): unknown mode char %c", m)
		}
	}
}
func (ch *Channel) IsOn(nk string) (*ChanPrivs, bool) {
	cp, ok := ch.Nicks[nk]
	return cp, ok
}
func (ch *Channel) Equals(other *Channel) bool {
	return reflect.DeepEqual(ch, other)
}
func (cm *ChanMode) Copy() *ChanMode {
	if cm == nil {
		return nil
	}
	c := *cm
	return &c
}
func (cm *ChanMode) Equals(other *ChanMode) bool {
	return reflect.DeepEqual(cm, other)
}
func (cp *ChanPrivs) Copy() *ChanPrivs {
	if cp == nil {
		return nil
	}
	c := *cp
	return &c
}