cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

Passing configuration to a plugin #154

Closed nTraum closed 10 years ago

nTraum commented 10 years ago

Hi,

I know this is not a support forum but I either didn't check the docs correctly or the specific use case is missing.

I want to pass down plugin specific configuration to a plugin (e.g. via a Hash). How can I achieve this?

assuming my plugin is:

require 'cinch'
class Foo
  include Cinch::Plugin
  listen_to :connect, :method => :join_channel

  def initialize(*args, options)
    super
    @options = options
  end

  def join_channel(m)
    bot.join(@options[:channel])
  end
end

Whats the correct way to pass the options Hash to the plugin (and register it in the cinch bot?)

Thanks in advance!

dominikh commented 10 years ago
class Foo
  include Cinch::Plugin
  listen_to :connect, :method => :join_channel

  def join_channel(m)
    bot.join(config[:channel])
  end
end

bot = Cinch::Bot.new do
  configure do |c|
    c.plugins.options[Foo][:channel] = "#some_channel"
  end
end

And I hope that plugin was just for demonstrative purposes, as Cinch has built-in options for joining channels when connecting.

nTraum commented 10 years ago

Thanks for the snippet.

Could you point me to an example / the doc where the auto join options are shown?

Thanks in advance. :)

dominikh commented 10 years ago

https://github.com/cinchrb/cinch/blob/master/examples/basic/hello.rb#L6