time command

This commit is contained in:
Jeremy Latt 2014-02-25 07:45:40 -08:00
parent f0305cf01a
commit 4d2d18caf1
4 changed files with 28 additions and 0 deletions

View File

@ -47,6 +47,7 @@ var (
PRIVMSG: NewPrivMsgCommand, PRIVMSG: NewPrivMsgCommand,
PROXY: NewProxyCommand, PROXY: NewProxyCommand,
QUIT: NewQuitCommand, QUIT: NewQuitCommand,
TIME: NewTimeCommand,
TOPIC: NewTopicCommand, TOPIC: NewTopicCommand,
USER: NewUserCommand, USER: NewUserCommand,
VERSION: NewVersionCommand, VERSION: NewVersionCommand,
@ -932,3 +933,16 @@ func NewInviteCommand(args []string) (editableCommand, error) {
channel: args[1], channel: args[1],
}, nil }, nil
} }
type TimeCommand struct {
BaseCommand
target string
}
func NewTimeCommand(args []string) (editableCommand, error) {
cmd := &TimeCommand{}
if len(args) > 0 {
cmd.target = args[0]
}
return cmd, nil
}

View File

@ -54,6 +54,7 @@ const (
PRIVMSG StringCode = "PRIVMSG" PRIVMSG StringCode = "PRIVMSG"
PROXY StringCode = "PROXY" PROXY StringCode = "PROXY"
QUIT StringCode = "QUIT" QUIT StringCode = "QUIT"
TIME StringCode = "TIME"
TOPIC StringCode = "TOPIC" TOPIC StringCode = "TOPIC"
USER StringCode = "USER" USER StringCode = "USER"
VERSION StringCode = "VERSION" VERSION StringCode = "VERSION"

View File

@ -374,6 +374,11 @@ func (target *Client) RplInviting(invitee *Client, channel string) {
"%s %s", invitee.Nick(), channel) "%s %s", invitee.Nick(), channel)
} }
func (target *Client) RplTime() {
target.NumericReply(RPL_TIME,
"%s :%s", target.server.name, time.Now().Format(time.RFC1123))
}
// //
// errors (also numeric) // errors (also numeric)
// //

View File

@ -791,3 +791,11 @@ func (msg *InviteCommand) HandleServer(server *Server) {
channel.Invite(target, client) channel.Invite(target, client)
} }
func (msg *TimeCommand) HandleServer(server *Server) {
if (msg.target != "") && (msg.target != server.name) {
msg.Client().ErrNoSuchServer(msg.target)
return
}
msg.Client().RplTime()
}