Code Monkey home page Code Monkey logo

Comments (17)

jgable avatar jgable commented on July 30, 2024

That's a good question. Have you tried response.reply? If not that then robot.reply user 'some msg'?

I just poked around the hubot coffeescript docs to find that, let me know if it works out.

http://coffeedoc.info/github/github/hubot/master/classes/Response.html

http://coffeedoc.info/github/github/hubot/master/classes/Robot.html#reply-instance

from hubot-irc.

timrogers avatar timrogers commented on July 30, 2024

I managed to get it working in the last hour or so, not sure if my method is the best though...I've got something like this:

module.exports = (robot) ->
  robot.enter (response) ->

    # Get the name of the user who has just joined
    user = response.message.user.name

    # Store the greetings - we store this in an array because it's nicer to send
    # multiple messages than ugly multi-line ones
    greetings = [
      "...",
      "..."
    ]

    unless user == "hubot" # We don't want the bot to PM itself...
      # Send a private message to the person who has joined
      robot.send({user: {name: user}}, greeting) for greeting in greetings

from hubot-irc.

timrogers avatar timrogers commented on July 30, 2024

I'd love to know know if there is a better way than this hack of composing the 'target' object. I just worked this out from reading the code in irc.coffee.

from hubot-irc.

jgable avatar jgable commented on July 30, 2024

Give the response.reply or robot.reply a shot.

from hubot-irc.

jmburges avatar jmburges commented on July 30, 2024

Also for different hubot-scripts they just flood the main chat...

from hubot-irc.

jjasghar avatar jjasghar commented on July 30, 2024

I think i'm going to hack the main help.coffee to send private messages when someone does "hubot help" any good suggestions on that?

from hubot-irc.

jgable avatar jgable commented on July 30, 2024

Did anyone ever try my original suggestion of response.reply or robot.reply?

from hubot-irc.

jjasghar avatar jjasghar commented on July 30, 2024

I attempted to, didn't seem to work at all. Luckly if you PRVMSG the bot then say Hubot help he'll send you the data there.

But it's still not exactly what i want, if someone says Hubot help in the main channel, it floods like no bodies business.

from hubot-irc.

jbartels avatar jbartels commented on July 30, 2024

@jjasghar did you get this working? We are wanting the same thing. Wanted to see if you got it working and possibly share?

from hubot-irc.

jjasghar avatar jjasghar commented on July 30, 2024

I hacked away at it for a bit, nothing. Basically, i got a nerf gun and will shoot anyone that runs hubot help in our main channel right now.

from hubot-irc.

rjhornsby avatar rjhornsby commented on July 30, 2024

After several hours of futzing, I figured out what is going on and why it behaves this way.

In scripts/help.coffee is msg.send emit. From everything I could understand, adding a username to that should have taken care of it:

msg.send msg.message.user.id, emit

However, in node_modules/hubot-irc/src/irc.coffee the send method calls _getTargetFromEnvelope to determine where to direct a reply. The first thing _getTargetFromEnvelope looks for is a room name in the envelope:

317.      # most common case - we're replying to a user in a room
318.      if user.room
319.        target = user.room
320.      # reply directly
321.      else if user.name

This fix is most definitely a hack and I'm sure not the right way to fix it, but I've never messed with coffeescript until now so you'll have to forgive me. In help.coffee, I removed the room from the message envelope before it was handed off to the send method, preventing _getTargetFromEnvelope from knowing anything about the room.

72.    emit = cmds.join "\n"
73.
74.    # force bot to respond privately by removing any reference to the room
75.    delete msg.message.user.room
76.
77.    msg.send emit

Now the bot replies to "help" by private message.

from hubot-irc.

jgable avatar jgable commented on July 30, 2024

Unfortunately, I don't see a solution other than the hack you had to put in the help script. We have no way of knowing whether something should be sent to the room or user only when both are passed.

I'll take a look at adding a convenience method for sending private messages.

from hubot-irc.

jjasghar avatar jjasghar commented on July 30, 2024

I like the idea of checking for private messaging. I could leverage this for specific commands for specific people when they do a private message.

Or at least something to that effect, but yeah, keep up the great work and thanks! 👍

from hubot-irc.

jjasghar avatar jjasghar commented on July 30, 2024

Playing around with one of my toy hubots....it seems it at least acknologes that it comes as a Private message:

[Tue Apr 01 2014 12:38:27 GMT-0500 (CDT)] INFO Got private message from j^2: help meme

from hubot-irc.

rjhornsby avatar rjhornsby commented on July 30, 2024

Playing around with one of my toy hubots....it seems it at least acknologes that it comes as a Private message:

The behavior I've observed is that hubot directs the reply to the source. If the source was a channel, the reply is directed there. If hubot gets a private message, it replies privately. The issue I was having (and what I understood to be the problem here) was more or less redirecting the reply, so that hubot would direct a reply for 'help' in a channel, not back to the channel, but to the user.

We have no way of knowing whether something should be sent to the room or user only when both are passed.

Makes sense. When the channel and the user are specified in the envelope, there has to be some precedence order. The order _getTargetFromEnvelope has right now seems appropriate. A convenience method would be great. A script like help.coffee could then leverage that method to be explicit about where it wanted the reply sent, instead of having to hack up the envelope :)

from hubot-irc.

jgable avatar jgable commented on July 30, 2024

I've added a new sendPrivate method on the Response object and Adapter. This makes it easy to put this kind of code in your scripts to send a private reply:

    if msg.sendPrivate
      msg.sendPrivate('Hello there')
    else
      msg.send('Hello there')

Should be published soon.

from hubot-irc.

jjasghar avatar jjasghar commented on July 30, 2024

@jgable Awesome man, thank you so much.

from hubot-irc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.