]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/autorejoin.rb
plugin(oxford): moved to lexico.com, closes #13
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / autorejoin.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: Autorejoin
5
6 class AutoRejoinPlugin < Plugin
7   Config.register Config::BooleanValue.new('rejoin.insult',
8     :default => true,
9     :desc => "Determines if the bot will insult whoever kicked it, after rejoin")
10   Config.register Config::BooleanValue.new('rejoin.kick',
11     :default => false,
12     :desc => "Determines if the bot will kick whoever kicked it, after rejoin")
13   Config.register Config::ArrayValue.new('rejoin.no_kick_list',
14     :default => ["owner"],
15     :desc => "List of botusers that can kick the bot without being kicked")
16
17
18   def initialize
19     super
20     @should_kick = Hash.new
21   end
22
23   def help(plugin, topic="")
24     "performs an automatic rejoin if the bot is kicked from a channel"
25   end
26
27   def kick(m)
28     password = m.channel.mode[:k].value
29
30     if m.address?
31       if @bot.config['rejoin.kick'] and not @bot.config['rejoin.no_kick_list'].include? m.source.botuser.username
32         @should_kick[m.channel.downcase] = m.sourcenick
33       end
34       r = rand(10)
35       if r > 0
36         @bot.timer.add_once(r) {
37           @bot.join m.channel, password
38           @bot.say(m.channel, @bot.lang.get("insult") % m.sourcenick) if @bot.config['rejoin.insult']
39         }
40       else
41         @bot.join m.channel, password
42         @bot.say(m.channel, @bot.lang.get("insult") % m.sourcenick) if @bot.config['rejoin.insult']
43       end
44     end
45   end
46
47   def modechange(m)
48     # if we got opped on a channel we want to kick somebody from,
49     # do the kicking
50
51     # getting opped on a channel is a channel mode change, so bail out if this
52     # is not a channel mode change
53     return unless m.target.kind_of? Channel
54     # bail out if we are not op, too
55     return unless @bot.myself.is_op?(m.target)
56     # bail out if there's nobody to kick
57     to_kick = @should_kick.delete(m.target.downcase)
58     return unless to_kick
59     # kick the evil user that kicked us
60     @bot.kick m.target, to_kick, _("for kicking me out earlier")
61   end
62
63 end
64
65 plugin = AutoRejoinPlugin.new