Tutorial on plugins

« Lesson 2 Lesson 4 »

Intent

We want it to automatically greet people when they join the channel.

code 1.3

extend OnHandlers def on_join(listener, nick, channel) answer("welcome in #{channel}, #{nick}") end

dialog 1.3

        *yournick joins #the-channel
butler: welcome in #the-channel, yournick

Explanation

OnHandlers installs a hook which looks out for on_* methods it knows about. If it detects such a method, it installs a callback that instanciates the plugin on a matching message - in our case, the on_join will be triggered on :JOIN mesages - and calls the method responsible for it. The callback is passed in as argument, that way you can disable it if you whish. For your convenience, OnHandlers invokes the methods with useful arguments. That's why even though @message is set in on_join too, we don't need it. If you want to see all possible OnHandlers and their arguments, take a look at the OnHandlers cheatsheet.

« Lesson 2 Lesson 4 »

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