mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +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)
|
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`
|
// NewChannel creates a new channel from a `Server` and a `name`
|
||||||
// string, which must be unique on the server.
|
// string, which must be unique on the server.
|
||||||
func NewChannel(s *Server, name string) *Channel {
|
func NewChannel(s *Server, name string) *Channel {
|
||||||
@ -106,6 +117,11 @@ func (channel *Channel) String() string {
|
|||||||
return channel.Id()
|
return channel.Id()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <mode> <mode params>
|
||||||
|
func (channel *Channel) ModeString() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (channel *Channel) Join(client *Client) {
|
func (channel *Channel) Join(client *Client) {
|
||||||
channel.members[client] = true
|
channel.members[client] = true
|
||||||
client.channels[channel] = true
|
client.channels[channel] = true
|
||||||
|
@ -348,11 +348,7 @@ func NewPrivMsgCommand(args []string) (EditableCommand, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *PrivMsgCommand) TargetIsChannel() bool {
|
func (m *PrivMsgCommand) TargetIsChannel() bool {
|
||||||
switch m.target[0] {
|
return IsChannel(m.target)
|
||||||
case '&', '#', '+', '!':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOPIC [newtopic]
|
// TOPIC [newtopic]
|
||||||
@ -428,11 +424,22 @@ func stringToRunes(str string) <-chan rune {
|
|||||||
return runes
|
return runes
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewModeCommand(args []string) (EditableCommand, error) {
|
type ChannelModeCommand struct {
|
||||||
if len(args) == 0 {
|
BaseCommand
|
||||||
return nil, NotEnoughArgsError
|
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{
|
cmd := &ModeCommand{
|
||||||
nickname: args[0],
|
nickname: args[0],
|
||||||
changes: make([]ModeChange,
|
changes: make([]ModeChange,
|
||||||
@ -460,12 +467,25 @@ func NewModeCommand(args []string) (EditableCommand, error) {
|
|||||||
return cmd, nil
|
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 {
|
type WhoisCommand struct {
|
||||||
BaseCommand
|
BaseCommand
|
||||||
target string
|
target string
|
||||||
masks []string
|
masks []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [ <target> ] <mask> *( "," <mask> )
|
||||||
func NewWhoisCommand(args []string) (EditableCommand, error) {
|
func NewWhoisCommand(args []string) (EditableCommand, error) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return nil, NotEnoughArgsError
|
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")
|
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)
|
// errors (also numeric)
|
||||||
|
|
||||||
func ErrAlreadyRegistered(source Identifier) Reply {
|
func ErrAlreadyRegistered(source Identifier) Reply {
|
||||||
@ -261,8 +266,8 @@ func ErrNeedMoreParams(source Identifier, command string) Reply {
|
|||||||
"%s :Not enough parameters", command)
|
"%s :Not enough parameters", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNoSuchChannel(source Identifier, channel string) Reply {
|
func ErrNoSuchChannel(server *Server, channel string) Reply {
|
||||||
return NewNumericReply(source, ERR_NOSUCHCHANNEL,
|
return NewNumericReply(server, ERR_NOSUCHCHANNEL,
|
||||||
"%s :No such channel", channel)
|
"%s :No such channel", channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,3 +316,8 @@ func ErrRestricted(server *Server) Reply {
|
|||||||
func ErrNoSuchServer(server *Server, target string) Reply {
|
func ErrNoSuchServer(server *Server, target string) Reply {
|
||||||
return NewNumericReply(server, ERR_NOSUCHSERVER, "%s :No such server", target)
|
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)
|
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