Code Monkey home page Code Monkey logo

cinch's Introduction

Cinch - The IRC Bot Building Framework

The Cinch project is no longer maintained. No new features will be added, and no bugs will be fixed. The repository has been archived. If you wish to continue developing Cinch, please fork the project. I am not accepting new maintainers for this project.

Description

Cinch is an IRC Bot Building Framework for quickly creating IRC bots in Ruby with minimal effort. It provides a simple interface based on plugins and rules. It's as easy as creating a plugin, defining a rule, and watching your profits flourish.

Cinch will do all of the hard work for you, so you can spend time creating cool plugins and extensions to wow your internet peers.

For general support, join #cinch channel on Freenode server (irc://irc.freenode.org/cinch) โ€“ but please don't bring any bots.

Installation

RubyGems

You can install the latest Cinch gem using RubyGems

gem install cinch

GitHub

Alternatively you can check out the latest code directly from Github

git clone http://github.com/cinchrb/cinch.git

Example

Your typical Hello, World application in Cinch would go something like this:

require 'cinch'

bot = Cinch::Bot.new do
  configure do |c|
    c.server = "irc.freenode.org"
    c.channels = ["#cinch-bots"]
  end

  on :message, "hello" do |m|
    m.reply "Hello, #{m.user.nick}"
  end
end

bot.start

More examples can be found in the examples directory.

Features

Documentation

Cinch provides a documented API, which is online for your viewing pleasure here.

Object Oriented

Many IRC bots (and there are, so many) are great, but we see so little of them take advantage of the awesome Object Oriented Interface which most Ruby programmers will have become accustomed to and grown to love.

Well, Cinch uses this functionality to its advantage. Rather than having to pass around a reference to a channel or a user, to another method, which then passes it to another method (by which time you're confused about what's going on) -- Cinch provides an OOP interface for even the simpliest of tasks, making your code simple and easy to comprehend.

Threaded

Unlike a lot of popular IRC frameworks, Cinch is threaded. But wait, don't let that scare you. It's totally easy to grasp.

Each of Cinch's plugins and handlers are executed in their own personal thread. This means the main thread can stay focused on what it does best, providing non-blocking reading and writing to an IRC server. This will prevent your bot from locking up when one of your plugins starts doing some intense operations. Damn that's handy.

Plugins

That's right folks, Cinch provides a modular based plugin system. This is a feature many people have bugged us about for a long time. It's finally here, and it's as awesome as you had hoped!

This system allows you to create feature packed plugins without interfering with any of the Cinch internals. Everything in your plugin is self contained, meaning you can share your favorite plugins among your friends and release a ton of your own plugins for others to use

Want to see the same Hello, World application in plugin form? Sure you do!

require 'cinch'

class Hello
  include Cinch::Plugin

  match "hello"

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

bot = Cinch::Bot.new do
  configure do |c|
    c.server = "irc.freenode.org"
    c.channels = ["#cinch-bots"]
    c.plugins.plugins = [Hello]
  end
end

bot.start

Note: Plugins take a default prefix of /^!/ which means the actual match is !hello.

More information can be found in the {Cinch::Plugin} documentation.

Numeric Replies

Do you know what IRC code 401 represents? How about 376? or perhaps 502? Sure you don't (and if you do, you're as geeky as us!). Cinch doesn't expect you to store the entire IRC RFC code set in your head, and rightfully so!

That's exactly why Cinch has a ton of constants representing these numbers so you don't have to remember them. We're so nice.

Pretty Output

Ever get fed up of watching those boring, frankly unreadable lines flicker down your terminal screen whilst your bot is online? Help is at hand! By default, Cinch will colorize all text it sends to a terminal, meaning you get some pretty damn awesome readable coloured text. Cinch also provides a way for your plugins to log custom messages:

on :message, /hello/ do |m|
  debug "Someone said hello"
end

Contribute

