Giter Club home page Giter Club logo

isaac's Introduction

Isaac - the smallish DSL for writing IRC bots

Features

  • Wraps parsing of incoming messages and raw IRC commands in simple constructs.

  • Hides all the ugly regular expressions of matching IRC commands. Leaves only the essentials for you to match.

  • Takes care of dull stuff such as replying to PING-messages and avoiding excess flood.

Getting started

An Isaac-bot needs a few basics:

require 'isaac'
configure do |c|
  c.nick    = "AwesomeBot"
  c.server  = "irc.freenode.net"
  c.port    = 6667
end

That’s it. Run ruby bot.rb and it will connect to the specified server.

Connecting

After the bot has connected to the IRC server you might want to join some channels:

on :connect do
  join "#awesome_channel", "#WesternBar"
end

Responding to messages

Joining a channel and sitting idle is not much fun. Let’s repeat everything being said in these channels:

on :channel do
  msg channel, message
end

Notice the channel and message variables. Additionally nick and match is available for channel-events. nick being the sender of the message, match being an array of captures from the regular expression:

on :channel, /^quote this: (.*)/ do
  msg channel, "Quote: '#{match[0]}' by #{nick}"
end

If you want to match private messages use the +on :private+ event:

on :private, /^login (\S+) (\S+)/ do
  username = match[0]
  password = match[1]
  # do something to authorize or whatevz.
  msg nick, "Login successful!"
end

You can also pass the RegExp captures as block arguments:

on :channel, /catch this: (.*) and this: (.*)/ do |first, last|
  # `first` will contain the first regexp capture,
  # `last` the second.
end

Defining helpers

Helpers should not be defined in the top level, but instead using the helpers-constructor:

helpers do
  def rain_check(meeting)
    msg nick, "Can I have a rain check on the #{meeting}?"
  end
end

on :private, /date/ do
  rain_check("romantic date")
end

Errors, errors, errors

Errors, as specified by RFC 1459, can be reacted upon as well. If you e.g. try to send a message to a non-existant nick you will get error 401: “No such nick/channel”.

on :error, 401 do
  # Do something.
end

Available variables: nick and channel.

Contribute

The source is hosted at GitHub: github.com/ichverstehe/isaac

License

Copyright © 2009 Harry Vangberg <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

isaac's People

Contributors

its-danny avatar kuadrosx avatar mikker avatar syd avatar tbuehlmann avatar titanous avatar vangberg avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.