Advertisement
blotavious

Untitled

Jan 14th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.54 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'optparse'
  4. load '/home/sdtd/source/lib/telnet.rb'
  5. load './sdtdsay-class.rb'
  6.  
  7. options = {}
  8. optparse = OptionParser.new do |opts|
  9.    begin
  10.       opts.banner = 'Usage: send-command.rb [options]'
  11.  
  12.       opts.on('-c <command>', '--command', String, 'The command to send i.e. "listplayers" or "listknownplayers"', '\'say "something to someone"\' or "admin add blotavious 0"') do |arg|
  13.          options[:command] = arg.to_s
  14.       end
  15.  
  16.       opts.on('-?', '--help', 'This help screen') do
  17.          puts opts
  18.          exit 0
  19.       end
  20.  
  21.       options[:device] = "TELNET"
  22.       opts.on('-D <device>', '--device', 'The device to use, can be one of "TELNET" or "STDOUT"') do |arg|
  23.          options[:device] = arg.to_s
  24.       end
  25.  
  26.       options[:quiet] = FALSE
  27.       opts.on('-q', '--quiet', 'Suppress output') do
  28.          options[:quiet] = TRUE
  29.       end
  30.  
  31.       if ARGV.length < 1 then
  32.          puts opts
  33.          exit
  34.       end
  35.       opts.parse!
  36.    rescue OptionParser::MissingArgument
  37.       puts 'This option requires an argument'
  38.       puts opts
  39.       exit
  40.    rescue OptionParser::InvalidArgument
  41.       puts 'The argument supplied is invalid, i.e. a number instead of a string etc.'
  42.       puts opts
  43.       exit
  44.    end
  45. end
  46.  
  47. telnet = SDTDSay.new({  :device => options[:device],
  48.                         :password => 'yourpassword',
  49.                         :host => 'localhost',
  50.                         :port => 8081,
  51.                         :quiet => options[:quiet]})
  52.  
  53. telnet.send(options[:command])
  54. telnet.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement