aboutsummaryrefslogtreecommitdiff
blob: cd1ea2fd054320af21c032db2f339cc6d8f53825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'set'
class Stack
  def initialize
    @hash = {}
  end

  def [](key)
    @hash[key] = [] unless @hash[key]
    @hash[key]
  end

  def contains?(key)
    @hash.has_key?(key)
  end

  def clear(key)
    @hash.delete(key)
  end
end

class GentooFixupPlugin < Plugin
  def initialize
    super
    @stack = Stack.new
  end

  def whois(m)
    nick = m.whois[:nick].downcase
    # need to see if the whois reply was invoked by this plugin
    return unless @stack.contains?(nick)
    #msg = "Real bot host:" + m.parse_channel_list.inspect
    channels = Set.new
    channels.merge(m.whois[:channels].compact) if m.whois.include?(:channels)
    #msg = "Real bot channels:" + m.whois.channels
    
    want_channels = Set.new(@bot.config['irc.join_channels'].compact)
    missing_channels = want_channels - channels
    s = missing_channels.to_a.join(', ')
    @bot.say 'robbat2|na', 'Fixing '+s
    @bot.say 'robbat2', 'Fixing '+s
    missing_channels.each do |chan|
      @bot.part(chan, "Fixing bot channels")
      @bot.join(chan)
    end

    @stack.clear(nick)
  end

  def fixup(m, params)
    nick = @bot.config['irc.nick']
    nick.downcase!
    @stack[nick] << m.replyto
    @bot.whois(nick)
  end

end
plugin = GentooFixupPlugin.new
plugin.map 'fixupjoin',
  :action => 'fixup',
  :auth_path => 'move'

# vim: et sts=2 ts=2 sw=2: