Guest User

Untitled

a guest
Mar 17th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Enable running the examples without installation
  4. libdir = File.expand_path(File.dirname(__FILE__)+'/../lib')
  5. $LOAD_PATH.unshift libdir if File.exist?(libdir)
  6.  
  7. # Require the necessary libraries
  8. begin; require 'rubygems'; rescue LoadError; end
  9. require 'silverplatter/irc/connection'
  10.  
  11. # extract opts
  12. def extract(opt)
  13. index = ARGV.index(opt)
  14. ARGV.delete_at(index)
  15. ARGV.delete_at(index)
  16. end
  17.  
  18. BotConfig = {
  19. :server => extract '--server',
  20. :port => extract '--port' || 6667,
  21. :serverpass => extract '--serverpass',
  22.  
  23. :join => [],
  24.  
  25. :nickname => extract '--nick' || 'irccat',
  26. :username => extract '--user' || 'irccat',
  27. :realname => extract '--real' || 'silverplatter-irc-cat',
  28.  
  29. :on_nick_error => SilverPlatter::IRC::Connection::IncrementOnNickError,
  30. }
  31. BotConfig[:join] = ARGV.shift until File.exist?(ARGV.first)
  32.  
  33. if ARGV.include?('--help') || ARGV.include?('-h') then
  34. abort(<<-EOH)
  35. irccat help:
  36. Usage: irccat --server irc.example.com [options] #channel ... [file ...]
  37. --server: server to connect to
  38. --port: port to use
  39. --serverpass: password to enter the server
  40. --nick: nickname to use (default: irccat)
  41. --user: username to use (default: irccat)
  42. --real: realname to use (default: silverplatter-irc-cat)
  43. EOH
  44. elsif !BotConfig[:server] || ARGV.empty? then
  45. abort("Usage: echo 'text' > irccat --server irc.freenode.org #channel ...")
  46. end
  47.  
  48. Bot = SilverPlatter::IRC::Connection.new(nil, BotConfig)
  49. Bot.connect
  50. Bot.run
  51. Bot.login
  52. while line = gets
  53. Bot.privmsg(line.chomp, *BotConfig[:join])
  54. end
  55. Bot.quit "My work here is done."
Add Comment
Please, Sign In to add comment