Tutorial on plugins

« Tutorial 1 Tutorial 3 »

Intent

Personalize the greeting. Let butler say the name of the one he greets back.

code 1.2

def on_trigger answer("greetings, #{@message.from.nick}") end __END__ :trigger: en: greetings

dialog 1.2

yournick: butler, greetings
  butler: greetings, yournick

Explanation

When a plugin is invoked, butler creates an instance of the plugin. The on_trigger method is an instance method of that class and is subsequently called. If the plugin was invoked as a result of a message, it sets the @message instance variable. That means we can use @message to see what kind of message it was, who sent it, where it was sent to and all other kinds of things you can query a Butler::IRC::Message. Here we use it to get the nickname of the sender.

« Tutorial 1 Tutorial 3 »

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