예제 #1
0
func (h RememberMeHandler) Handle(tw twistream.Status, tl *twistream.Timeline) error {

	user, err := models.FindUserByIdStr(DB(), tw.User.IdStr)
	log.Println(user, err)

	if err == nil {
		txt := words.New("いや、もう知ってますよ...").Prepend("@" + tw.User.ScreenName).Join()
		return tl.Tweet(twistream.Status{
			Text:                txt,
			InReplyToScreenName: tw.User.ScreenName,
			InReplyToStatusId:   tw.Id,
		})
	}

	err = models.SaveNewUser(DB(), models.NewUserFromTwistreamStatus(tw))
	if err != nil {
		return err
	}

	txt := words.New("よろしくおねがいしまーす! 今日も1日がんばるぞい!").Prepend("@" + tw.User.ScreenName).Join()
	return tl.Tweet(twistream.Status{
		Text:                txt,
		InReplyToScreenName: tw.User.ScreenName,
		InReplyToStatusId:   tw.Id,
	})
}
예제 #2
0
파일: done.go 프로젝트: hisyotan/hisyotan
func (h DoneHandler) 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("/done", "/d")

	newlist := words.New(user.TODOs...).Remove(d.Words...).Words
	user.TODOs = newlist

	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,
	})
}
예제 #3
0
파일: hello.go 프로젝트: hisyotan/hisyotan
func (h HelloHandler) Handle(tw twistream.Status, tl *twistream.Timeline) error {

	user, err := models.FindUserByIdStr(DB(), tw.User.IdStr)
	log.Println(user, err)

	if err == nil {
		txt := words.New("hello! hello!").Prepend("@" + tw.User.ScreenName).Join()
		return tl.Tweet(twistream.Status{
			Text:                txt,
			InReplyToScreenName: tw.User.ScreenName,
			InReplyToStatusId:   tw.Id,
		})
	}

	txt := words.New("誰すか?").Prepend("@" + tw.User.ScreenName).Join()
	return tl.Tweet(twistream.Status{
		Text:                txt,
		InReplyToScreenName: tw.User.ScreenName,
		InReplyToStatusId:   tw.Id,
	})
}
예제 #4
0
파일: list.go 프로젝트: hisyotan/hisyotan
func (h ListHandler) Handle(tw twistream.Status, tl *twistream.Timeline) error {

	user, err := models.FindUserByIdStr(DB(), tw.User.IdStr)
	if err != nil {
		return err
	}

	botname := config.V.Twitter.Bot.ScreenName
	txt := words.New(user.TODOs...).
		Remove("@"+botname).Remove("/add", "/a").
		Prepend("@" + tw.User.ScreenName).
		Append("いちらんです").
		Join(" ")
	return tl.Tweet(twistream.Status{
		Text:                txt,
		InReplyToScreenName: tw.User.ScreenName,
		InReplyToStatusId:   tw.Id,
	})
}