From 15068f45e239c6e8fb9149215935c0d97927c304 Mon Sep 17 00:00:00 2001 From: Dmitry Kim Date: Thu, 15 Mar 2007 01:12:23 +0000 Subject: + Added remotectl plugin and an example druby API client implementation --- bin/rbot-remote | 76 ++++++++++++++++++++++++++++++++++++++++++ data/rbot/plugins/remotectl.rb | 30 +++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 bin/rbot-remote create mode 100644 data/rbot/plugins/remotectl.rb diff --git a/bin/rbot-remote b/bin/rbot-remote new file mode 100755 index 00000000..37c7964a --- /dev/null +++ b/bin/rbot-remote @@ -0,0 +1,76 @@ +#! /usr/bin/ruby +require 'drb' +require 'optparse' + +#++ +# +# :title: RemoteCtl example script +# +# Author:: jsn (dmitry kim) +# Copyright:: (C) 2007 dmitry kim +# License:: in public domain + +user = nil +pw = nil +dst = nil +uri = 'druby://localhost:7268' + +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('-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: + + permissions set +remotectl for rmuser + 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 remote + alright + + 4) # 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 + +rbot = DRbObject.new_with_uri(uri) +id = rbot.delegate(nil, "remote login #{user} #{pw}")[:return] +puts "id is #{id.inspect}" +loop { + s = gets or break + s.chomp! + rv = rbot.delegate(id, "dispatch say #{dst} #{s}") or break + puts "rv is #{rv.inspect}" +} + diff --git a/data/rbot/plugins/remotectl.rb b/data/rbot/plugins/remotectl.rb new file mode 100644 index 00000000..b5b460fe --- /dev/null +++ b/data/rbot/plugins/remotectl.rb @@ -0,0 +1,30 @@ +#-- vim:sw=4:et +#++ +# +# :title: RemoteCtl plugin +# +# Author:: jsn (dmitry kim) +# Copyright:: (C) 2007 dmitry kim +# License:: in public domain +# +# Adds druby remote command execution to rbot. See 'bin/rbot-remote' for +# example usage. + +class RemoteCtlPlugin < Plugin + include RemotePlugin + + def remote_command(m, params) + s = params[:string].to_s + new_m = PrivMessage.new(@bot, @bot.server, m.source, @bot.nick, s) + @bot.plugins.delegate "listen", new_m + @bot.plugins.privmsg(new_m) + end +end + +me = RemoteCtlPlugin.new + +me.remote_map 'dispatch *string', + :action => 'remote_command', + :action_path => 'dispatch' + +me.default_auth('*', false) -- cgit v1.2.3