Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save adapter name in robot class #647

Closed
larrycai opened this issue Feb 14, 2014 · 5 comments
Closed

save adapter name in robot class #647

larrycai opened this issue Feb 14, 2014 · 5 comments

Comments

@larrycai
Copy link

in hubot script, sometimes the logic depends on the adapter.

If the adapter is started in --adapter, which may differ from the HUBOT_ADAPTER environment, how can I get it in the script ?

It will be nice if the adapter name is saved in hubot/src/robot.coffee when doing loadAdapter

I also put it in stackoverflow http://stackoverflow.com/questions/21746880

@technicalpickles
Copy link
Member

Should be possible to just save it during the constructor as adapterName somewhere in here: https://github.com/github/hubot/blob/master/src/robot.coffee#L41

It's not as graceful, but you can sometimes 'sniff' for things on robot.adapter to try to determine what adapter it is. For example, this can be used to check for the campfire adapter:

# campfire adapter
if robot.adapter.bot?

The adapter itself could be updated to have name field too.

@larrycai
Copy link
Author

thanks, I answered there by myself with my code sample for irc,shell,xmpp

    robot.respond /adapter$/i, (msg) ->
        #console.log "adapter", robot.adapter
        if robot.adapter.client?
            if robot.adapter.client.preferredSaslMechanism?
                msg.send "this is xmpp adapter"
        if robot.adapter.bot?
            if robot.adapter.bot.opt?
                msg.send "this is irc adapter"
            #if robot.adapter.bot?
                #   msg.send "this is campfire ?"
        if robot.adapter.repl?
            if robot.adapter.repl.terminal?
                msg.send "this is shell adapter"

(can't find the special data for campfire due to environment setup)

better to have this in robot.coffee, hope to get graceful solution.

Anyway, good enough for me.

@technicalpickles
Copy link
Member

Awesome, glad you were able to work something out in the interim! Agree that it'd be easier if robot just remembered the adapter name, or an adapter knew its own name.

@atmos
Copy link
Contributor

atmos commented Mar 5, 2014

Can we just store the string on the robot? Checking methods seems really silly.

@atmos
Copy link
Contributor

atmos commented Mar 5, 2014

Fixed in #663

@atmos atmos closed this as completed Mar 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants