Tutorial on plugins

« Tutorial Intro Tutorial 2 »


We start with a plugin that will greet you back when you greet butler.

code 1.1

def on_trigger answer("greetings to you too") end __END__ --- :trigger: en: greetings

dialog 1.1

yournick: butler, greetings
  butler: greetings to you too


Ruby stops interpreting a code file after __END__, in normal scripts data after __END__ is available in the constant DATA. In plugins for butler we use it to store metadata in YAML format.

Notice that the 'en' is indented by 2 spaces and not a tab or anything else

You might already have thought it: the 'en' stands for 'english'. It's possible to define the trigger for any language you like. When butler looks for what language will be explained later. Now that trigger 'greetings' tells butler to listen for invocations with the first word being 'greetings'. If he detects such a message, he calls the 'on_trigger' of that plugin. And don't worry, every plugin's 'on_trigger' method is in a separate class, even without you defining that class. So they won't interfere with each other.

« Tutorial Intro Tutorial 2 »

Valid XHTML, 2008-21-05 21:22 CEST