cinchrb / cinch

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

Plugins not registering? #152

Closed lpeabody closed 10 years ago

lpeabody commented 10 years ago

I'm using Cinch v2.0.11 and Ruby v1.9.3-p484. I have the following code:

require 'cinch'
require 'yaml'

config = YAML.load_file('config.yml')

class Hello
    include Cinch::Plugin

    match "hello"

    def execute(m)
        m.reply "Hello, #{m.user.user}!"
    end
end

password = config['bot']['password']
host = config['bot']['server']
nick = config['bot']['nick']
channels = config['application']['channels'].map { |v| "##{v}" }

bot = Cinch::Bot.new do
  configure do |c|
    c.server = host
    # c.port = port
    c.nick = nick
    c.password = password
    c.channels = channels
    c.plugins.plugins = [Hello]
  end
end

bot.start

My understanding based on the example in the readme from the repo front page is that this should work. However, when the bot connects and I enter "hello" into chat, I get no response. Any idea as to why this could be happening? I'm hoping I'm just missing something painfully obvious. Thanks.

dominikh commented 10 years ago

Bitten by the lack of documentation on that bit. Matchers in plugins have a default prefix /^!/ – which means that the command starts with a !. hello turns into !hello.

lpeabody commented 10 years ago

Gotcha. Is there an example somehwere that shows how to set the prefix on a matcher?

dominikh commented 10 years ago

https://github.com/cinchrb/cinch/blob/master/examples/plugins/custom_prefix.rb for per-plugin prefix. c.plugins.prefix for a bot-wide prefix. match /.../, prefix: my_prefix for a per-match prefix.