Coder Social home page Coder Social logo

matzbot's Introduction

**********************
   Plugin API Howto
 (so we don't forget)
**********************

Typical plugin:

  module MatzBot::Commands
    needs_gem 'hpricot' => [ :tinyurl, :get_tinyurl ]

    def tinyurl(data)
      say "Here it is! #{get_tinyurl(data.first)}"
    rescue
      say "No, no that's not gonna work."
    end

  private
    def get_tinyurl(url)
      return if url.empty?

      res = Net::HTTP.post_form(URI.parse('http://tinyurl.com/create.php'), { 'url' => url })
      doc = Hpricot(res.body)
      ((doc/:blockquote).last/:b).innerHTML
    end
  end

- New methods added to MatzBot::Commands show up as commands

- If you want to add methods which aren't bot commands, make them protected or private.

- Methods must accept one argument, an array of words said after the command.

- If you need to require a gem, use needs_gem like above.  Pass it the gem name and all
  the methods that depend on it.

- If you need to keep around data, use the `session' hash.
    session[:my_plugin] = true
    session[:my_plugin]

- You can use `reply' like say, except it will prefix your command with the user's name.
    <defunkt> hey bot
    <matzbot> defunkt: hey  # => using reply 'hey'

- You can use `pm' to send a private message to whoever made a request of you.  Use it like `say.'

- The above plugin would be triggered like this:
    <irc_dude> tinyurl http://myurl.com
    <matzbot> Here it is!  http://tinyurl.com/fz3

- You get these methods in the Commands API:
  - puts(string to say)
  - reply(string to say)
  - pm(sting to pm) [your bot must be ident'd on most networks for this to work]
  - action(string to emote)
  - config -- hash of runtime configuration options
  - socket -- direct access to the socket, if you need it

- Put plugins in ~/.matzbot and name them whatever.rb.

=> Evan Weaver && Chris Wanstrath
>> %w[ http://blog.evanweaver.com http://errtheblog.com ]

matzbot's People

Contributors

evanphx avatar

Stargazers

 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

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.