From 5a7db119faf09027f0555e721d8770a03e69c3a8 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 2 Aug 2016 09:30:21 +0300 Subject: [PATCH] Print the motd if no parameters are passed --- host.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/host.go b/host.go index 85ce495..c666377 100644 --- a/host.go +++ b/host.go @@ -425,23 +425,29 @@ func (h *Host) InitCommands(c *chat.Commands) { PrefixHelp: "[MESSAGE]", Help: "Set a new message of the day, print current motd without parameters", Handler: func(room *chat.Room, msg message.CommandMsg) error { - if !room.IsOp(msg.From()) { - return errors.New("must be op") - } - - motd := "" args := msg.Args() - if len(args) > 0 { - motd = strings.Join(args, " ") - } + user := msg.From() + motd := h.motd - h.motd = motd - body := fmt.Sprintf("New message of the day set by %s:", msg.From().Name()) - room.Send(message.NewAnnounceMsg(body)) - if motd != "" { - room.Send(message.NewAnnounceMsg(motd)) - } + if len(args) == 0 { + room.Send(message.NewSystemMsg(motd, user)) + } else if !room.IsOp(user) { + return errors.New("must be OP to modify the MOTD") + } else { + motd := "" + args := msg.Args() + if len(args) > 0 { + motd = strings.Join(args, " ") + } + + h.motd = motd + body := fmt.Sprintf("New message of the day set by %s:", msg.From().Name()) + room.Send(message.NewAnnounceMsg(body)) + if motd != "" { + room.Send(message.NewAnnounceMsg(motd)) + } + } return nil }, })