Print the motd if no parameters are passed

This commit is contained in:
Aaron 2016-08-02 09:30:21 +03:00
parent 61e8442cf5
commit 5a7db119fa

34
host.go
View File

@ -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
},
})