]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/greet.rb
plugin(lart): fix not save before load
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / greet.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: Greet Plugin
5 #
6 # Author:: Raine Virta <rane@kapsi.fi>
7 # Copyright:: (C) 2009 Raine Virta
8 # License:: GPL v2
9 #
10 # Description:: Greet people when they join a channel
11
12 class GreetPlugin < Plugin
13   Config.register Config::ArrayValue.new('greet.channels',
14     :desc => _("Greet people on these channels."),
15     :default => [])
16
17   Config.register Config::ArrayValue.new('greet.messages',
18     :desc => _("By default, greetings are fetched from lang files. You can use this to specify custom messages, use %s to represent a nick."),
19     :default => [])
20
21   Config.register Config::BooleanValue.new('greet.delay',
22     :desc => _("Greet with delay so that the greeting seems human-like."),
23     :default => false)
24
25
26   def join(m)
27     return if m.source == @bot.myself
28     return unless @bot.config['greet.channels'].include?(m.channel.to_s)
29
30     greeting = if @bot.config['greet.messages'].empty?
31       @bot.lang.get("hello_X")
32     else
33       @bot.config['greet.messages'].pick_one
34     end
35
36     msg = Proc.new { @bot.say m.channel, greeting % m.sourcenick }
37
38     if @bot.config['greet.delay']
39       @bot.timer.add_once(2+rand(3)) { msg.call }
40     else
41       msg.call
42     end
43   end
44 end
45
46 plugin = GreetPlugin.new