Love Cinch? Love Ruby? Love helping? Of course you do! If you feel like Cinch is missing that awesome jaw-dropping feature and you want to be the one to make this magic happen, you can!

Please note that although we very much appreciate all of your efforts, Cinch will not accept patches in aid of Ruby 1.8 compatibility. We have no intention of supporting Ruby versions below 1.9.1.

Fork the project, implement your awesome feature in its own branch, and send a pull request to one of the Cinch collaborators. We'll be more than happy to check it out.

cinch's People

Contributors

achiurizo avatar britishtea avatar causal-agent avatar cysioland avatar dcu avatar defman21 avatar didlix avatar dominikh avatar elberet avatar gentlejolt avatar gizmokid2005 avatar hcolomb avatar kamilaborowska avatar kyrylo avatar leejarvis avatar makzu avatar mpapis avatar nevir avatar nickrw avatar ochaochaocha3 avatar paradox460 avatar petertseng avatar phlipper avatar rennex avatar scoopr avatar splaspood avatar thedjinn avatar thenotary avatar tilegg avatar ymendel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cinch's Issues

Do not load plugin if it misses config options

Feature request to have the bot spit out some warnings and not run the plugin if it misses some pre-defined config options.

Say that you have a plugin that requires some options :foo and :bar that is actually required for the bot to run. An API-key or similar. The main problem here is that sometime you need this to do proper request against a web service or similar and and it would be nice to have a standardized way to do this instead of having to implement the same thing in each plugin.

Might look something like:

require_options [:foo, :bar]

And if those config options isn't set then the bot would just warn about it and not run the plugin.

Quit raises exception

Hey,

when I use @bot.quit I get an exception as listed below

on :message, "!quit" do |m|
@bot.quit
end

/Users/nils/.rvm/gems/ruby-1.9.2-p180/bundler/gems/cinch-b0a7419e3e09/lib/cinch/bot.rb:267:in dispatch' /Users/nils/.rvm/gems/ruby-1.9.2-p180/bundler/gems/cinch-b0a7419e3e09/lib/cinch/irc.rb:104:inblock in start_reading_thread'
NoMethodError: undefined method values' for #<Cinch::HandlerList:0x0000010152b730> from /Users/nils/.rvm/gems/ruby-1.9.2-p180/bundler/gems/cinch-b0a7419e3e09/lib/cinch/irc.rb:105:inblock in start_reading_thread'

Dynamically reload bot

Is there a built-in way to reload the bot (without having to kill the ruby process and start a new one)? I'd like to test my code, but I'm getting klined due to rapid reconnects. Not ideal.

Plugins not working for me

I copied and pasted (changed irc server) the plugin hello example and it does not work the non plugin hello example works fine

Plugin does not get executed

Hi!

I Just tried the "Hello world" example with Cinch 1.1.3 and ruby 1.9.3 (the example is at: https://github.com/cinchrb/cinch/blob/master/examples/plugins/hello.rb). It is my understanding that the bot should reply to "hello" messages, but it does not, although it seems to register the plugin fine.

[2011/09/05 14:12:43.394] !! [on handler] Registering handler with pattern `#<Cinch::Pattern:0x00000001d95138@prefix=nil, @pattern=//, @suffix=nil>`, reacting on `connect`
[2011/09/05 14:12:43.394] !! [plugin] hello: Registering executor with pattern `#<Cinch::Pattern:0x00000001d94350@prefix=/^!/, @pattern=/hello/, @suffix=nil>`, reacting on `message`
[2011/09/05 14:12:43.394] !! [on handler] Registering handler with pattern `#<Cinch::Pattern:0x00000001d94350@prefix=/^!/, @pattern=/hello/, @suffix=nil>`, reacting on `message`
[2011/09/05 14:12:43.394] !! Connecting to irc.freenode.org:6667
# etc. ...

ruby -v is ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-linux]

I'm not really sure what's wrong here, as I haven't had a lot of time to investigate past this.
HTH.

