#-- vim:sw=2:et #++ # # :title: IRC Gateway Plugin for rbot # # Author:: Matthias Hecker # # Copyright:: (C) 2009 Matthias Hecker # # License:: GPL v2 # # Version:: v01 # # The IRC-Gateway Plugin uses the RBot Remote Interface # to connect 2 Bots and forward the Messages from one Channel # to another. You must change the default Port(7268) # of one of them: # config set remote.port 7269 # after that setup the ircgw settings... # config search ircgw # require 'drb' class IrcGw < Plugin include RemotePlugin Config.register Config::StringValue.new('ircgw.host', :default => 'localhost', :desc => 'rBot-Remote Hostname') Config.register Config::IntegerValue.new('ircgw.port', :default => 7268, :desc => 'rBot-Remote Port') Config.register Config::StringValue.new('ircgw.authpw', :default => '', :desc => 'rBot-Remote Auth Password') Config.register Config::StringValue.new('ircgw.local_channel', :default => '', :desc => 'The Source Channel') Config.register Config::StringValue.new('ircgw.remote_channel', :default => '', :desc => 'The Destination Channel') Config.register Config::StringValue.new('ircgw.network', :default => '', :desc => 'Display this Network as Source') def forward_msg(forward_msg) remote_host = @bot.config['ircgw.host'] remote_port = @bot.config['ircgw.port'] remote_auth = @bot.config['ircgw.authpw'] local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] remote_network = @bot.config['ircgw.network'] # maybe in a thread # the problem is that the order of the messages sometimes go wrong # Thread.new do rbot = DRbObject.new_with_uri("druby://#{remote_host}:#{remote_port}") id = rbot.delegate(nil, "remote login owner #{remote_auth}")[:return] rbot.delegate(id, "dispatch action #{remote_channel} #{forward_msg}") # end end def message(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] remote_network = @bot.config['ircgw.network'] return if m.address? return if remote_channel.empty? return if not m.channel.to_s == local_channel.to_s if remote_network.empty? then src = "#{m.sourcenick}" else src = "#{m.sourcenick}@#{remote_network}" end if m.action? then src = "* #{src}" else src = "(#{src})" end forward_msg("#{src} #{m.message}") end def nick(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] return if remote_channel.empty? forward_msg("#{m.oldnick} is now known as #{m.newnick}") end def join(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] return if remote_channel.empty? return if not m.channel == local_channel forward_msg("#{m.sourcenick} has joined #{m.channel}") end def part(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] return if remote_channel.empty? return if not m.channel == local_channel forward_msg("#{m.sourcenick} has left #{m.channel}") end def quit(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] return if remote_channel.empty? return if not m.channel.to_s == local_channel forward_msg("#{m.sourcenick} has quit (#{m.message})") end def kick(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] return if remote_channel.empty? return if not m.channel.to_s == local_channel forward_msg("#{m.sourcenick} has kicked #{m.target} from #{m.channel} (#{m.message})") end def topic(m) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] return if remote_channel.empty? return if not m.channel.to_s == local_channel forward_msg("#{m.sourcenick} has changed the topic to: #{m.topic}") end def rwho(m, params) local_channel = @bot.config['ircgw.local_channel'] remote_channel = @bot.config['ircgw.remote_channel'] remote_network = @bot.config['ircgw.network'] return if remote_channel.empty? if remote_network.empty? then src = "#{local_channel}" else src = "#{local_channel}@#{remote_network}" end channels = 'foobar' @bot.server.channels.each_index do |i| if @bot.server.channels[i].name.to_s == local_channel then channels = @bot.server.channels[i].users.join ' ' break end end forward_msg("in #{src}: #{channels}") end def who(m, params) remote_host = @bot.config['ircgw.host'] remote_port = @bot.config['ircgw.port'] remote_auth = @bot.config['ircgw.authpw'] rbot = DRbObject.new_with_uri("druby://#{remote_host}:#{remote_port}") id = rbot.delegate(nil, "remote login owner #{remote_auth}")[:return] rbot.delegate(id, "ircgw rwho") end end plugin = IrcGw.new plugin.map 'ircgw who', :action => 'who' plugin.remote_map 'ircgw rwho', :action => 'rwho'