 #   Sachinr
 
 module.exports = (robot) ->
-  cronJob  = require('cron').CronJob
   response = new robot.Response(robot)
   robot.brain.data.twitter_mention ?= {}
+  setInterval ->
+    last_tweet = robot.brain.data.twitter_mention.last_tweet || ''
 
-  if twitter_query(robot)?
-    new cronJob '*/5 * * * *', ->
-      last_tweet = robot.brain.data.twitter_mention.last_tweet || ''
-
+    if twitter_query(robot)?
       response.http('http://search.twitter.com/search.json')
         .query(q: escape(twitter_query(robot)), since_id: last_tweet)
         .get() (err, res, body) ->

#   hubot show twitter query - Show current search query
#
# Dependencies:
#   "cron": "1.0.1"
#
# Configuration:
#   HUBOT_TWITTER_MENTION_QUERY

            for tweet in tweets.results.reverse()
              sendMessage robot, "http://twitter.com/#!/#{tweet.from_user}/status/#{tweet.id_str}"

  , 1000 * 60 * 5


  robot.respond /(set twitter query) (.*)/i, (msg) ->
    robot.brain.data.twitter_mention.query = msg.match[2]
