func (h AddHandler) Handle(tw twistream.Status, tl *twistream.Timeline) error { botname := config.V.Twitter.Bot.ScreenName user, err := models.FindUserByIdStr(DB(), tw.User.IdStr) if err != nil { return err } d := words.Parse(tw.Text).Remove("@"+botname).Remove("/add", "/a") user.TODOs = append(user.TODOs, d.Words...) user.Update(DB()) txt := words.New(d.Words...). Prepend("@" + tw.User.ScreenName). Append("追加しました"). Join(" ") return tl.Tweet(twistream.Status{ Text: txt, InReplyToScreenName: tw.User.ScreenName, InReplyToStatusId: tw.Id, }) }
func (h AddHandler) Match(tw twistream.Status) bool { if tw.InReplyToUserIdStr != config.V.Twitter.Bot.UserID { return false } d := words.Parse(tw.Text) return (d.Has("/add") || d.Has("/a")) }
func (h OnErrorHandler) HandleError(err error, tw twistream.Status, tl *twistream.Timeline) error { // botname := config.V.Twitter.Bot.ScreenName txt := words.Parse("エラー、よく聞き取れませんでした: "). Prepend("@otiai10"). Append(err.Error()). Join(" ") return tl.Tweet(twistream.Status{ Text: txt, InReplyToScreenName: tw.User.ScreenName, InReplyToStatusId: tw.Id, }) return err }
func (h EchoHandler) Handle(tw twistream.Status, tl *twistream.Timeline) error { botname := config.V.Twitter.Bot.ScreenName txt := words.Parse(tw.Text). Remove("@" + botname). Remove("/echo"). Prepend("@" + tw.User.ScreenName). Append("って何?"). Join(" ") err := tl.Tweet(twistream.Status{ Text: txt, InReplyToScreenName: tw.User.ScreenName, InReplyToStatusId: tw.Id, }) log.Println(txt, err) return err }
func (h RememberMeHandler) Match(tw twistream.Status) bool { if tw.InReplyToUserIdStr != config.V.Twitter.Bot.UserID { return false } return words.Parse(tw.Text).Has("/rememberme") }