Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

268 lines (196 sloc) 6.554 kb

@title Migration Guide

@markup kramdown

Migration Guide

This document explains how to migrate between API incompatible versions of Cinch.

Migrating from 1.x to 2.x


New methods

Plugins have the following (new) instance and class methods, which you shouldn't and usually mustn't overwrite:

  • #bot
  • #config
  • #handlers
  • #synchronize
  • #timers
  • #unregister
  • ::call_hooks
  • ::check_for_missing_options
  • ::ctcp
  • ::ctcps
  • ::help=
  • ::help
  • ::hook
  • ::hooks
  • ::listen_to
  • ::listeners
  • ::match
  • ::matchers
  • ::plugin_name=
  • ::plugin_name
  • ::prefix=
  • ::prefix
  • ::react_on=
  • ::react_on
  • ::required_options=
  • ::required_options
  • ::set
  • ::suffix=
  • ::suffix
  • ::timer
  • ::timers

Note: The list does also include methods from prior versions.

Plugin options

Previously, plugins used a DSL-like way of setting options like the plugin prefix. This contradicts with the general idea of plugins being ordinary Ruby classes and also caused a lot of code and documentation smell.

Instead of having methods like #prefix double as both attribute getter and setter, options can now be set in two different ways: Using ordinary attribute setters or using the {Cinch::Plugin::ClassMethods#set #set} method.

Cinch 1.x

class MyPlugin
  include Cinch::Plugin

  prefix /^!/
  help "some help message"
  match /foo/
  def execute(m)
    # ...

Cinch 2.x, attribute setters

class MyPlugin
  include Cinch::Plugin

  self.prefix = /^!/   = "some help message"
  match /foo/
  def execute(m)
    # ...

Cinch 2.x, #set method

class MyPlugin
  include Cinch::Plugin

  set :prefix, /^!/
  set :help,   "some help message"
  match /foo/
  def execute(m)
    # ...

Cinch 2.x, #set method, alternative syntax

class MyPlugin
  include Cinch::Plugin

  set prefix: /^!/,
      help:   "some help message"
  match /foo/
  def execute(m)
    # ...

No more automatic matcher with the plugin's name

Cinch does not add a default matcher with the plugin's name anymore. If you've been relying on the following to work

class Footastic
  include Cinch::Plugin

  def execute(m)
    # this will triger on "!footastic"

you will have to rewrite it using an explicit matcher:

class Footastic
  include Cinch::Plugin

  match "footastic"
  def execute(m)
    # ...

No more default #execute and #listen methods

Plugins do not come with default #execute and #listen methods anymore, which means that specifying a matcher or listener without providing the required methods will always result in an exception.

Programmatically registering plugins

If you're using the API to register plugins on your own, you will have to use the new {Cinch::PluginList} class and its methods, instead of using Cinch::Bot#register_plugin or Cinch::Bot#register_plugins, which have been removed.

The PluginList instance is available via {Cinch::Bot#plugins}.


Logging in Cinch 2.x has been greatly improved. Instead of only supporting one logger and having all logging-relevant methods in {Cinch::Bot}, we've introduced the {Cinch::LoggerList} class, which manages an infinite number of loggers. Included with Cinch are the {Cinch::Logger::FormattedLogger formatted logger}, known from Cinch 1.x, and a new {Cinch::Logger::ZcbotLogger Zcbot logger}, a logger emulating the log output of Zcbot, a format which can be parsed by { pisg}.

Log levels

The old @config.verbose option has been replaced with a finely tunable log level system. Each logger has {Cinch::Logger#level its own level}, but it is also possible to {Cinch::LoggerList#level= set the level for all loggers at once}.

The available levels, in ascending order of verbosity, are:

  • fatal
  • error
  • warn
  • info
  • log
  • debug


All logging related methods (Cinch::Bot#debug et al) have been removed from the Bot class and instead moved to the loggers and the {Cinch::LoggerList LoggerList}. If you want to log messages from your plugins or handlers, you should use {Cinch::Bot#loggers} to access the {Cinch::LoggerList LoggerList} and then call the right methods on that. Alterntively you can also use the logging-related helper methods provided by {Cinch::Helpers}.

For more information on the logging architecture as well as examples on how to use it, check the {file:docs/ Logging readme}.

Prefix/suffix + string semantics

Behaviour of string prefixes and suffixes has been adapted to match that of matchers.

That means that if the prefix or suffix are strings, the ^ or $ anchor will be prepended/appened.

Hooks and their return value

Hooks now behave as filters. If a hook returns false, the message will not further be processed in a particular plugin.


All constants for numeric replies (e.g. RPL_INFO) have been moved from {Cinch} to {Cinch::Constants}. Thus Cinch::RPL_INFO becomes {Cinch::Constants::RPL_INFO}, same for all other numeric constants.

Bot configuration

Bot configuration now uses {Cinch::Configuration special classes} instead of OpenStructs. Thus, assignments like

configure do |c|
  c.timeouts ={:read => 240, :connect => 10})

are not possible anymore and have to be written as either

configure do |c|    = 240
  c.timeouts.connect = 10


configure do |c|
  c.timeouts.load({:read => 240, :connect => 10})

The second version is especially interesting to tools like { Cinchize}, which load the configuration from a YAML file. For more information see {file:docs/ Bot options}.

Various removed methods

See {file:docs/ What's changed}

on-handlers now only accepts one pattern

In previous versions, {Cinch::Bot#on} accepted a variable amount of patterns to match against. This feature was rarely used and has hence been removed. If you've been using constructs like

on :message, [/this/, /that/] do |m|
  # ...

you will have to rewrite them as follows:

b = lambda { |m|
  # ...

[/this/, /that/].each do |pattern|
  on :message, pattern, &b
Jump to Line
Something went wrong with that request. Please try again.