From c8661e6883fdc5503058fd74eed6dd7d6b81c0ab Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Wed, 3 Aug 2016 17:58:49 -0400 Subject: [PATCH] motd: Allow for reading the current motd when no additional args given. Closes #155, merges #157 Squashed commit of the following: commit bcb0810637c99223753629a2e55169b07ee9fe51 Author: Andrey Petrov Date: Wed Aug 3 17:58:37 2016 -0400 motd: Refactor inner conditions commit ac28c8cb4e8dc2a0d23abe3dcf52b69175cde51b Author: Aaron Date: Tue Aug 2 09:38:36 2016 +0300 Fix small issues with the help message commit a80ae77e1d691a4ec7125be5441d4f6eea767a75 Author: Aaron Date: Tue Aug 2 09:30:21 2016 +0300 Print the motd if no parameters are passed commit 2db1b3c123661cdbd622d5ba2ff81ede8cb8a951 Author: Aaron Date: Tue Aug 2 09:29:41 2016 +0300 Update the motd command's description --- host.go | 19 ++++++++++++------- identity.go | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/host.go b/host.go index a8fe6c1a..41c2f915 100644 --- a/host.go +++ b/host.go @@ -425,15 +425,21 @@ func (h *Host) InitCommands(c *chat.Commands) { c.Add(chat.Command{ Op: true, Prefix: "/motd", - PrefixHelp: "MESSAGE", - Help: "Set the MESSAGE of the day.", + PrefixHelp: "[MESSAGE]", + Help: "Set a new MESSAGE of the day, print the current motd without parameters.", Handler: func(room *chat.Room, msg message.CommandMsg) error { - if !room.IsOp(msg.From()) { - return errors.New("must be op") + args := msg.Args() + user := msg.From() + motd := h.motd + + if len(args) == 0 { + room.Send(message.NewSystemMsg(motd, user)) + return nil + } + if !room.IsOp(user) { + return errors.New("must be OP to modify the MOTD") } - motd := "" - args := msg.Args() if len(args) > 0 { motd = strings.Join(args, " ") } @@ -444,7 +450,6 @@ func (h *Host) InitCommands(c *chat.Commands) { if motd != "" { room.Send(message.NewAnnounceMsg(motd)) } - return nil }, }) diff --git a/identity.go b/identity.go index 21988e34..b4de8729 100644 --- a/identity.go +++ b/identity.go @@ -45,6 +45,7 @@ func (i Identity) Whois() string { if i.PublicKey() != nil { fingerprint = sshd.Fingerprint(i.PublicKey()) } + // TODO: Include time joined, client, etc. return fmt.Sprintf("name: %s"+message.Newline+ " > ip: %s"+message.Newline+ " > fingerprint: %s", i.Name(), ip, fingerprint)