mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 21:39:25 +01:00
away modes
This commit is contained in:
parent
cdae59ecf5
commit
08d9d5ab79
@ -55,11 +55,13 @@ func (channel *Channel) Destroy() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (channel *Channel) Reply(reply Reply) error {
|
func (channel *Channel) Reply(replies ...Reply) error {
|
||||||
if channel.replies == nil {
|
if channel.replies == nil {
|
||||||
return ErrAlreadyDestroyed
|
return ErrAlreadyDestroyed
|
||||||
}
|
}
|
||||||
channel.replies <- reply
|
for _, reply := range replies {
|
||||||
|
channel.replies <- reply
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,23 +11,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
away bool
|
away bool
|
||||||
channels ChannelSet
|
awayMessage string
|
||||||
conn net.Conn
|
channels ChannelSet
|
||||||
hostname string
|
conn net.Conn
|
||||||
idleTimer *time.Timer
|
hostname string
|
||||||
invisible bool
|
idleTimer *time.Timer
|
||||||
nick string
|
invisible bool
|
||||||
operator bool
|
nick string
|
||||||
quitTimer *time.Timer
|
operator bool
|
||||||
realname string
|
quitTimer *time.Timer
|
||||||
recv *bufio.Reader
|
realname string
|
||||||
registered bool
|
recv *bufio.Reader
|
||||||
replies chan<- Reply
|
registered bool
|
||||||
send *bufio.Writer
|
replies chan<- Reply
|
||||||
server *Server
|
send *bufio.Writer
|
||||||
serverPass bool
|
server *Server
|
||||||
username string
|
serverPass bool
|
||||||
|
username string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(server *Server, conn net.Conn) *Client {
|
func NewClient(server *Server, conn net.Conn) *Client {
|
||||||
|
@ -18,6 +18,7 @@ var (
|
|||||||
NotEnoughArgsError = errors.New("not enough arguments")
|
NotEnoughArgsError = errors.New("not enough arguments")
|
||||||
ErrParseCommand = errors.New("failed to parse message")
|
ErrParseCommand = errors.New("failed to parse message")
|
||||||
parseCommandFuncs = map[string]parseCommandFunc{
|
parseCommandFuncs = map[string]parseCommandFunc{
|
||||||
|
"AWAY": NewAwayCommand,
|
||||||
"CAP": NewCapCommand,
|
"CAP": NewCapCommand,
|
||||||
"JOIN": NewJoinCommand,
|
"JOIN": NewJoinCommand,
|
||||||
"MODE": NewModeCommand,
|
"MODE": NewModeCommand,
|
||||||
@ -609,3 +610,24 @@ func NewProxyCommand(args []string) (editableCommand, error) {
|
|||||||
destPort: args[4],
|
destPort: args[4],
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AwayCommand struct {
|
||||||
|
BaseCommand
|
||||||
|
text string
|
||||||
|
away bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *AwayCommand) String() string {
|
||||||
|
return fmt.Sprintf("AWAY(%s)", msg.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAwayCommand(args []string) (editableCommand, error) {
|
||||||
|
cmd := &AwayCommand{}
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
cmd.text = args[0]
|
||||||
|
cmd.away = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
19
irc/reply.go
19
irc/reply.go
@ -252,8 +252,23 @@ func RplBanList(channel *Channel, ban UserMask) Reply {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RplEndOfBanList(channel *Channel) Reply {
|
func RplEndOfBanList(channel *Channel) Reply {
|
||||||
return NewNumericReply(channel.server, RPL_ENDOFBANLIST, "%s :End of channel ban list",
|
return NewNumericReply(channel.server, RPL_ENDOFBANLIST,
|
||||||
channel.name)
|
"%s :End of channel ban list", channel.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RplNowAway(server *Server) Reply {
|
||||||
|
return NewNumericReply(server, RPL_NOWAWAY,
|
||||||
|
":You have been marked as being away")
|
||||||
|
}
|
||||||
|
|
||||||
|
func RplUnAway(server *Server) Reply {
|
||||||
|
return NewNumericReply(server, RPL_UNAWAY,
|
||||||
|
":You are no longer marked as being away")
|
||||||
|
}
|
||||||
|
|
||||||
|
func RplAway(server *Server, client *Client) Reply {
|
||||||
|
return NewNumericReply(server, RPL_AWAY,
|
||||||
|
"%s :%s", client.nick, client.awayMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// errors (also numeric)
|
// errors (also numeric)
|
||||||
|
@ -147,12 +147,12 @@ func (s *Server) tryRegister(c *Client) {
|
|||||||
RplYourHost(s),
|
RplYourHost(s),
|
||||||
RplCreated(s),
|
RplCreated(s),
|
||||||
RplMyInfo(s))
|
RplMyInfo(s))
|
||||||
server.MOTD(c)
|
s.MOTD(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) MOTD(client *Client) {
|
func (server *Server) MOTD(client *Client) {
|
||||||
c.Reply(ErrNoMOTD(server))
|
client.Reply(ErrNoMOTD(server))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Id() string {
|
func (s *Server) Id() string {
|
||||||
@ -305,6 +305,9 @@ func (m *PrivMsgCommand) HandleServer(s *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
target.Reply(RplPrivMsg(m.Client(), target, m.message))
|
target.Reply(RplPrivMsg(m.Client(), target, m.message))
|
||||||
|
if target.away {
|
||||||
|
m.Client().Reply(RplAway(s, target))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ModeCommand) HandleServer(s *Server) {
|
func (m *ModeCommand) HandleServer(s *Server) {
|
||||||
@ -407,3 +410,15 @@ func (msg *CapCommand) HandleServer(server *Server) {
|
|||||||
func (msg *ProxyCommand) HandleServer(server *Server) {
|
func (msg *ProxyCommand) HandleServer(server *Server) {
|
||||||
msg.Client().hostname = LookupHostname(msg.sourceIP)
|
msg.Client().hostname = LookupHostname(msg.sourceIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *AwayCommand) HandleServer(server *Server) {
|
||||||
|
client := msg.Client()
|
||||||
|
client.away = msg.away
|
||||||
|
client.awayMessage = msg.text
|
||||||
|
|
||||||
|
if client.away {
|
||||||
|
client.Reply(RplNowAway(server))
|
||||||
|
} else {
|
||||||
|
client.Reply(RplUnAway(server))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -108,7 +108,7 @@ type Identifier interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Replier interface {
|
type Replier interface {
|
||||||
Reply(Reply) error
|
Reply(...Reply) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Reply interface {
|
type Reply interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user