Tutorial on plugins

« Tutorial 5

Intent

Our greeter plugin is so good, another user of butler wants it. But he wants to use it in his local, non-english speaking channel. We want a common code base so fixes in the code can be shared. The solution is localizable strings.

code 1.6

extend OnHandlers configuration( "seen" => {} ) every 7.days do now = Time.now @config["seen"] = @config["seen"].reject { |key, value| now-value > 7.days } end def on_join(listener, nick, channel) unless plugin.config["seen"][nick] then answer(:greetings, :channel => channel, :nick => nick) plugin.config["seen"][nick] = Time.now end end __END__ --- :strings: :greetings: en: "Welcome in <%= channel %>, <%= nick %>." de: "Willkommen in <%= channel %>, <%= nick %>."

Explanation

If you use answer with a Symbol, it will look up the name in the strings-metadata. With single-file plugins, you can use the __END__ part in the ruby file to place yaml-data with all metadata-sections. Also take a look at Metadata cheatsheet to see a list of all metadata.
You should use that even if you write your plugin only for a single language. Simply because it makes it possible for other users to just add another language to your plugin.

« Tutorial 5

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