class Sforwarder < Plugin def initialize super @links= @registry[:links]||Hash.new end def join_linked_channels @links.to_a.flatten.uniq.each{|channel| begin @bot.join '#test' rescue warn "Sforwarder :: joining #{channel} failed" end } @joined = true end def add_link m, params _in = params[:channel_in] _out = params[:channel_out] unless _in =~ /\#.+/ && _out =~ /\#.+/ m.reply "there is atleast one not valid channel name" return end @bot.join _in @bot.join _out @links[_in]||=Array.new unless @links[_in].include? _out @links[_in].push _out end @registry[:links]=@links m.reply "#{params[:channel_in]} => #{params[:channel_out]}" end def links_inspect m, params m.reply @links.inspect end def del_link m, params chain = params[:chain_name] if @links.keys.include? chain @links[chain]=[] @registry[:links]=@links m.reply "deleted the chain for channel #{chain}" else m.reply "no chain called #{chain} try 'inspect forwarder'" end end def message m join_linked_channels unless @joined if m.channel && @links.keys.include?(channel=m.channel.name) @links[channel].each{|_out| @bot.say _out, "<_#{m.source}@#{channel}_> #{m.plainmessage}" } end end def help plugin, topic='' case topic when 'forward' "forward #channel_in => #channel_out\t: adding channel_out to #channel_in's forward chain" when 'delete forward chain' "delete forward chain #channel\t: delet the forwarding rule for #channel" when 'inspect forwarder' "inspect forwarder\t: shows you all the forwarding rules" else "this is a simple forwarder, it can forward any message, from any channel to any other channel on the server.\nOfcourse the bot must be allowed to be present in both of them, there won't be any error message if joining a channel fails password protected channels are not supported yet, I also don't understand the auth_path option so it's possible for everyone to edit everything(what's not too bad I think most people are good :) )" end end end plugin = Sforwarder.new plugin.map "forward :channel_in => :channel_out", :action => 'add_link', :auth_path => 'edit' plugin.map "delete forward chain :chain_name", :action => 'del_link', :auth_path => 'edit' plugin.map "inspect forwarder", :action => 'links_inspect', :auth_path => 'view'