root/bin/rbot-remote @ 1e9373e223fe142fb412f268d33e993a09d4d818

Revision 33f1c8ddc1f4c9f897f3b194a44faa1834f61566, 2.2 KB (checked in by dmitry kim <jason@…>, 2 years ago)

* bin/rbot-remote: doc typo

  • Property mode set to 100755
Line 
1#! /usr/bin/ruby
2require 'drb'
3require 'optparse'
4
5#++
6#
7# :title: RemoteCtl example script
8#
9# Author:: jsn (dmitry kim) <dmitry dot kim at gmail dot org>
10# Copyright:: (C) 2007 dmitry kim
11# License:: in public domain
12
13user = nil
14pw = nil
15dst = nil
16uri = 'druby://localhost:7268'
17
18opts = OptionParser.new
19opts.on('-u', '--user <user>', "remote user (mandatory)") { |v| user = v }
20opts.on('-p', '--password <pw>', "remote user password (mandatory)") { |v| pw = v }
21opts.on('-d', '--destination <user or #channel>') { |v| dst = v }
22opts.on('-r', '--uri <drb uri>', "rbot url (#{uri})") { |v| uri = v }
23opts.on('-h', '--help', "this message") { |v| pw = nil } # sorry!
24opts.on('-a', '--about', "what it's all about.") { |v|
25    puts <<EOF
26This is just a proof-of-concept example for rbot druby-based api. This program
27reads lines of text from the standard input and sends them to a specified irc
28channel or user via rbot. Make sure you have remotectl.rb plugin loaded before
29use.
30
31The 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:
34
35       <you> user create rmuser rmpw
36       <rbot> created botuser remote
37
38    2) # add a remotectl permission to your newly created remote user:
39
40       <you> permissions set +remotectl for rmuser
41       <rbot> okies!
42
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:
46
47       <you> permissions set +basics::talk::do for rmuser
48       <rbot> alright
49
50    4) # run the #{$0} and type something. the message should
51       # show up on your channel / arrive as an irc private message.
52       
53       [you@yourhost ~]$ ./bin/rbot-remote -u rmuser -p rmpw -d '#your-channel'
54       hello, world!
55       <Ctrl-D>
56       [you@yourhost ~]$
57EOF
58    exit 0
59}
60opts.parse!
61
62if !pw || !user || !dst
63    puts opts.to_s
64    exit 0
65end
66
67rbot = DRbObject.new_with_uri(uri)
68id = rbot.delegate(nil, "remote login #{user} #{pw}")[:return]
69puts "id is #{id.inspect}"
70loop {
71    s = gets or break
72    s.chomp!
73    rv = rbot.delegate(id, "dispatch say #{dst} #{s}") or break
74    puts "rv is #{rv.inspect}"
75}
76
Note: See TracBrowser for help on using the browser.