mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 21:39:25 +01:00
minimal channel mode command
This commit is contained in:
parent
a0eed1d687
commit
d8951e1b48
@ -23,6 +23,17 @@ type ChannelCommand interface {
|
||||
HandleChannel(channel *Channel)
|
||||
}
|
||||
|
||||
func IsChannel(target string) bool {
|
||||
if target == "" {
|
||||
return false
|
||||
}
|
||||
switch target[0] {
|
||||
case '&', '#', '+', '!':
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// NewChannel creates a new channel from a `Server` and a `name`
|
||||
// string, which must be unique on the server.
|
||||
func NewChannel(s *Server, name string) *Channel {
|
||||
@ -106,6 +117,11 @@ func (channel *Channel) String() string {
|
||||
return channel.Id()
|
||||
}
|
||||
|
||||
// <mode> <mode params>
|
||||
func (channel *Channel) ModeString() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (channel *Channel) Join(client *Client) {
|
||||
channel.members[client] = true
|
||||
client.channels[channel] = true
|
||||
|
@ -348,11 +348,7 @@ func NewPrivMsgCommand(args []string) (EditableCommand, error) {
|
||||
}
|
||||
|
||||
func (m *PrivMsgCommand) TargetIsChannel() bool {
|
||||
switch m.target[0] {
|
||||
case '&', '#', '+', '!':
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return IsChannel(m.target)
|
||||
}
|
||||
|
||||
// TOPIC [newtopic]
|
||||
@ -428,11 +424,22 @@ func stringToRunes(str string) <-chan rune {
|
||||
return runes
|
||||
}
|
||||
|
||||
func NewModeCommand(args []string) (EditableCommand, error) {
|
||||
if len(args) == 0 {
|
||||
return nil, NotEnoughArgsError
|
||||
type ChannelModeCommand struct {
|
||||
BaseCommand
|
||||
channel string
|
||||
}
|
||||
|
||||
// MODE <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
|
||||
func NewChannelModeCommand(args []string) (EditableCommand, error) {
|
||||
cmd := &ChannelModeCommand{
|
||||
channel: args[0],
|
||||
}
|
||||
// TODO implement channel mode changes
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// MODE <nickname> *( ( "+" / "-" ) *( "i" / "w" / "o" / "O" / "r" ) )
|
||||
func NewUserModeCommand(args []string) (EditableCommand, error) {
|
||||
cmd := &ModeCommand{
|
||||
nickname: args[0],
|
||||
changes: make([]ModeChange,
|
||||
@ -460,12 +467,25 @@ func NewModeCommand(args []string) (EditableCommand, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func NewModeCommand(args []string) (EditableCommand, error) {
|
||||
if len(args) == 0 {
|
||||
return nil, NotEnoughArgsError
|
||||
}
|
||||
|
||||
if IsChannel(args[0]) {
|
||||
return NewChannelModeCommand(args)
|
||||
} else {
|
||||
return NewUserModeCommand(args)
|
||||
}
|
||||
}
|
||||
|
||||
type WhoisCommand struct {
|
||||
BaseCommand
|
||||
target string
|
||||
masks []string
|
||||
}
|
||||
|
||||
// [ <target> ] <mask> *( "," <mask> )
|
||||
func NewWhoisCommand(args []string) (EditableCommand, error) {
|
||||
if len(args) < 1 {
|
||||
return nil, NotEnoughArgsError
|
||||
|
14
irc/reply.go
14
irc/reply.go
@ -234,6 +234,11 @@ func RplEndOfWhois(server *Server) Reply {
|
||||
return NewNumericReply(server, RPL_ENDOFWHOIS, ":End of WHOIS list")
|
||||
}
|
||||
|
||||
func RplChannelModeIs(server *Server, channel *Channel) Reply {
|
||||
return NewNumericReply(server, RPL_CHANNELMODEIS, "%s %s",
|
||||
channel.name, channel.ModeString())
|
||||
}
|
||||
|
||||
// errors (also numeric)
|
||||
|
||||
func ErrAlreadyRegistered(source Identifier) Reply {
|
||||
@ -261,8 +266,8 @@ func ErrNeedMoreParams(source Identifier, command string) Reply {
|
||||
"%s :Not enough parameters", command)
|
||||
}
|
||||
|
||||
func ErrNoSuchChannel(source Identifier, channel string) Reply {
|
||||
return NewNumericReply(source, ERR_NOSUCHCHANNEL,
|
||||
func ErrNoSuchChannel(server *Server, channel string) Reply {
|
||||
return NewNumericReply(server, ERR_NOSUCHCHANNEL,
|
||||
"%s :No such channel", channel)
|
||||
}
|
||||
|
||||
@ -311,3 +316,8 @@ func ErrRestricted(server *Server) Reply {
|
||||
func ErrNoSuchServer(server *Server, target string) Reply {
|
||||
return NewNumericReply(server, ERR_NOSUCHSERVER, "%s :No such server", target)
|
||||
}
|
||||
|
||||
func ErrUserNotInChannel(server *Server, nick string, channel *Channel) Reply {
|
||||
return NewNumericReply(server, ERR_USERNOTINCHANNEL,
|
||||
"%s %s :They aren't on that channel", nick, channel.name)
|
||||
}
|
||||
|
@ -299,3 +299,14 @@ func (m *WhoisCommand) HandleServer(server *Server) {
|
||||
}
|
||||
client.replies <- RplEndOfWhois(server)
|
||||
}
|
||||
|
||||
func (msg *ChannelModeCommand) HandleServer(server *Server) {
|
||||
client := msg.Client()
|
||||
channel := server.channels[msg.channel]
|
||||
if channel == nil {
|
||||
client.replies <- ErrNoSuchChannel(server, msg.channel)
|
||||
return
|
||||
}
|
||||
|
||||
client.replies <- RplChannelModeIs(server, channel)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user