 #  HUBOT_AUTO_FAV_API_SECRET
 #  HUBOT_AUTO_FAV_ACCESS_TOKEN
 #  HUBOT_AUTO_FAV_ACCESS_TOKEN_SECRET
+#  HUBOT_AUTO_FAV_SHOW_DETAIL
 #
 # Commands:
 #   None


module.exports = (robot) ->

  apiInterval = parseInt(process.env.HUBOT_AUTO_FAV_API_INTERVAL ? '1000', 10)
  interval = parseInt(process.env.HUBOT_AUTO_FAV_INTERVAL ? '60000', 10)
  keywords = JSON.parse(process.env.HUBOT_AUTO_FAV_KEYWORDS ? '[]').map (k) ->

  tweetUrl = (tweet) ->
    "https://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id_str}"

  tweetDetail = (tweet) ->
    """
    #{tweet.user.screen_name}: #{tweet.text}
    #{tweetUrl(tweet)}
    """

  format = (tweet) ->
    if showDetail then tweetDetail(tweet) else tweetUrl(tweet)

  searchAndFavorite = (keyword) ->
    options = if keyword.sinceId? then { since_id: keyword.sinceId } else {}
    search keyword.q, options
