diff options
Diffstat (limited to 'gentoo-fixup.rb')
-rw-r--r-- | gentoo-fixup.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gentoo-fixup.rb b/gentoo-fixup.rb new file mode 100644 index 0000000..cd1ea2f --- /dev/null +++ b/gentoo-fixup.rb @@ -0,0 +1,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: |