From 0ea6cec493eb68fc4e660030eac14dd075bba640 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 18 Feb 2010 21:53:10 +0000 Subject: Fixup tricks. --- gentoo-fixup.rb | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 gentoo-fixup.rb (limited to 'gentoo-fixup.rb') 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: -- cgit v1.2.3-65-gdbad