コード例 #1
0
ファイル: robot.go プロジェクト: bcho/read
func (r *robot) responseBookmark(msg tgbot.Message) string {
	defer r.SetIdle()

	link := extractFirstLink(r.currCommanadArgument)
	if link == "" {
		return "Oops, can't find any links."
	}

	err := r.bookmarks.Remember(msg.Time(), link, r.currCommanadArgument)
	if err != nil {
		return err.Error()
	}

	return fmt.Sprintf("Roger that! New link %s added.", link)
}
コード例 #2
0
ファイル: robot.go プロジェクト: bcho/read
func (r *robot) Response(message tgbot.Message) tgbot.MessageConfig {
	if message.IsCommand() {
		r.SetCommand(message.Command(), message.CommandArguments())
	}

	var response string
	switch r.currCommand {
	case Idle:
		response = r.responseIdle(message)
	case Read:
		response = r.responseRead(message)
	case Stats:
		response = r.responseStats(message)
	case Bookmark:
		response = r.responseBookmark(message)
	case Random:
		response = r.responseRandom(message)
	case Publish:
		response = r.responsePublish(message)
	}

	reply := tgbot.NewMessage(message.Chat.ID, response)
	reply.ReplyToMessageID = message.MessageID

	return reply
}