X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=bin%2Frbot-remote;h=29005f633b9ce473e6e4ca065c41c6990de4dfe3;hb=3ace72d5642284665fce2c33c99dfeb1b931b2c6;hp=353bb06d94d8ddb95c37b74b9c492306ecec274d;hpb=33f1c8ddc1f4c9f897f3b194a44faa1834f61566;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/bin/rbot-remote b/bin/rbot-remote index 353bb06d..29005f63 100755 --- a/bin/rbot-remote +++ b/bin/rbot-remote @@ -1,32 +1,38 @@ #! /usr/bin/ruby -require 'drb' + +require 'uri' +require 'net/http' require 'optparse' #++ # -# :title: RemoteCtl example script +# :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 -uri = 'druby://localhost:7268' +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 ') { |v| dst = 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 remotectl permission to your newly created remote user: + 2) # add a permission to say for your newly created remote user: - permissions set +remotectl for rmuser + allow rmuser to do say #channel message okies! - 3) # add specific permissions for the commands you want to allow via - # remote interface. for example, in this script we want 'say', - # 'action' and other basic commands to work: - - permissions set +basics::talk::do for rmuser - alright - - 4) # run the #{$0} and type something. the message should + 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' @@ -64,13 +63,14 @@ if !pw || !user || !dst exit 0 end -rbot = DRbObject.new_with_uri(uri) -id = rbot.delegate(nil, "remote login #{user} #{pw}")[:return] -puts "id is #{id.inspect}" +uri = URI(uri) +uri.user = user +uri.password = pw + loop { s = gets or break s.chomp! - rv = rbot.delegate(id, "dispatch say #{dst} #{s}") or break - puts "rv is #{rv.inspect}" + resp = Net::HTTP.post_form(uri, 'command' => [function, dst, s].join(' ')) + puts [resp.code, resp.message, resp.body].join("\t") }