Added support for querying of Channel Modes
This commit is contained in:
parent
72875efb89
commit
19635143fe
81
commands.go
81
commands.go
@ -530,6 +530,7 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
needsArgs = needsArgs[1:]
|
needsArgs = needsArgs[1:]
|
||||||
argsCount++
|
argsCount++
|
||||||
if argsCount > 3 { //Only allow 3 argument based flags per mode command
|
if argsCount > 3 { //Only allow 3 argument based flags per mode command
|
||||||
|
needsArgs = []fullFlag{}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
mode.Param = param
|
mode.Param = param
|
||||||
@ -584,6 +585,7 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
_, ok := masks[mask]
|
_, ok := masks[mask]
|
||||||
if !ok {
|
if !ok {
|
||||||
channel.AddBanMask(mask)
|
channel.AddBanMask(mask)
|
||||||
|
mode.Param = mask
|
||||||
changes = append(changes, mode)
|
changes = append(changes, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,6 +594,7 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
_, ok := masks[mask]
|
_, ok := masks[mask]
|
||||||
if !ok {
|
if !ok {
|
||||||
channel.AddExceptionMask(mask)
|
channel.AddExceptionMask(mask)
|
||||||
|
mode.Param = mask
|
||||||
changes = append(changes, mode)
|
changes = append(changes, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,6 +603,7 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
_, ok := masks[mask]
|
_, ok := masks[mask]
|
||||||
if !ok {
|
if !ok {
|
||||||
channel.AddInvitationMask(mask)
|
channel.AddInvitationMask(mask)
|
||||||
|
mode.Param = mask
|
||||||
changes = append(changes, mode)
|
changes = append(changes, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,8 +617,10 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
switch mod { // Set if flag is adding a removing a mode
|
switch mod { // Set if flag is adding a removing a mode
|
||||||
case ModeModifierAdd:
|
case ModeModifierAdd:
|
||||||
modifier = ModeModifierAdd
|
modifier = ModeModifierAdd
|
||||||
|
continue
|
||||||
case ModeModifierRemove:
|
case ModeModifierRemove:
|
||||||
modifier = ModeModifierRemove
|
modifier = ModeModifierRemove
|
||||||
|
continue
|
||||||
|
|
||||||
}
|
}
|
||||||
flag := ChannelMode(char)
|
flag := ChannelMode(char)
|
||||||
@ -625,7 +631,23 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
if modifier == ModeModifierAdd {
|
if modifier == ModeModifierAdd {
|
||||||
needsArgs = append(needsArgs, fullFlag{modifier, flag, ""})
|
needsArgs = append(needsArgs, fullFlag{modifier, flag, ""})
|
||||||
}
|
}
|
||||||
default:
|
case ChannelModeAnonymous, ChannelModeInviteOnly, ChannelModeModerated, ChannelModeNoOutsideMessages,
|
||||||
|
ChannelModePrivate, ChannelModeSecret, ChannelModeQuiet, ChannelModeReOp, ChannelModeTopic:
|
||||||
|
|
||||||
|
if flag == ChannelModeAnonymous {
|
||||||
|
switch channel.Name[0] {
|
||||||
|
case '#', '+': // # and + channels can't be anonymous
|
||||||
|
m := irc.Message{Prefix: client.Server.Prefix, Command: irc.ERR_UNKNOWNMODE, Params: []string{client.Nickname, string(flag)}, Trailing: "is unknown mode char to me for " + channel.Name}
|
||||||
|
client.Encode(&m)
|
||||||
|
continue
|
||||||
|
case '!': // ! Channels can only have anonymous flag set, not unset
|
||||||
|
if modifier == ModeModifierRemove {
|
||||||
|
m := irc.Message{Prefix: client.Server.Prefix, Command: irc.ERR_UNKNOWNMODE, Params: []string{client.Nickname, string(flag)}, Trailing: "is unknown mode char to me for " + channel.Name}
|
||||||
|
client.Encode(&m)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
found := channel.HasMode(flag)
|
found := channel.HasMode(flag)
|
||||||
if modifier == ModeModifierAdd {
|
if modifier == ModeModifierAdd {
|
||||||
|
|
||||||
@ -648,12 +670,69 @@ func ChannelModeHandler(message *irc.Message, client *Client) {
|
|||||||
changes = append(changes, fullFlag{modifier, flag, ""})
|
changes = append(changes, fullFlag{modifier, flag, ""})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
m := irc.Message{Prefix: client.Server.Prefix, Command: irc.ERR_UNKNOWNMODE, Params: []string{client.Nickname, string(flag)}, Trailing: "is unknown mode char to me for " + channel.Name}
|
||||||
|
client.Encode(&m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(changes) == 0 { // No changes were made
|
||||||
|
|
||||||
|
if len(needsArgs) != 0 { // query instead of modification
|
||||||
|
arg := needsArgs[0] //just return information on just one flag
|
||||||
|
|
||||||
|
m := irc.Message{Prefix: client.Server.Prefix, Params: []string{client.Nickname}}
|
||||||
|
switch arg.ChannelMode {
|
||||||
|
case ChannelModeBan:
|
||||||
|
m.Command = irc.RPL_BANLIST
|
||||||
|
for mask := range channel.GetBanMasks() {
|
||||||
|
p := irc.ParsePrefix(mask)
|
||||||
|
fmt.Println("New BanMask: ", p.String())
|
||||||
|
m.Params = []string{client.Nickname, channel.Name, mask}
|
||||||
|
|
||||||
|
client.Encode(&m)
|
||||||
|
}
|
||||||
|
m.Params = []string{client.Nickname, channel.Name}
|
||||||
|
m.Trailing = "End of channel ban list"
|
||||||
|
m.Command = irc.RPL_ENDOFBANLIST
|
||||||
|
client.Encode(&m)
|
||||||
|
|
||||||
|
case ChannelModeExceptionMask:
|
||||||
|
m.Command = irc.RPL_EXCEPTLIST
|
||||||
|
|
||||||
|
for mask := range channel.GetExceptionMasks() {
|
||||||
|
m.Params = []string{client.Nickname, channel.Name, mask}
|
||||||
|
|
||||||
|
client.Encode(&m)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Params = []string{client.Nickname, channel.Name}
|
||||||
|
m.Trailing = "End of channel exception list"
|
||||||
|
m.Command = irc.RPL_ENDOFEXCEPTLIST
|
||||||
|
client.Encode(&m)
|
||||||
|
|
||||||
|
case ChannelModeInvitationMask:
|
||||||
|
m.Command = irc.RPL_INVITELIST
|
||||||
|
for mask := range channel.GetInvitationMasks() {
|
||||||
|
m.Params = []string{client.Nickname, channel.Name, mask}
|
||||||
|
|
||||||
|
client.Encode(&m)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Params = []string{client.Nickname, channel.Name}
|
||||||
|
m.Trailing = "End of channel invite list"
|
||||||
|
m.Command = irc.RPL_ENDOFINVITELIST
|
||||||
|
client.Encode(&m)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
changeString := ""
|
changeString := ""
|
||||||
paramsChanged := []string{}
|
paramsChanged := []string{}
|
||||||
previousMode := ModeModifier(' ')
|
previousMode := ModeModifier(' ')
|
||||||
|
25
modes.go
25
modes.go
@ -113,28 +113,6 @@ const (
|
|||||||
ChannelModeInvitationMask ChannelMode = 'I'
|
ChannelModeInvitationMask ChannelMode = 'I'
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChannelModes contains the supported channel modes
|
|
||||||
// Currently supported modes are just those in RFC 1459
|
|
||||||
var ChannelModes = map[ChannelMode]interface{}{
|
|
||||||
//ChannelModeCreator: nil,
|
|
||||||
ChannelModeOperator: nil,
|
|
||||||
ChannelModeVoice: nil,
|
|
||||||
//ChannelModeAnonymous: nil,
|
|
||||||
ChannelModeInviteOnly: nil,
|
|
||||||
ChannelModeModerated: nil,
|
|
||||||
ChannelModeNoOutsideMessages: nil,
|
|
||||||
//ChannelModeQuiet: nil,
|
|
||||||
ChannelModePrivate: nil,
|
|
||||||
ChannelModeSecret: nil,
|
|
||||||
//ChannelModeReOp: nil,
|
|
||||||
ChannelModeTopic: nil,
|
|
||||||
ChannelModeKey: nil,
|
|
||||||
ChannelModeLimit: nil,
|
|
||||||
ChannelModeBan: nil,
|
|
||||||
//ChannelModeExceptionMask: nil,
|
|
||||||
//ChannelModeInvitationMask: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChannelModeSet represents a set of active ChannelModes
|
// ChannelModeSet represents a set of active ChannelModes
|
||||||
type ChannelModeSet struct {
|
type ChannelModeSet struct {
|
||||||
modes map[ChannelMode]interface{}
|
modes map[ChannelMode]interface{}
|
||||||
@ -203,8 +181,11 @@ func (c *ChannelModeSet) String() string {
|
|||||||
params = append(params, param)
|
params = append(params, param)
|
||||||
}
|
}
|
||||||
for _, param := range params {
|
for _, param := range params {
|
||||||
|
if param != nil {
|
||||||
s += fmt.Sprintf(" %v", param)
|
s += fmt.Sprintf(" %v", param)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user