From 4d2d18caf15c1fd3efbf992170afed3b173d9faf Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Tue, 25 Feb 2014 07:45:40 -0800 Subject: [PATCH] time command --- irc/commands.go | 14 ++++++++++++++ irc/constants.go | 1 + irc/reply.go | 5 +++++ irc/server.go | 8 ++++++++ 4 files changed, 28 insertions(+) diff --git a/irc/commands.go b/irc/commands.go index d935ec04..5c2b9765 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -47,6 +47,7 @@ var ( PRIVMSG: NewPrivMsgCommand, PROXY: NewProxyCommand, QUIT: NewQuitCommand, + TIME: NewTimeCommand, TOPIC: NewTopicCommand, USER: NewUserCommand, VERSION: NewVersionCommand, @@ -932,3 +933,16 @@ func NewInviteCommand(args []string) (editableCommand, error) { channel: args[1], }, 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 +} diff --git a/irc/constants.go b/irc/constants.go index e00e6e74..55aa44fd 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -54,6 +54,7 @@ const ( PRIVMSG StringCode = "PRIVMSG" PROXY StringCode = "PROXY" QUIT StringCode = "QUIT" + TIME StringCode = "TIME" TOPIC StringCode = "TOPIC" USER StringCode = "USER" VERSION StringCode = "VERSION" diff --git a/irc/reply.go b/irc/reply.go index 18b30549..ca9f497f 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -374,6 +374,11 @@ func (target *Client) RplInviting(invitee *Client, channel string) { "%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) // diff --git a/irc/server.go b/irc/server.go index 8d3b72d8..acac8ed6 100644 --- a/irc/server.go +++ b/irc/server.go @@ -791,3 +791,11 @@ func (msg *InviteCommand) HandleServer(server *Server) { 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() +}