Tutorial on plugins

« Tutorial 4 Tutorial 6 »


The version of 1.4 has a drawback. It never deletes any nicks, which will keep
a) the config-file growing and growing
b) butler from greeting people using the same nickname as somebody before
We want to counter that by purging long not seen people from the file.

code 1.5

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("welcome in #{channel}, #{nick}") plugin.config["seen"][nick] = Time.now end end


Plugin::every will run the block every n seconds. 7.days returns the amount of seconds in 7 days (7*24*3600). The block in the example deletes nicks stored in the config older than 7 days.
It only greets nicks not already in config["seen"] hash and enters newly greeted people there with the time when greeted (so the block can delete them if they become too old).

« Tutorial 4 Tutorial 6 »

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