Add a function for notice

For now I'm using and there is no known (to me) other method of doing this:
@bot.raw "NOTICE #{m.user.nick} :#{text}"
But I would like to see something like
m.user.notice text
or
m.notice text
This is not that hard to implement
def notice(text)
@bot.raw "NOTICE #{nick} :#{text}"
end
and would make bots written with cinch even more beautiful.

I just wonder if @bot.raw is thread safe?

New gem release

When are you guys going to release the next cut of cinch? Are there open issues that need to be resolved before you are wiling to cut a new release?

code converter not found (UTF-8 to UTF-8) (Encoding::ConverterNotFoundError)

Im using Cinch 1.0.1 and rails 3.0.0.rc and ruby 1.9.2-p0

and i get the following error:

!! Connecting to irc.freenode.org:6667
<< NICK TestmeBot
!! /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/irc.rb:46:in `gets': code converter not found (UTF-8 to UTF-8) (Encoding::ConverterNotFoundError)
!!  /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/irc.rb:46:in `block in connect'
<< USER TestmeBot 0 * :cinch
fatal: deadlock detected
    from /home/name/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:185:in `sleep'
    from /home/name/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:185:in `block in pop'
    from <internal:prelude>:10:in `synchronize'
    from /home/name/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:180:in `pop'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/message_queue.rb:52:in `process!'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/irc.rb:60:in `connect'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/bot.rb:404:in `start'
    from (irb):1
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/railties-3.0.0.rc/lib/rails/commands/console.rb:44:in `start'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/railties-3.0.0.rc/lib/rails/commands/console.rb:8:in `start'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/railties-3.0.0.rc/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Im just testing it out, and I have a file called lib/bot.rb:

class Bot
  def self.bot
    bot = Cinch::Bot.new do
      configure do |c|
        c.server   = "irc.freenode.org"
        c.nick     = "TestmeBot"
        c.channels = ["#cinch"]
      end

      on :message, /^!msg (.+?) (.+)/ do |m, who, text|
        User(who).send text
      end
    end
  end
end

if I do $ rails console
and do Bot.bot.start I get the message above. If I run it outside of rails with just `irb' it runs perfect. I don't know if its rails 3 or something eternal stuff with rails and cinch that makes it go boom :(

Unable to Join Channels

I've attempted to do the following

irc = Cinch.Setup :verbose => true do
server "irc.gamesurge.net"
nick "xperienceBot"
channels %w(#xperience)
end

irc.run

but the bot doesn't join any channels. I have used this library before and had no problems.

Dynamic "plugin" discovery

I haven't fully thought this out, but it'd be nice if you could point your ruby code at a directory full of .rb files, and they would:

  • Magically be required
  • The classes, that include Cinch::Plugins, would be added to the plugins list.
  • !help would show all commands listed, or at least all plugins.
  • !help would be routed to the right plugin for more information.

Ciao!

Won't work with ISO-2022-JP

When running Cinch with encoding = "iso-2022-jp", Ruby rises Encoding::CompatibilityError. The cause is probably because ISO-2022-JP is not compatible with ASCII. (ISO-2022-JP is commonly used by Japanese in IRCNet.)

(Error message)
/Users/yasu/devel/cinch/lib/cinch/message_queue.rb:68:in `process!': incompatible character encodings: ISO-2022-JP and UTF-8 (Encoding::CompatibilityError)

(Quick fix)
It works, but I'm not sure whether if it is suitable fix.
force_encoding("binary") is required for ASCII incompatible encoding to work.
https://gist.github.com/1528729

Multiple bots and threads

My application produces a lot of messages and speed is important, but there is a spam limit for the server. One way to get around this is to have n + 1 bots, with the n bots dedicated to sending the messages. I have tried this by running each bot in its own thread, with weird results.

  • First bot works fine.
  • Other bots connect to the server with no problem.
  • Other bots do not join any channels.
  • Upon messaging one of the other bots, the first one replies instead!

