Closed wedtm closed 13 years ago
This is when trying to import a simple plugin.
/Users/wedtm/.rvm/gems/ruby-1.9.2-p180/gems/cinch-1.1.3/lib/cinch/bot.rb:362:in `register_plugins': undefined method `plugins' for [TinyURL]:Array (NoMethodError) from /Users/wedtm/.rvm/gems/ruby-1.9.2-p180/gems/cinch-1.1.3/lib/cinch/bot.rb:409:in `start' from fred.rb:29:in `<main>' ~/Dropbox/code/fred >
require 'rubygems' #require 'bundler/setup' #Bundler.require require 'cinch' require 'nokogiri' require 'cgi' Dir[File.join('plugins', '*.rb')].each { |file| require "./" + file } bot = Cinch::Bot.new do configure do |c| c.server = "irc.esper.net" c.channels = ["#wedtm"] c.nick = "Fred" c.user = "Fred" c.plugins = [TinyURL] end on :message, "hello" do |m| m.reply "Hello, #{m.user.nick}" end on :message, /^hello (.+)/ do |m, args| m.reply "Hello 2, #{args[0]}" end end bot.start
require 'open-uri' require 'cinch' class TinyURL include Cinch::Plugin listen_to :channel def shorten(url) url = open("http://tinyurl.com/api-create.php?url=#{URI.escape(url)}").read url == "Error" ? nil : url rescue OpenURI::HTTPError nil end def listen(m) urls = URI.extract(m.message, "http") short_urls = urls.map { |url| shorten(url) }.compact unless short_urls.empty? m.reply short_urls.join(", ") end end end
It has to be c.plugins.plugins, not c.plugins. I know, at first that seems weird, but the reason for this is that we also have c.plugins.options
c.plugins.plugins
c.plugins
c.plugins.options
This is when trying to import a simple plugin.
fred.rb
plugins/tinyurl.rb