Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Accessing IrcBot from a script #23

Open
hferentschik opened this Issue · 5 comments

4 participants

@hferentschik

Hi,

more of a question really, but how would I go about if I want to write a custom script and want to access the bot variable defined in the irc.coffee? Is that possible?

@ehberg

Good question. I am wondering something similar, I need to send raw Irc commands from my Hubot. Is that possible?

@jgable
Collaborator

Well, the hubot (hubot-irc) has a reference to the Irc module as the .bot property.

I'm not sure what exactly your use case is, but I would probably approach this as a script.

This explanation of Hubot Scripts shows that you get a reference to the hubot from your script initialization. You could check for the presence of hubot.bot and that it was of type Irc; something like this (this exact code probably won't work)

# MyIrcScript.coffee

module.exports = (robot) ->
  return unless typeof robot.bot is "IrcClient"

  robot.respond /hi|hello/i, (msg) ->
    # Send some IRC command...
    robot.bot.sendSomeIrcCommand

Hope that helps, if not, please give some examples of what you've tried and what your use case is.

@ehberg

I have found that you can access the irc 'bot' via

# MyIrcScript.coffee
module.exports = (robot) ->
    robot.adapter.whateverMethod()

So now the issue for me is sending raw commands such as MODE. We have a private internal IRC server and our bots control operators with on an old java framework. I would like to have my irc hubot send the MODE command to add operator mode to a given user. I have tried modifying the adapter and playing around even with the node-irc package to no avail. Here is one example of something that didnt work from within the irc hubot adapter

# irc.coffee
mode: () ->
    @bot.emit 'raw',
       command: 'MODE'
       nick: process.env.HUBOT_IRC_NICK
       args: ["#myroom", "+o", "myuser"]

Something like that seems like it should work when calling it like:

# MyIrcScript.coffee
module.exports = (robot) ->
    robot.adapter.mode()

Function gets called as you would expect, but mode does not change. Maybe an expert here can comment. Cheers

@nmcclain

Here is a simple hubot script that grants OP to anyone that asks hubot for it - no need to edit irc.coffee:

# opme.coffee
module.exports = (robot) ->
  robot.respond /op me/i, (msg) ->
    robot.adapter.command('MODE', msg.message.user.room, '+o', msg.message.user.name);
@ehberg

Awesome find nmcclain! I could have sworn I tried that, but I must have missed it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.