I am sure I can find ways around this problem, but the fix may be simple (I haven't been able to find it). Thanks for the awesome framework.

Unintended log output

Following message is shown even if loggers.level is set to higher one (such as :warn) in the block associated with Cinch::Bot.new. The reason is that @loggers.level is overwritten just before registering on-connect handler in Cinch::Bot#initialize.

[2012/01/25 00:06:20.225] !! [on handler] Registering handler with pattern `#<Cinch::Pattern:0x00000100860be0 @prefix=nil, @pattern=//, @suffix=nil>`, reacting on `connect`
require "cinch"

bot = Cinch::Bot.new do
  loggers.level = :warn # won't work
  configure do |c|
    c.server = "localhost"
    c.port = 6690
    c.channels = ["#FatechanMoe"]
  end
end
bot.loggers.level = :warn # works!
bot.start

undefined method `irc_downcase'

When I try to call opped?, I get an error:

!! /home/alex/tf2.pug.na-IRC-bot/cinch/user.rb:39:in find_ensured': undefined methodirc_downcase' for #Cinch::Message:0x9ab8cf4 (NoMethodError)

Am I doing something wrong or is this a bug?

Thanks.

*Auth* check support for Unreal/Aitvaras network

The network I'm using returns a line like this one when whoising someone:
13:49:47 aitvaras -- | [txdv] is a registered nick
this occures only when the nick is registered AND identified. I guess that is not the raw format is different, I'll look it up.

fall-through reply

When the bot receives a message that no plugin has responded to, it would be great if there was a way to supply a response message.

Test coverage + contribution

Hi,
i found some problems when I tried to test my cinch plugins (no clean api for testing), so I'm trying to use master version, but I found bug there and maybe there is more. So I would like to ask, do you consider some kind of test/spec coverage? Its hard to contribute a project and do not break anything. But from what I see there is no spec or tests.

Btw bug is https://github.com/cinchrb/cinch/blob/master/lib/cinch/handler_list.rb#L38
type is symbol, but passing symbol to match, blows because it expects integer

timer.rb NoMethodError

Hey, I got this error:

/usr/local/rvm/gems/ruby-1.9.2-p290/bundler/gems/cinch-1e606cd6a5d9/lib/cinch/timer.rb:47:in block (3 levels) in start': undefined methodrescue_exception' for #Cinch::Timer:0xa609fdc (NoMethodError)

callback to setup the plugin before executing it

in my bot I would like to configure the plugins depending on some parameters (say the channel). for example if I want to setup the timezone and translations(i18n) per channel the callback would be like this:

def before_executing_a_plugin(m)
  if m.channel && m.channel.name == "#colombia"
    Time.zone = "Bogota" #this is thread-safe
    I18n.locale = :es
  end
end

the callback should be called in the thread in which the actual plugin callback is called

Bad colorcode escaping

The message was: [01:06:22] DEAD opa;): wh

The loggeroutput:

:six!~[email protected] PRIVMSG #six : DEAD 04opa;): wh

in the original message opa was colored red, so colorcode04, but it is not escaped.

(feature request) print regexes with .source instead of to_s

def spf_regex(r)
  case r
  when Regexp
    return "/#{r.source}/"
  when String
    return r
  end
end

plugin.rb:line 128

bot.debug ("[plugin] #{plugin_name}: Registering executor with pattern `#{spf_regex(pattern.pattern)}`, reacting on `#{react_on}`") if bot.config.verbose

Helper methods not available from plugins?

In my bot:

helpers do
  def shutup?
    @shutup = false if @shutup_expire <= @shutup
    !!@shutup
  end 
end

And in a plugin:

m.reply @factoids[matches[2].downcase] unless @bot.shutup?

But when running I get:

factoids.rb:31:in `listen': undefined method `shutup?' for #<Cinch::Bot:0x000000028ee098> (NoMethodError)

Am I misunderstanding how helpers work or is this a bug? I thought it would define the methods in the context of the bot object?

Example of writing tests

It would be nice to have an example for writing tests for a cinch-bot. Preferably in rspec, but anything would be nice.

(feature request) config.logger.log_prefix

if I could get lines like

!! Connecting to irc.freenode.net:6667
<< NICK

to come as

MyBot:Cinch: !! Connecting to irc.freenode.net:6667
MyBot:Cinch: << NICK 

I would be even more happy with cinch :)

