3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-13 07:29:30 +01:00

Some user/channel modes.

This commit is contained in:
Jeremy Latt 2012-12-09 21:46:22 -08:00
parent 41e79e3b09
commit 78e741af3b
2 changed files with 53 additions and 6 deletions

View File

@ -1,13 +1,31 @@
package irc
type Channel struct {
name string
key string
topic string
members ClientSet
server *Server
name string
key string
topic string
members ClientSet
operators ClientSet
creators ClientSet
voiced ClientSet
invites map[string]bool
// modes
anonymous bool
inviteOnly bool
invites map[string]bool
server *Server
moderated bool
noOutside bool
quiet bool
private bool
secret bool
serverReop bool
operTopic bool
// modes with args
password string
userLimit int
banMask string
banExceptMask string
inviteMask string
}
type ChannelSet map[*Channel]bool
@ -43,6 +61,10 @@ func (ch *Channel) Nicks() []string {
return nicks
}
func (ch *Channel) IsEmpty() bool {
return len(ch.members) == 0
}
//
// channel functionality
//

View File

@ -165,16 +165,41 @@ type ModeMessage struct {
modes []string
}
type ChannelModeMessage struct {
*ModeMessage
channel string
modeParams []string
}
// mode s is accepted but ignored, like some other modes
var MODE_RE = regexp.MustCompile("^[-+][iwroOs]+$")
var CHANNEL_RE = regexp.MustCompile("^[+\\&\\!#][:alnum:]+$")
var EXTRACT_MODE_RE = regexp.MustCompile("^([-+])?([aimnqpsrtklbeI]+)$")
func NewModeMessage(args []string) (Message, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
msg := &ModeMessage{
nickname: args[0],
}
if (len(args) > 1) && CHANNEL_RE.MatchString(args[1]) {
cmsg := &ChannelModeMessage{msg}
if len(args) > 2 {
groups := EXTRACT_MODE_RE.FindStringSubmatch(args[2])
cmsg.modes = make([]string, len(groups[2]))
i := 0
for _, char := range groups[2] {
cmsg.modes[i] = fmt.Sprintf("%s%c", groups[1], char)
i++
}
}
if len(args > 3) {
cmsg.modeParams = strings.Split(args[3], ",")
}
return cmsg
}
for _, arg := range args[1:] {
if !MODE_RE.MatchString(arg) {
return nil, ErrUModeUnknownFlag