-2

I have just installed hubot and I'm trying some basic tests.

I have this basic script in /scripts:

module.exports = (robot) ->

  robot.respond /myscript status/i, (msg) ->
        if robot.auth.hasRole(msg.envelope.user, 'test')
            msg.reply "Success"
        else
            msg.reply "Sorry. Need 'test' role."

I issue the appropriate Slack commands:

schroeder has test role

"OK, schroeder has the 'test' role."

myscript status

"Sorry. Need 'test' role."

I have:

  • tried to reverse the logic (if vs unless)
  • verified that the scripts are being updated (by changing responses)
  • verified that the redis backend is storing the role (connected via redis-cli and inspected the key).

After re-reading all the documentation and looking up bug reports I still cannot see what I'm missing. It has got to be something simple, but I'm out of ideas. It is almost as though the script is not able to view the stored role (hubot-auth can, but my script cannot).

schroeder
  • 533
  • 1
  • 7
  • 25

1 Answers1

-1

Even though on start, hubot says that it is connecting to a local Redis server:

INFO hubot-redis-brain: Using default redis on localhost:6379

It isn't... At least not in a way that you would expect.

If redis is, in fact running, you should get an extra message:

INFO hubot-redis-brain: Data for hubot brain retrieved from Redis

That message does not appear and there is no warning or error that Redis is not running.

If you have not set up hubot-redis-brain properly, you will get strange errors and inconsistencies, like hubot-auth role check functions failing.

In addition, I found that even after I set Redis up properly, my test script did not work. Even though all the tutorials I found test the msg.envelope.user, this did not work for me. I needed to use the msg.message.user.name and resolve with the brain class:

module.exports = (robot) ->

  robot.respond /fbctf status/i, (msg) ->
    user = robot.brain.userForName(msg.message.user.name)
    if robot.auth.hasRole(user, 'test')
      msg.reply "Success"
    else
      msg.reply "Sorry. Need 'test' role."
schroeder
  • 533
  • 1
  • 7
  • 25
  • If you have the redis-brain script installed all the scripts that make use of the brain for memory will fail or behave strangely (in my experience they all throw errors). If you remove redis-brain they will work just fine because they will use a in-memory brain. Your problem is that your assumptions were wrong, the message `hubot-redis-brain: Using default redis on localhost:6379` means that no redis url was found in the config, so it's using the default. `hubot-redis-brain: Successfully connected to Redis` is what you wanted. Always check the code of the script to save some frustration ;) – LucasMetal Dec 13 '18 at 13:16