bot.quit gives deadlock error

When running the following code

require 'cinch'

bot = Cinch::Bot.new do
    configure do |c|
        c.nick = "IgorBot"
        c.server = "irc.freenode.org"
        c.channels = ["#mybotchannel"]
    end

    # quit
    on :message, "!quit" do |m|
        bot.quit
    end
end

bot.start

and sending the !quit command, I receive following error:

/home/igor/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:185:in sleep': deadlock detected (fatal) from /home/igor/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:185:inblock in pop'
from internal:prelude:10:in synchronize' from /home/igor/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:180:inpop'
from /home/igor/.rvm/gems/ruby-1.9.2-p0/gems/cinch-1.0.2/lib/cinch/message_queue.rb:52:in process!' from /home/igor/.rvm/gems/ruby-1.9.2-p0/gems/cinch-1.0.2/lib/cinch/irc.rb:58:inconnect'
from /home/igor/.rvm/gems/ruby-1.9.2-p0/gems/cinch-1.0.2/lib/cinch/bot.rb:404:in start' from mybot.rb:12:in

'

Feature: method to send message to channel

The simplest way to send message to channel I found isn't very elegant:

class Cinch::Base
  def announce_on_all_channels( msg )
    channels.each do | channel |
      process(":[email protected] PRIVMSG #{channel} :!say #{msg}")
    end
  end
end

bot = Cinch.setup :verbose => true

bot.plugin("say :text") do |m|
  m.reply m.args[:text]
end

cinch is not thread-safe

it can fail if you use threads in plugins.
actually I think plugins(rules) should be executed in threads and maybe allow to set a timeout option

something like

Timeout.timeout(timeout_option) do
Thread.start do
blk.call(...)
end
end

periodic reply

hi! i just started using this gem and it's awesome!

I do have a question though. Is it possible to make the bot send a message to a channel periodically? Because right now the bot is only triggered through the plugin method (i.e. when someone sends a message to a channel)

would be glad for info on this. thanks!

Cinch cannot attempt to reconnect if a network connection is unavailable

When the bot times out (due to either the internet going out due to power outage, or some other thing that causes it), it attempts to reconnect, however the process quits instead of retrying. (In the current Cinch code as of 2011-08-23 1:28 PM ADT)

An example of the error is shown below:

