github / hubot-scripts

DEPRECATED, see https://github.com/github/hubot-scripts/issues/1113 for details - optional scripts for hubot, opt in via hubot-scripts.json
MIT License
3.53k stars 1.86k forks source link

Redis.brain responds differently with local redis server compared to heroku redis cloud. #1712

Closed auryn-macmillan closed 8 years ago

auryn-macmillan commented 8 years ago

First time writing a hubot script and using coffeescript, so excuse the messy code.

I wrote a script for automating responses on slack, it works great using a local redis server, but when I run it on heroku using the redis cloud some of the logic doesn't work. Any idea what might cause this?

Here's a link to my script: https://github.com/auryn-macmillan/spam_free_slackbot/tree/master

here is the code that is broken on heroku.

  # respond when corresponding trigger is heard.
  robot.hear /(.*)/i, (res) ->
    # check if robot.brain.data.responses are allowed in this channel,
    if robot.brain.data.channels[res.message.room]
      # get current time, -0 becasue otherwise 'new Date()' returns a string.
      robot.brain.data.channels[res.message.room].timeNow = new Date() - 0
    for comm of robot.brain.data.responses
      if !robot.brain.data.responses[comm][res.message.room]
        robot.brain.data.responses[comm][res.message.room] = new Channel res.message.room
      # cheack if hubot is allowed to post in this channel
      # and check the current time is more than TIMELIMIT minutes from the last time this message was posted,
      # and check that there has been at least LINECOUNT lines posted since the last time this message was posted.
      if robot.brain.data.channels[res.message.room] and robot.brain.data.channels[res.message.room].timeNow - robot.brain.data.responses[comm][res.message.room].lastTime > TIMELIMIT and robot.brain.data.channels[res.message.room].lineCount - robot.brain.data.responses[comm][res.message.room].lastLine > LINECOUNT
        for trig of robot.brain.data.responses[comm].triggers
          if res.match[1].includes(robot.brain.data.responses[comm].triggers[trig])
            res.send robot.brain.data.responses[comm].response
            robot.brain.data.responses[comm][res.message.room].lastTime = robot.brain.data.channels[res.message.room].timeNow
            robot.brain.data.responses[comm][res.message.room].lastLine = robot.brain.data.channels[res.message.room].lineCount
            break
technicalpickles commented 8 years ago

Closing for https://github.com/hubot-scripts/hubot-redis-brain/issues/21