7 # :title: RemoteCtl example script
9 # Author:: jsn (dmitry kim) <dmitry dot kim at gmail dot org>
10 # Copyright:: (C) 2007 dmitry kim
11 # License:: in public domain
16 uri = 'druby://localhost:7268'
18 opts = OptionParser.new
19 opts.on('-u', '--user <user>', "remote user (mandatory)") { |v| user = v }
20 opts.on('-p', '--password <pw>', "remote user password (mandatory)") { |v| pw = v }
21 opts.on('-d', '--destination <user or #channel>') { |v| dst = v }
22 opts.on('-r', '--uri <drb uri>', "rbot url (#{uri})") { |v| uri = v }
23 opts.on('-h', '--help', "this message") { |v| pw = nil } # sorry!
24 opts.on('-a', '--about', "what it's all about.") { |v|
26 This is just a proof-of-concept example for rbot druby-based api. This program
27 reads lines of text from the standard input and sends them to a specified irc
28 channel or user via rbot. Make sure you have remotectl.rb plugin loaded before
31 The necessary setup is:
32 1) # create a new rbot user ("rmuser", in this example) with a password
33 # ("rmpw", in this example). in an open query to rbot:
35 <you> user create rmuser rmpw
36 <rbot> created botuser remote
38 2) # add a remotectl permission to your newly created remote user:
40 <you> permissions set +remotectl for rmuser
43 3) # add specific permissions for the commands you want to allow via
44 # remote interface. for example, in this script we want 'say',
45 # 'action' and other basic commands to work:
47 <you> permissions set +basics::talk::do for rmuser
50 4) # run the #{$0} and type something. the message should
51 # show up on your channel / arrive as an irc private message.
53 [you@yourhost ~]$ ./bin/rbot-remote -u rmuser -p rmpw -d '#your-channel'
62 if !pw || !user || !dst
67 rbot = DRbObject.new_with_uri(uri)
68 id = rbot.delegate(nil, "remote login #{user} #{pw}")[:return]
69 puts "id is #{id.inspect}"
73 rv = rbot.delegate(id, "dispatch say #{dst} #{s}") or break
74 puts "rv is #{rv.inspect}"