cinchrb / cinch

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

Cannot do things like op and kick #149

Closed juderosen closed 10 years ago

juderosen commented 10 years ago

I've installed Cinch and made a nice bot that replies to regex, but I cannot do things like op and kick. Here's some of what I've tried:

require 'cinch'

bot = Cinch::Bot.new do
    # This has always worked
    configure do |c|
        c.server = "hubbard.freenode.net"
        c.channels = ["#mychannel"]
        c.nick = "mybotsname"
        c.password = "mypassword"
    end
    op("mybotsname") # This isn't recognized
    # This has always worked fine.
    on :message, /((hi)+)|((hello)+)/i do |m|
        m.reply "Hello, #{m.user.nick}! Type 'info' or 'information'!"
    end
    on :message, /somethingidontwantsaid/i do |user|
        # This doesn't work
        kick(user, reason = "Please, do not say that.")
    end
end
bot.start

I get this error when I run my code (not the example code above, my actual code, which has all the same stuff in it, just in a different order):

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cinch-2.0.10/lib/cinch/user.rb:381:in `m
ethod_missing': undefined method `op' for #<Bot nick=nil> (NoMethodError)
        from mybotfile.rb:11:in `block in <main>'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cinch-2.0.10/lib/cinch/bot.
rb:353:in `instance_eval'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/cinch-2.0.10/lib/cinch/bot.
rb:353:in `initialize'
        from mybotfile.rb:4:in `new'
        from mybotfile.rb:4:in `<main>'

What am I doing wrong? I did give my bot ops, so, I don't know what's going on.

If it helps, I'm running Ruby 2.0.0 x64 on Windows 7 x64.

hcolomb commented 10 years ago

First of all, the bot can't op itself. If you want to op somebody who sends a command to the bot try something like:

on :message, /^!op/ do |m|
  m.channel.op(m.user)
end

For kick you need to do the same thing:

on :message, /somethingidontwantsaid/i do |m|
  m.channel.kick(m.user, reason = "Please, do not say that.")
end

I don't have the ability to check my syntax 100% at the moment, but take a look at the Message and Channel classes and some of the examples (I'd say the autovoice example should help you out a bit.) to help with these errors.

juderosen commented 10 years ago

Thanks. That worked wonders.