This commit is contained in:
Andrey Petrov 2015-01-18 19:55:01 -08:00
parent c33f4284f9
commit 080b6e8f1b
2 changed files with 39 additions and 13 deletions

2
cmd.go
View File

@ -144,7 +144,7 @@ func main() {
logger.Errorf("Failed to load MOTD file: %v", err) logger.Errorf("Failed to load MOTD file: %v", err)
return return
} }
motdString := string(motd[:]) motdString := strings.TrimSpace(string(motd))
// hack to normalize line endings into \r\n // hack to normalize line endings into \r\n
motdString = strings.Replace(motdString, "\r\n", "\n", -1) motdString = strings.Replace(motdString, "\r\n", "\n", -1)
motdString = strings.Replace(motdString, "\n", "\r\n", -1) motdString = strings.Replace(motdString, "\n", "\r\n", -1)

50
host.go
View File

@ -81,6 +81,11 @@ func (h *Host) Connect(term *sshd.Terminal) {
}() }()
defer user.Close() defer user.Close()
// Send MOTD
if h.motd != "" {
user.Send(chat.NewAnnounceMsg(h.motd))
}
member, err := h.Join(user) member, err := h.Join(user)
if err == chat.ErrIdTaken { if err == chat.ErrIdTaken {
// Try again... // Try again...
@ -284,6 +289,28 @@ func (h *Host) InitCommands(c *chat.Commands) {
}, },
}) })
c.Add(chat.Command{
Prefix: "/whois",
PrefixHelp: "USER",
Help: "Information about USER.",
Handler: func(room *chat.Room, msg chat.CommandMsg) error {
args := msg.Args()
if len(args) == 0 {
return errors.New("must specify user")
}
target, ok := h.GetUser(args[0])
if !ok {
return errors.New("user not found")
}
id := target.Identifier.(*Identity)
room.Send(chat.NewSystemMsg(id.Whois(), msg.From()))
return nil
},
})
// Op commands // Op commands
c.Add(chat.Command{ c.Add(chat.Command{
Op: true, Op: true,
@ -349,28 +376,27 @@ func (h *Host) InitCommands(c *chat.Commands) {
c.Add(chat.Command{ c.Add(chat.Command{
Op: true, Op: true,
Prefix: "/whois", Prefix: "/motd",
PrefixHelp: "USER", PrefixHelp: "MESSAGE",
Help: "Information about USER.", Help: "Set the MESSAGE of the day.",
Handler: func(room *chat.Room, msg chat.CommandMsg) error { Handler: func(room *chat.Room, msg chat.CommandMsg) error {
// TODO: Would be nice to specify what to ban. Key? Ip? etc.
if !room.IsOp(msg.From()) { if !room.IsOp(msg.From()) {
return errors.New("must be op") return errors.New("must be op")
} }
motd := ""
args := msg.Args() args := msg.Args()
if len(args) == 0 { if len(args) > 0 {
return errors.New("must specify user") motd = strings.Join(args, " ")
} }
target, ok := h.GetUser(args[0]) h.motd = motd
if !ok { body := fmt.Sprintf("New message of the day set by %s:", msg.From().Name())
return errors.New("user not found") room.Send(chat.NewAnnounceMsg(body))
if motd != "" {
room.Send(chat.NewAnnounceMsg(motd))
} }
id := target.Identifier.(*Identity)
room.Send(chat.NewSystemMsg(id.Whois(), msg.From()))
return nil return nil
}, },
}) })