Question

Is there a way to find an @mention name for a user name (either the numeric xxxx_xxxxxx or full name) and vice versa?

Looking at the msg.message object there is a user object with the id, jid, and name of the person the message was from. I'd like to find that person's @mention name and potentially the user name of any person they @ mention in their message.

Était-ce utile?

La solution

I want this too. But as it's not on the xmpp message hubot won't know about it. I think you will need to add a command that will set the mention name as a property of the user. Something like:

robot.respond /mentionname is @?(.+)$/i, (msg) ->
  mentionname = msg.match[2]

  user = robot.brain.userForId(msg.envelope.user.id)
  user.mentionname = mentionname

You can then look it up in other custom commands. You add another method to the brain userForMentionName that does much the same as userForName. Add this to the brain in ur script init.

userForMentionName = (name) ->
  result = null
  lowerName = name.toLowerCase()

  for k of (robot.brain.data.users or { })
    mentionName = robot.brain.data.users[k]['mention_name']      
    if mentionName? and mentionName.toLowerCase() is lowerName
      result = robot.brain.data.users[k]
  result

Alternatively you could modify userForName to check the userName or the mentionname field, but that might break other stuff. Either way you will need ur users to tell hubot what their mentionname is... or perhaps the hubot-hipchat adapter could look it up if it has that information... i'll have a look.

-- Edit --

Ignore all that :D The hipchat adapter adds a "mention_name" field to the user object stored in the brain. So all you have to do is loop through the users and find the one with a matching mention name

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top