Comments (17)
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.
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.
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.
Give the response.reply
or robot.reply
a shot.
from hubot-irc.
Also for different hubot-scripts they just flood the main chat...
from hubot-irc.
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.
Did anyone ever try my original suggestion of response.reply
or robot.reply
?
from hubot-irc.
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.
@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.
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.
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.
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.
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.
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.
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.
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.
@jgable Awesome man, thank you so much.
from hubot-irc.
Related Issues (20)
- Hubot doesn't respond on channels starting with ! HOT 3
- Error when `npm install hubot-irc --save`
- Hubot doesn't join IRC channel, stuck on "INFO Using default redis on localhost:6379" HOT 3
- Release v0.2.8 on npm HOT 1
- TLS Support for Hubot HOT 4
- message parsing link/url ?
- Allow multiple server configuration HOT 2
- Have bot respond to its nick when automatically renamed on connect HOT 1
- Install fails on optional dep node-icu-charset-detector HOT 4
- Quit log message shows all channels, not just ones user was in
- Document `notice` function HOT 1
- Hubot doesn't join channels if NICKSERV_PASSWORD is set HOT 2
- HUBOT_IRC_IGNOREINVITE has opposite effect
- Newbie having problems setting up a new hubot-irc in an old 64-bit Debian stable/Jessie box. HOT 19
- Add `hubot-adapter` topic HOT 1
- Update dependencies HOT 3
- Add Real Name option
- Adapter doesn't work with robot.messageRoom
- matrix-org/node-irc dependency not tracking upstream HOT 9
- Failing to connect with `matrix-org/node-irc` >= `1.0.0` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hubot-irc.