func (d *Default) look() *messages.Error { containerId, err := util.GetContainer(d.M, d.M.GetResource()) if err != nil { return err } shortDesc, err := util.GetShortDesc(d.M, containerId) if err != nil { return err } longDesc, err := util.GetLongDesc(d.M, containerId) if err != nil && !util.IsNoSuchMethod(err) { return err } siblings, err := util.GetContent(d.M, containerId) if err != nil && !util.IsNoSuchMethod(err) { return err } descs, err := util.GetShortDescs(d.M, siblings) if err != nil { return err } if longDesc != "" { util.SendToClient(d.M, util.Sprintf("%v\n%v\n\n%v\n", util.Capitalize(shortDesc.IndefArticlize()), longDesc, descs.Enumerate())) } else { util.SendToClient(d.M, util.Sprintf("%v\n\n%v\n", util.Capitalize(shortDesc.IndefArticlize()), descs.Enumerate())) } return nil }
func (d *Default) L(what string) *messages.Error { if what == "" { return d.look() } matches, err := util.Identify(d.M, what) if err != nil { return err } if len(matches) == 0 { util.SendToClient(d.M, "Look at what?\n") } for _, resource := range matches { shortDesc, err := util.GetShortDesc(d.M, resource) if err != nil { return err } longDesc, err := util.GetLongDesc(d.M, resource) if err != nil && !util.IsNoSuchMethod(err) { return err } if longDesc != "" { util.SendToClient(d.M, util.Sprintf("%v\n%v\n", util.Capitalize(shortDesc.IndefArticlize()), longDesc)) } else { util.SendToClient(d.M, util.Sprintf("%v\n", shortDesc.IndefArticlize())) } } return nil }
func (d *Default) Ident(what string) *messages.Error { matches, err := util.Identify(d.M, what) if err != nil { return err } if len(matches) == 0 { util.SendToClient(d.M, "Identify what?\n") } for _, match := range matches { util.SendToClient(d.M, util.Sprintf("%+v\n", match)) } return nil }
func (h *DefaultHandler) Event(ctx *messages.Context, ev *messages.Event) bool { if ctx.Request.Header.Source != h.M.GetResource() { return true } switch ev.Type { case messages.EventTypeSay: subject := "something" verb := "" if ev.Source == h.M.GetResource() { subject = "you" verb = "say" } else { subjectDesc, serr := util.GetShortDesc(h.M, ev.Source) if serr == nil { subject = subjectDesc.DefArticlize() } verb = "says" } util.SendToClient(h.M, util.Capitalize(util.Sprintf("%v %v %q.\n", subject, verb, ev.Metadata[messages.MetadataPayload]))) case messages.EventTypeDestruct: util.SendToClient(h.M, util.Capitalize(util.Sprintf("%v disappears.\n", ev.SourceShortDesc.IndefArticlize()))) case messages.EventTypeConstruct: object := "something" objectDesc, err := util.GetShortDesc(h.M, ev.Source) if err == nil { object = objectDesc.IndefArticlize() } util.SendToClient(h.M, util.Capitalize(util.Sprintf("%v appears.\n", object))) case messages.EventTypeRequest: if util.DefaultAttentionLevels.Ignored(h.M, ev) { return true } subject := "something" verb := "" if ev.Request.Header.Source == h.M.GetResource() { verb = ev.Request.Header.Verb.SecondPerson subject = "you" } else { verb = ev.Request.Header.Verb.ThirdPerson subjectDesc, serr := util.GetShortDesc(h.M, ev.Request.Header.Source) if serr == nil { subject = subjectDesc.DefArticlize() } } object := "something" if ev.Request.Resource == h.M.GetResource() { if ev.Request.Header.Source == h.M.GetResource() { object = "yourself" } else { object = "you" } } else { objectDesc, err := util.GetShortDesc(h.M, ev.Request.Resource) if err == nil { object = objectDesc.DefArticlize() } } util.SendToClient(h.M, util.Capitalize(util.Sprintf("%v %v %v.\n", subject, verb, object))) default: util.SendToClient(h.M, util.Sprintf("%+v\n", ev)) } return true }