#! /usr/bin/ruby require 'uri' require 'net/http' require 'optparse' #++ # # :title: webserver dispatch example script # # Author:: jsn (dmitry kim) # Copyright:: (C) 2007 dmitry kim # License:: in public domain # Modified by:: Giuseppe "Oblomov" Bilotta # Copyright:: (C) 2020 Giuseppe Bilotta user = nil pw = nil dst = nil function = 'say' uri = 'http://localhost:7268/dispatch' opts = OptionParser.new opts.on('-u', '--user ', "remote user (mandatory)") { |v| user = v } opts.on('-p', '--password ', "remote user password (mandatory)") { |v| pw = v } opts.on('-d', '--destination ', "destination of the action (mandatory)") { |v| dst = v } opts.on('-f', '--function ', "function to trigger (e.g. say, notify), default: #{function}") { |v| function = v } opts.on('-r', '--uri ', "rbot url (#{uri})") { |v| uri = v } opts.on('-h', '--help', "this message") { |v| pw = nil } # sorry! opts.on('-a', '--about', "what it's all about.") { |v| puts < user create rmuser rmpw created botuser remote 2) # add a permission to say for your newly created remote user: allow rmuser to do say #channel message okies! 3) # run the #{$0} and type something. the message should # show up on your channel / arrive as an irc private message. [you@yourhost ~]$ ./bin/rbot-remote -u rmuser -p rmpw -d '#your-channel' hello, world! [you@yourhost ~]$ EOF exit 0 } opts.parse! if !pw || !user || !dst puts opts.to_s exit 0 end uri = URI(uri) uri.user = user uri.password = pw loop { s = gets or break s.chomp! resp = Net::HTTP.post_form(uri, 'command' => [function, dst, s].join(' ')) puts [resp.code, resp.message, resp.body].join("\t") }