mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 07:29:31 +01:00
Some user/channel modes.
This commit is contained in:
parent
41e79e3b09
commit
78e741af3b
@ -1,13 +1,31 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
|
server *Server
|
||||||
name string
|
name string
|
||||||
key string
|
key string
|
||||||
topic string
|
topic string
|
||||||
members ClientSet
|
members ClientSet
|
||||||
inviteOnly bool
|
operators ClientSet
|
||||||
|
creators ClientSet
|
||||||
|
voiced ClientSet
|
||||||
invites map[string]bool
|
invites map[string]bool
|
||||||
server *Server
|
// modes
|
||||||
|
anonymous bool
|
||||||
|
inviteOnly bool
|
||||||
|
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
|
type ChannelSet map[*Channel]bool
|
||||||
@ -43,6 +61,10 @@ func (ch *Channel) Nicks() []string {
|
|||||||
return nicks
|
return nicks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ch *Channel) IsEmpty() bool {
|
||||||
|
return len(ch.members) == 0
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// channel functionality
|
// channel functionality
|
||||||
//
|
//
|
||||||
|
@ -165,16 +165,41 @@ type ModeMessage struct {
|
|||||||
modes []string
|
modes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChannelModeMessage struct {
|
||||||
|
*ModeMessage
|
||||||
|
channel string
|
||||||
|
modeParams []string
|
||||||
|
}
|
||||||
|
|
||||||
// mode s is accepted but ignored, like some other modes
|
// mode s is accepted but ignored, like some other modes
|
||||||
var MODE_RE = regexp.MustCompile("^[-+][iwroOs]+$")
|
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) {
|
func NewModeMessage(args []string) (Message, error) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return nil, NotEnoughArgsError
|
return nil, NotEnoughArgsError
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &ModeMessage{
|
msg := &ModeMessage{
|
||||||
nickname: args[0],
|
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:] {
|
for _, arg := range args[1:] {
|
||||||
if !MODE_RE.MatchString(arg) {
|
if !MODE_RE.MatchString(arg) {
|
||||||
return nil, ErrUModeUnknownFlag
|
return nil, ErrUModeUnknownFlag
|
||||||
|
Loading…
Reference in New Issue
Block a user