[2011/08/23 11:10:40.665] << PING 0
[2011/08/23 11:10:59.618] !! C:/Ruby192/lib/ruby/1.9.1/openssl/buffering.rb:145:in `sysread_nonblock': An existing connection wa
s forcibly closed by the remote host. (Errno::ECONNRESET)
[2011/08/23 11:10:59.620] !!    C:/Ruby192/lib/ruby/1.9.1/openssl/buffering.rb:145:in `read_nonblock'
[2011/08/23 11:10:59.621] !!    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:135:in `rbuf_fill'
[2011/08/23 11:10:59.622] !!    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
[2011/08/23 11:10:59.622] !!    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
[2011/08/23 11:10:59.623] !!    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:89:in `block in start_reading_t
hread'
Deprecation warning: Beginning with version 1.2.0, Bot#dispatch should not be used anymore.
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/bot.rb:267:in `dispatch'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:104:in `block in start_reading_thread'
[2011/08/23 11:11:09.843] !! Waiting 1 seconds before reconnecting
[2011/08/23 11:11:10.844] !! Connecting to irc.freenode.net:6697
[2011/08/23 11:11:11.469] !! C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:34:in `initialize': getaddrinfo: N
o such host is known.  (SocketError)
[2011/08/23 11:11:11.470] !!    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:34:in `new'
[2011/08/23 11:11:11.471] !!    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:34:in `block in connect'
[2011/08/23 11:11:11.472] !!    C:/Ruby192/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
[2011/08/23 11:11:11.472] !!    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:33:in `connect'
[2011/08/23 11:11:11.473] !!    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:140:in `start'
[2011/08/23 11:11:11.474] !!    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/bot.rb:338:in `start'
[2011/08/23 11:11:11.475] !!    g:/bot/bot_base.rb:93:in `<main>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:205:in `message': undefined method `queue' for nil:NilClass (No
MethodError)
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:79:in `send_login'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/irc.rb:141:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/cinch-1.1.3/lib/cinch/bot.rb:338:in `start'
        from g:/bot/bot_base.rb:93:in `<main>'

`register_plugins': undefined method `plugins' while trying a simple plugin.

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 > 

fred.rb

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

plugins/tinyurl.rb

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

FormattedLogger#log doesn't work with message kind :generic

log method never set prefix when message kind is :generic tho it's the default.
crash in 'lib/cinch/logger/formatted_logger.rb', line 55

[2011/04/12 02:33:32.088] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/logger/formatted_logger.rb:55:in block (2 levels) in log': undefined method+' for nil:NilClass (NoMethodError)
[2011/04/12 02:33:32.088] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/logger/formatted_logger.rb:31:in each' [2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/logger/formatted_logger.rb:31:inblock in log'
[2011/04/12 02:33:32.089] !! internal:prelude:10:in synchronize' [2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/logger/formatted_logger.rb:29:inlog'
[2011/04/12 02:33:32.089] !! /home/max/Documents/dev/tornbot/plugins/control.rb:30:in join' [2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/plugin.rb:207:incall'
[2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/plugin.rb:207:in block (2 levels) in __register_with_bot' [2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/bot.rb:637:ininstance_exec'
[2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/bot.rb:637:in block (2 levels) in invoke' [2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/bot.rb:636:incatch'
[2011/04/12 02:33:32.089] !! /home/max/.rvm/gems/ruby-1.9.2-p180@tornbot/gems/cinch-1.1.2/lib/cinch/bot.rb:636:in `block in invoke'

Should plugins be rewritten or extended when their rules are duplicated

At the moment, when defining an already existing rule the body (or block) of the plugin moves into an Array with the rest of the already defined blocks. Meaning a plugin could look like this:

:foo => [Proc, Proc, Proc]

Of course that's a dumbed down example. I've been thinking of whether plugins should be overwritten or extended when they're redefined. This means that the loading of plugins which may exist in external resources could be dynamically reloaded and the initial plugin body would be replaced by a new block.

Anyone have any thoughts on this?

Action message API

There these thingies called action messages, when you write /me
I would like to have some API for them, since there were none, I wrote myself some:

class Cinch::Message
  def action?
    return false if message == nil
    return ctcp_message.starts_with?("ACTION ")
  end

  def action_message
    return message.split(" ")[1..-1].join(" ")
  end
end

But I guess this is an ugly hack and we want to see something more viable!

can I use cinch to build and extend an irc logger?

Can I use cinch to build and extend an irc logger?

I've been using a very old Perl IRC logger http://www.dajobe.org/software/logger/ for logging conversations on the #otrunk channel on freenode -- but it doesn't work very well and I know Ruby not Perl.

I'm not very familiar with irc bot programming but creating a logger out of a mashup of sinatra/rack and cinch might be pretty strait-forward -- and perhaps an example is already around somewhere.

Thanks for any advice/feedback.

Bot wont join channels

If a server doesn't pass response 376, the bot will not join any channel you pass to it via channels.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.